Help coderanch get a
new server
by contributing to the fundraiser
  • 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Persisting second identical object causes ConstraintViolationException?

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Forum,

first - I'm new to javaee and ejb3 ;)

I've created a new entity bean which has successfully be deployed on my jboss 5.0.0GA. Persisting new objects does work. (via em.persist(object)) So I wrote a little test to find out, if my unique constraint also work - well, it doesn't seem to/it works too good ...

When adding a second, identical object to my database, I get an ConstraintViolationException. Can someone tell me, where my mistake is?

I thought, that, when catching EntityExistsException that should not happen...

best regard,
Dellerium



entity bean:


Dao bean:




 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Looks like program is trying to insert rows with same id. You can see "Unique Key Voilation" error in thread. Query the database table and you can find out row exist or not.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic