• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem in fetching the persist record which is not committed

 
Gourav Bansal
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I am new to JPA and stuck with fetching the records from DB. What I am doing is

Transaction Begin
Go to Class A-> Create Object A using EntityManager persist method.
Go to Class B-> Create Object B using EntityManager persist method.
Go to Class C-> try to fetch the Object A using EntityManager createQuery method and here I am passing some parameters(Don't have the Primary key so using this).
then query.getResultList() this give me the empty result list.

Transaction commit

But when I check the DB after committing I got the expected result. I believe I got the empty list because I persist the record "A" but not committed into DB. If this is the case please help me in fetching that record.

Thanks

 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Calling flush() updates the database, but I'm not sure if that is the best approach here.
 
Gourav Bansal
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jeanne for reply.

I modified the entity and give the back traverse using mappedBy attribute and get the Object A
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure all of that operation was part of the same transaction? Also, what is the transaction isolation on the JDBC connection that JPA is using? It depends on how the connection/datasource is configured.
 
Gourav Bansal
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes that is same part of same transaction.

I din't set any isolation level. I believe by default its Read_Commit
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic