Win a copy of Java Challengers this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • paul wheaton
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • Mikalai Zaikin
  • Himai Minh

optimize read-only query in stateless session bean

 
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to make a query returend by a session bean READ-ONLY for optimization:

@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public void queryReadOnly(){

// make query..
List<User> users = entityManager.createNamedQuery(..).getResultList();


// proof if optimization worked
for(User u: users){
log.info("entityManager.contains 'Entity': {0}", entityManager.contains(u));

}

}

But I get for all my entities 'true' which means all entities are managed - is that not paradox, I have thought using TransactionAttributeType.NOT_SUPPORTED does not use entityManager first-cache.
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't follow. Why would loading entities in a method which doesn't support transactions make things read only? Am I missing something? (And what "optimization" are you trying to get by making these entities read only?)
 
nimo frey
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I dont know,
according to hibernate spec there are some optimizations when using something like

query.readOnly(true)

or

@org.hibernate.annotations.Immutable on a class or collection.


I have a large query which contains only entities for read-only (reporting things), so I want to bypass the overhead of entitymanager:
I dont want that the persistence provider has the overhead to manage my entities as they are only read-only.

Am I false with that?
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There's nothing in JPA for this, as far as I am aware. Hibernate supports read only queries, which changes the update checking logic (which would make them slightly more efficient). Its a specific query hint you use for this though.
 
nimo frey
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
okay thanks, I use aggregate queries and find out that with that I bypass the entityManager 1l-cache.
 
reply
    Bookmark Topic Watch Topic
  • New Topic