My question is about the way Spring data is generating the query .
I have two entities : Message , Sender
@Entity
public class Message extends BaseEntity {
@ManyToOne
protected Account sender;
}
I have a call to
messageDao.findBySenderId(Long id)
The result is query all columns from the two two table with a left outer join
between the two tables , but my expectation was simply to just select from message table where sender_id =
the passed value.
So is there a way to force selecting only the first message entity and not to join with the other one? I want simple condition in the where clause by using findBy not custom @Query
You will need a repository like (untested) :
@Repository
public interface MessageRepository extends JpaRepository<Message, Long> {
Message findFirstBySenderId(Long id);
}
See repositories.query-methods
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With