Hibernate does not output subtitle if not
We have the following domain: Members and Channels.
Member is the equivalent of a user.
@Entity
@Table(name = "member")
public class Member {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "first_name")
private String firstName;
}
Channel - Will group blog posts by topic.
@Entity
@Table(name = "channel")
public class Channel {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;
@Column(name = "name")
private String name;
}
Members can be assigned to channels by becoming members in the channel. Thus, we have a ChannelMember object, since we don't always want to get both ends of the relationship.
@Entity
@Table(name = "channel_member")
public class ChannelMember {
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@OneToOne
@JoinColumn(name = "channel_id", nullable = false)
private Channel channel;
@OneToOne
@JoinColumn(name = "member_id", nullable = false)
private Member member;
}
We are using Spring data JPA and MySQL for our provisioning (Spring release version 1.5.3).
Why can a separate query in a JPQL query for Hibernate fetch any records in the following case?
Sample repository code as follows:
@Repository
public interface MemberRepository extends JpaRepository<Member, Long> {
@Query("select cm.member from ChannelMember cm")
List<Member> getNotWorking(); // empty List will be returned
@Query("select distinct cm.member from ChannelMember cm")
List<Member> getWorking();
}
+3
source to share
No one has answered this question yet
Check out similar questions: