• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem in fetching the persist record which is not committed

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
author & internet detective
Posts: 41914
910
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic