-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: [JPA]How to avoid making additional queries in favor of JOIN
PostPosted: Sat Jul 13, 2013 3:47 pm 
Newbie

Joined: Sat Jul 13, 2013 3:27 pm
Posts: 1
Hello, i am using Hibernate with annotated entities (both with JPA and Hibernate annotations).

I am having a schema with many users, having many groups, having many roles.

The problem i am experiencing is that hibernate makes an additional query for each of users to select his groups, so if i selected 100 users -- i will get 100+M queries, where M is some small constant (1-4 queries), which is slow and inefficent.

I would like to alter this behavior, probably forcing hibernate to use a few JOIN queries instead of lots of additional queries.

I have tried adding @Fetch(FetchMode.JOIN) annotation to my UserEntity.groups and GroupEntity.roles fields, but it changed nothing.

Please, advise me how to solve this problem.

Here are my entities:

UserEntity.java
Code:
@Entity
@Table(name = "users")
public class UserEntity {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(nullable = false)
    private Integer id;

    @Column(nullable = false, unique = true)
    private String name;

    @Column(nullable = false)
    private String passwordHash;

    @Column(nullable = false)
    private Date joined = new Date();

    @Column(nullable = false)
    private Boolean active = true;

    @Column(nullable = true)
    private String email = null;

    @ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
    @JoinTable(
            name = "users_groups_map",
            joinColumns = @JoinColumn(name = "userId", nullable = false, updatable = false),
            inverseJoinColumns = @JoinColumn(name = "groupId", nullable = false, updatable = false))
    @OrderBy("name")
    private Set<GroupEntity> groups;

// setters and getters
}


GroupEntity.java
Code:
@Entity
@Table(name = "groups")
public class GroupEntity {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(nullable = false)
    private Integer id;

    @Column(nullable = false, unique = true)
    private String name;

    @Column(nullable = true)
    private String description;

    @ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
    @JoinTable(
            name = "groups_roles_map",
            joinColumns = @JoinColumn(name = "groupId", nullable = false, updatable = false),
            inverseJoinColumns = @JoinColumn(name = "roleId", nullable = false, updatable = false))
    @OrderBy("name")
    private Set<RoleEntity> roles = new HashSet<RoleEntity>();

    @ManyToMany(fetch = FetchType.LAZY, mappedBy = "groups")
    @OrderBy("joined")
    private Set<UserEntity> users = new HashSet<UserEntity>();

// setters and getters
}


RoleEntity.java
Code:
@Entity
@Table(name = "roles")
public class RoleEntity {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(nullable = false)
    private Integer id;

    @Column(nullable = false, unique = true)
    private String name;

    @Column(nullable = true)
    private String description;

    @ManyToMany(fetch = FetchType.LAZY, mappedBy = "roles")
    @OrderBy("name")
    private Set<GroupEntity> groups;

// setters and getters
}


And here is my hibernate log upon selecting 100 users:

Code:
Hibernate: select userentity0_.id as id1_4_, userentity0_.active as active2_4_, userentity0_.email as email3_4_, userentity0_.joined as joined4_4_, userentity0_.name as name5_4_, userentity0_.passwordHash as password6_4_ from users userentity0_ order by userentity0_.joined desc limit ? offset ?
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select roles0_.groupId as groupId1_0_1_, roles0_.roleId as roleId2_1_1_, roleentity1_.id as id1_3_0_, roleentity1_.description as descript2_3_0_, roleentity1_.name as name3_3_0_ from groups_roles_map roles0_ inner join roles roleentity1_ on roles0_.roleId=roleentity1_.id where roles0_.groupId=? order by roleentity1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select groups0_.userId as userId1_4_1_, groups0_.groupId as groupId2_5_1_, groupentit1_.id as id1_0_0_, groupentit1_.description as descript2_0_0_, groupentit1_.name as name3_0_0_ from users_groups_map groups0_ inner join groups groupentit1_ on groups0_.groupId=groupentit1_.id where groups0_.userId=? order by groupentit1_.name
Hibernate: select count(userentity0_.id) as col_0_0_ from users userentity0_


Top
 Profile  
 
 Post subject: Re: [JPA]How to avoid making additional queries in favor of JOIN
PostPosted: Sat Jul 27, 2013 2:06 am 
Newbie

Joined: Sat Jul 27, 2013 1:47 am
Posts: 5
I guess you are talking about the typical n+1 select problem. Optimize through lazy and batch fetching.

First make the join entities associations - fetch type as LAZY. Then add @BatchSize on the join entities.
This would avoid n+1 select problem.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.