• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Effective way for checking whether the entity exist before persisting  RSS feed

 
Ranch Hand
Posts: 209
Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,
I am using Jpa-Hibernate , I want to know if there is any effective way of checking whether the entity exist in the database before persisting it actually to the database.
Let me explain my question with the following example
I have created a function which takes object as an argument and does persisting for you with all the boilerplate code of creating transaction , closing session.


1. Create a Person entity
2. Persist the person entity using the above function.
3. Now if someone by mistakenly again calls the above function with the same entity which has been already persisted , then i will get


So i wanted to know whether there is an effective way (in terms of performance ) of checking whether the entity exist in the database and then do a persist.
Something like the following


I dont want to query the database for that check , some solution through which i can do a check in memory area which Hibernate uses.

Regards,
Shroff.
 
Sagar Shroff
Ranch Hand
Posts: 209
Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just found the solution to my typical scenario i should replace persist with merge in the function.
I am new to Jpa-Hibernate , so as i am learning i also want to consider the performance implications.
So i will still like to know/hear from ull if any better or appropriate solution with respect to Performance.

Thanks,
Shroff.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!