[hibernate-issues] [Hibernate-JIRA] Created: (EJB-260) OneToMany relationship not persiting merges

Chadwick Baatz (JIRA) noreply at atlassian.com
Fri Jan 5 13:45:44 EST 2007


OneToMany relationship not persiting merges
-------------------------------------------

         Key: EJB-260
         URL: http://opensource.atlassian.com/projects/hibernate/browse/EJB-260
     Project: Hibernate Entity Manager
        Type: Bug

    Versions: 3.2.1    
 Environment: MySQL 5.0x
    Reporter: Chadwick Baatz
    Priority: Blocker
 Attachments: TestProject.zip

I am having problems with the merging of a detached object that has changed.  The unidirectional OneToMany relationship is being updated in the Hibernate Context, but that update is not being persisted to the database.  I've been able to prove that the Hibernate layer works correctly when either:

1. The object is not detached and I perform a persist
2. The object is detached I perform a merge before any changes, then persist after all changes have been made to the object.

However, if I have a detached object with modifications to the manged one and I perform a merge those changes are done to the managed object in the Hibernate Context, but the database statement is never fired to make the change in the database.  Worse yet, any changes merged in this way are not updated on subsequent persist calls.

I've attached a sample project with test code that you can use to recreate the problem.  You the SQL statements below to populate the database and you'll have to set up the connection in the persistence.xml file.

SQL Statements:
Create table customer (
   customer_id Varchar(100) NOT NULL,
   UNIQUE (customer_id),
 Primary Key (customer_id)) ENGINE = InnoDB;

Create table customer_group (
   customer_group_id Int UNSIGNED NOT NULL AUTO_INCREMENT,
   name Varchar(250),
 Primary Key (customer_group_id)) ENGINE = InnoDB;

Create table customer_group_customer (
   customer_group_id Int UNSIGNED NOT NULL,
   customer_id Varchar(100) NOT NULL,
 Primary Key (customer_group_id,customer_id)) ENGINE = InnoDB;

Alter table customer_group_customer add Foreign Key (customer_id) references customer (customer_id) on delete  restrict on update  restrict;
Alter table customer_group_customer add Foreign Key (customer_group_id) references customer_group (customer_group_id) on delete  restrict on update  restrict; 

Create table customer (
   customer_id Varchar(100) NOT NULL,
   UNIQUE (customer_id),
 Primary Key (customer_id)) ENGINE = InnoDB;

Create table customer_group (
   customer_group_id Int UNSIGNED NOT NULL AUTO_INCREMENT,
   name Varchar(250),
 Primary Key (customer_group_id)) ENGINE = InnoDB;

Create table customer_group_customer (
   customer_group_id Int UNSIGNED NOT NULL,
   customer_id Varchar(100) NOT NULL,
 Primary Key (customer_group_id,customer_id)) ENGINE = InnoDB;

Alter table customer_group_customer add Foreign Key (customer_id) references customer (customer_id) on delete  restrict on update  restrict;
Alter table customer_group_customer add Foreign Key (customer_group_id) references customer_group (customer_group_id) on delete  restrict on update  restrict; 

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira




More information about the hibernate-issues mailing list