wood burning stoves 2.0*
The moose likes Object Relational Mapping and the fly likes Hibernate 3.3.1 - Delete doesn't work Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate 3.3.1 - Delete doesn Watch "Hibernate 3.3.1 - Delete doesn New topic
Author

Hibernate 3.3.1 - Delete doesn't work

Attila Kozma
Greenhorn

Joined: Jun 01, 2011
Posts: 2
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
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

When you run your delete code do you commit your transaction?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Attila Kozma
Greenhorn

Joined: Jun 01, 2011
Posts: 2
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.
 
GeeCON Prague 2014
 
subject: Hibernate 3.3.1 - Delete doesn't work