• 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

duplicate key violates unique constraint if I do not call getId()?

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have a small application with PersonEntity and NameEntity. Every person has a collection of names so there is a OneToMany relations


Every person also has a date attribute. I have once made the mistake to declare the date as a string property. But I would like to have it as a java.util.Data property. This is way I have created a new PersonWithDateEntity that is completly equal to PersonEntity but its date is of type java.util.Date.

When this is deployed two new tables are created - personwithdateentity and personwithdateentity_nameentity;

In order to transform from the PersonEntity to PersonWithDateEntity in a session bean I am executing the following.



The problem is that this code throws an org.postgresql.util.PSQLException: ERROR: duplicate key violates unique constraint "personwithdateentity_nameentity_pkey"

While investigating the problem I have noticed that if I call

before calling entityManager.persist(entity2) that everything works fine. The tables are filled. The date is converted.

So If I call name.getId() everything works find. But If I do not then a duplicate key error occurs.

Problably I am missing something. Does anybody knows why is it neccessary to call name.getId()?

The id of the name is actually


My environment
gentoo linux, glassfish 2, java ee 5, postgresql 8.0.15, postgresql-jdbc-8.3-604.

Thank you.
reply
    Bookmark Topic Watch Topic
  • New Topic