• 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

how manage INSERT operation?

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I accept suggestion about the management of INSERT into database.

I have a method in a sessionBean that simly does this operation

Entity manager em;

...
em.persist(NuovoRecord);


The problem is this, when the new record have a key equal to a stored object the jboss shows an error and my application crash. I need to manage the duplicate case, in the sense that if the user is inserting an object that already exists (or that has a key already existent) i have to send back to user a message to advice him about it.
Using the servlet and directly executing an sql code from it, i solved this problem using try catch(sqlException). in this case i can't, i try doing a flush before closing the method, and in this case i can catch the error and the application continue to works, but the jboss continues to show pages and pages of errors about duplicate keys.

What's the correct way for doing this operation?
Anyone can help me?

thans to all

Alessandro
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic