JPAContainer unnecessary queries?

Hi,

I just finished reading JPAContainer tutorial and started coding application very similar to example.

I’m using JBoss EAP 6.1.0 and EJB 3.1 which extends CachingMutableLocalEntityProvider where User is sample entity class. I have 8 entities in my database. I have noticed that each time table of users is rendered there are many Hibernate queries fired.


15:34:08,217 INFO  [stdout]
 (http-/127.0.0.1:8080-1) Hibernate: 
15:34:08,217 INFO  [stdout]
 (http-/127.0.0.1:8080-1)     select
15:34:08,217 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         count(user0_.id) as col_0_0_ 
15:34:08,217 INFO  [stdout]
 (http-/127.0.0.1:8080-1)     from
15:34:08,217 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         users user0_
15:34:08,219 INFO  [stdout]
 (http-/127.0.0.1:8080-1) Hibernate: 
15:34:08,219 INFO  [stdout]
 (http-/127.0.0.1:8080-1)     select
15:34:08,219 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.id as col_0_0_ 
15:34:08,219 INFO  [stdout]
 (http-/127.0.0.1:8080-1)     from
15:34:08,219 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         users user0_ 
15:34:08,219 INFO  [stdout]
 (http-/127.0.0.1:8080-1)     order by
15:34:08,219 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.slogin desc,
15:34:08,219 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.id desc limit ?
15:34:08,223 INFO  [stdout]
 (http-/127.0.0.1:8080-1) Hibernate: 
15:34:08,223 INFO  [stdout]
 (http-/127.0.0.1:8080-1)     select
15:34:08,223 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.id as id1_3_0_,
15:34:08,223 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.bactive as bactive2_3_0_,
15:34:08,223 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.tcreated as tcreated3_3_0_,
15:34:08,223 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.semailaddress as semailad4_3_0_,
15:34:08,223 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.sfirstname as sfirstna5_3_0_,
15:34:08,223 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.tlastmodified as tlastmod6_3_0_,
15:34:08,223 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.slastname as slastnam7_3_0_,
15:34:08,223 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.slogin as slogin8_3_0_,
15:34:08,223 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.spassword as spasswor9_3_0_,
15:34:08,223 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.srole as srole10_3_0_ 
15:34:08,224 INFO  [stdout]
 (http-/127.0.0.1:8080-1)     from
15:34:08,224 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         users user0_ 
15:34:08,224 INFO  [stdout]
 (http-/127.0.0.1:8080-1)     where
15:34:08,224 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.id=?
15:34:08,226 INFO  [stdout]
 (http-/127.0.0.1:8080-1) Hibernate: 
15:34:08,227 INFO  [stdout]
 (http-/127.0.0.1:8080-1)     select
15:34:08,227 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.id as id1_3_0_,
15:34:08,227 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.bactive as bactive2_3_0_,
15:34:08,227 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.tcreated as tcreated3_3_0_,
15:34:08,227 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.semailaddress as semailad4_3_0_,
15:34:08,227 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.sfirstname as sfirstna5_3_0_,
15:34:08,227 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.tlastmodified as tlastmod6_3_0_,
15:34:08,227 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.slastname as slastnam7_3_0_,
15:34:08,227 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.slogin as slogin8_3_0_,
15:34:08,227 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.spassword as spasswor9_3_0_,
15:34:08,227 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.srole as srole10_3_0_ 
15:34:08,227 INFO  [stdout]
 (http-/127.0.0.1:8080-1)     from
15:34:08,227 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         users user0_ 
15:34:08,227 INFO  [stdout]
 (http-/127.0.0.1:8080-1)     where
15:34:08,227 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.id=?
15:34:08,231 INFO  [stdout]
 (http-/127.0.0.1:8080-1) Hibernate: 
15:34:08,231 INFO  [stdout]
 (http-/127.0.0.1:8080-1)     select
15:34:08,231 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.id as id1_3_0_,
15:34:08,231 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.bactive as bactive2_3_0_,
15:34:08,231 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.tcreated as tcreated3_3_0_,
15:34:08,231 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.semailaddress as semailad4_3_0_,
15:34:08,231 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.sfirstname as sfirstna5_3_0_,
15:34:08,232 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.tlastmodified as tlastmod6_3_0_,
15:34:08,232 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.slastname as slastnam7_3_0_,
15:34:08,232 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.slogin as slogin8_3_0_,
15:34:08,232 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.spassword as spasswor9_3_0_,
15:34:08,232 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.srole as srole10_3_0_ 
15:34:08,232 INFO  [stdout]
 (http-/127.0.0.1:8080-1)     from
15:34:08,232 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         users user0_ 
15:34:08,232 INFO  [stdout]
 (http-/127.0.0.1:8080-1)     where
15:34:08,232 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.id=?
15:34:08,236 INFO  [stdout]
 (http-/127.0.0.1:8080-1) Hibernate: 
15:34:08,237 INFO  [stdout]
 (http-/127.0.0.1:8080-1)     select
15:34:08,237 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.id as id1_3_0_,
15:34:08,237 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.bactive as bactive2_3_0_,
15:34:08,237 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.tcreated as tcreated3_3_0_,
15:34:08,237 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.semailaddress as semailad4_3_0_,
15:34:08,237 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.sfirstname as sfirstna5_3_0_,
15:34:08,237 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.tlastmodified as tlastmod6_3_0_,
15:34:08,237 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.slastname as slastnam7_3_0_,
15:34:08,237 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.slogin as slogin8_3_0_,
15:34:08,237 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.spassword as spasswor9_3_0_,
15:34:08,237 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.srole as srole10_3_0_ 
15:34:08,237 INFO  [stdout]
 (http-/127.0.0.1:8080-1)     from
15:34:08,237 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         users user0_ 
15:34:08,237 INFO  [stdout]
 (http-/127.0.0.1:8080-1)     where
15:34:08,237 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.id=?
15:34:08,241 INFO  [stdout]
 (http-/127.0.0.1:8080-1) Hibernate: 
15:34:08,242 INFO  [stdout]
 (http-/127.0.0.1:8080-1)     select
15:34:08,242 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.id as id1_3_0_,
15:34:08,242 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.bactive as bactive2_3_0_,
15:34:08,242 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.tcreated as tcreated3_3_0_,
15:34:08,242 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.semailaddress as semailad4_3_0_,
15:34:08,242 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.sfirstname as sfirstna5_3_0_,
15:34:08,242 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.tlastmodified as tlastmod6_3_0_,
15:34:08,242 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.slastname as slastnam7_3_0_,
15:34:08,242 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.slogin as slogin8_3_0_,
15:34:08,242 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.spassword as spasswor9_3_0_,
15:34:08,242 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.srole as srole10_3_0_ 
15:34:08,242 INFO  [stdout]
 (http-/127.0.0.1:8080-1)     from
15:34:08,242 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         users user0_ 
15:34:08,242 INFO  [stdout]
 (http-/127.0.0.1:8080-1)     where
15:34:08,242 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.id=?
15:34:08,246 INFO  [stdout]
 (http-/127.0.0.1:8080-1) Hibernate: 
15:34:08,246 INFO  [stdout]
 (http-/127.0.0.1:8080-1)     select
15:34:08,246 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.id as id1_3_0_,
15:34:08,246 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.bactive as bactive2_3_0_,
15:34:08,246 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.tcreated as tcreated3_3_0_,
15:34:08,246 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.semailaddress as semailad4_3_0_,
15:34:08,247 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.sfirstname as sfirstna5_3_0_,
15:34:08,247 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.tlastmodified as tlastmod6_3_0_,
15:34:08,247 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.slastname as slastnam7_3_0_,
15:34:08,247 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.slogin as slogin8_3_0_,
15:34:08,247 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.spassword as spasswor9_3_0_,
15:34:08,247 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.srole as srole10_3_0_ 
15:34:08,247 INFO  [stdout]
 (http-/127.0.0.1:8080-1)     from
15:34:08,247 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         users user0_ 
15:34:08,247 INFO  [stdout]
 (http-/127.0.0.1:8080-1)     where
15:34:08,247 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.id=?
15:34:08,254 INFO  [stdout]
 (http-/127.0.0.1:8080-1) Hibernate: 
15:34:08,254 INFO  [stdout]
 (http-/127.0.0.1:8080-1)     select
15:34:08,254 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.id as id1_3_0_,
15:34:08,254 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.bactive as bactive2_3_0_,
15:34:08,254 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.tcreated as tcreated3_3_0_,
15:34:08,254 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.semailaddress as semailad4_3_0_,
15:34:08,254 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.sfirstname as sfirstna5_3_0_,
15:34:08,255 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.tlastmodified as tlastmod6_3_0_,
15:34:08,255 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.slastname as slastnam7_3_0_,
15:34:08,255 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.slogin as slogin8_3_0_,
15:34:08,255 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.spassword as spasswor9_3_0_,
15:34:08,255 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.srole as srole10_3_0_ 
15:34:08,255 INFO  [stdout]
 (http-/127.0.0.1:8080-1)     from
15:34:08,255 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         users user0_ 
15:34:08,255 INFO  [stdout]
 (http-/127.0.0.1:8080-1)     where
15:34:08,255 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.id=?
15:34:08,261 INFO  [stdout]
 (http-/127.0.0.1:8080-1) Hibernate: 
15:34:08,261 INFO  [stdout]
 (http-/127.0.0.1:8080-1)     select
15:34:08,261 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.id as id1_3_0_,
15:34:08,261 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.bactive as bactive2_3_0_,
15:34:08,261 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.tcreated as tcreated3_3_0_,
15:34:08,261 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.semailaddress as semailad4_3_0_,
15:34:08,261 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.sfirstname as sfirstna5_3_0_,
15:34:08,261 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.tlastmodified as tlastmod6_3_0_,
15:34:08,261 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.slastname as slastnam7_3_0_,
15:34:08,261 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.slogin as slogin8_3_0_,
15:34:08,261 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.spassword as spasswor9_3_0_,
15:34:08,261 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.srole as srole10_3_0_ 
15:34:08,261 INFO  [stdout]
 (http-/127.0.0.1:8080-1)     from
15:34:08,261 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         users user0_ 
15:34:08,261 INFO  [stdout]
 (http-/127.0.0.1:8080-1)     where
15:34:08,261 INFO  [stdout]
 (http-/127.0.0.1:8080-1)         user0_.id=?

Here is how i am building the table component:


final JPAContainer<User> persons = new JPAContainer<User>(User.class);
        persons.setEntityProvider(userJPAContainer);


        persons.sort(new String[]{"login", "id"},
                     new boolean[]{false, false});


        final Table personTable = new Table("The Persistent People", persons);
        personTable.setVisibleColumns(new String[]{"id","login","password"});

        personTable.setSelectable(true);
        personTable.setImmediate(true);

        personTable.setBuffered(true);

I guess the first two are ok (count + select, but it selects only ids) but as you can see after that there are 8 queries fired (for each entity). What’s wrong? Those two queries should be enough.