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

Hibernate 3.3.1 - Delete doesn't work

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

I am new with Hibernate and encountered an issue, I will describe it through a short example because the involved classes and tables are parts of a very complex project from where is a little difficult to take out the code. In the project Hibernate 3.3.1 is used.

We have 2 tables: ParentTable and ChildTable.
ParentTable has: Parent_Id (primary key) and some other fields (which are not interesting for us)
ChildTable has: Parent_Id (foreign key from ParentTable), Field1, Field2. (FK_Parent_id and Field1) are the primary key for this table, so in the DB we have a Unique index for these fields.

Currently we have the following mappings in Java:

Basically on the GUI I have a form with many fields (for Parent) and have a grid (which has 2 columns: Field1 and Field2) and can contain several rows (for child).

The problem is that if I remove a row from this grid the delete doesn’t work from the DB, the value is put back and it is showed again on the GUI. Only inserts and update works as expected.
I read a couple of articles, forums, a few chapters from hibernate books but none of the solutions worked, does somebody has any idea of what can I change or what is wrong?

Thanks
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you run your delete code do you commit your transaction?
 
Attila Kozma
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Of course.
I debugged the code and noticed that Hibernate generated an update instead of delete, it tries to update the foreign key (which also belongs to the primary key) to null, which of course is not possible.
 
I knew I would regret that burrito. But this tiny ad has never caused regrets:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic