-->
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.  [ 3 posts ] 
Author Message
 Post subject: Can't find newly persisted entities using native queries!!!
PostPosted: Mon Aug 04, 2008 7:08 am 
Newbie

Joined: Thu Jul 31, 2008 5:44 am
Posts: 9
Hi,
I am using Hibernate's JPA implementation in a J2SE application. I am using an application-managed EntityManager and an EXTENDED persistence context. I chose to set the flush mode on the EntityManager to COMMIT. I am also using a resource-local transaction returned by the EntityManager.

During the transaction, I persist some newly created entities. But when I use native queries to search for these newly created entities, I get nothing back.

Correct me if I am wrong, but once an entity is persisted, any query (native or not) through the EntityManager should first examine the persistence context and then the database. If so, why isn't this the case for my example. For the record, I am using SELECT statements to look up the newly created entities and the look-ups are not based on the primary keys.

Any help would be appreciated.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 04, 2008 7:23 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
Ask in the jpa annotations forum.


P.a. Did you flush the session so the data is actually in the db ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 06, 2008 12:53 pm 
Newbie

Joined: Thu Jul 31, 2008 5:44 am
Posts: 9
max,
Thanks for your reply.
My mistake for not beeing very clear in my post. Things work ok when I flush the entity manager. However, this is exactly my problem. For every newly persisted object, I need to flush the entity manager, just so that my queries can find the newly persisted entity. This seems like an unecessary flush, since the object is already present in the persistence context. Why can't the entity manager take into account the content of the persistence context when executing a query?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.