Update of Many-to-Many relationships not allways working (deletes records but doesn't
insert them)
--------------------------------------------------------------------------------------------------
Key: HHH-5256
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-5256
Project: Hibernate Core
Issue Type: Bug
Components: entity-manager
Affects Versions: 3.3.2
Environment: JBoss 5.1.0.GA / MySql 5.1
Reporter: Ignacio Larrañaga
Priority: Critical
Attachments: bug_test.jar
I'm executing an update of the User entity and it deletes a relationship that must not
change as it is not modified.
It works well when new registers are added to the practicedSports relationship as well
that when this relationship is updated, but when I update another field of the User
entity, without changing practicedSports Hibernates only executes the delete so the
entities disapears after the update.
Also I verify that the user entity has something in the collection to be updated.
This is the declaration of the User object, and particularly the relationship:
@Entity
@Name(User.SEAM_CONTEXT_NAME)
@Scope(ScopeType.CONVERSATION)
@Table(name="users", uniqueConstraints = {
@UniqueConstraint(columnNames={"country_id", "citizen_id"})
})
@NamedQueries({
@NamedQuery(name = User.FIND_BY_NAME, query = "from User where name = :name"),
@NamedQuery(name = User.FIND_BY_EMAIL, query = "from User where email =
:email"),
@NamedQuery(name = User.FIND_BY_MOBILE_PHONE, query = "from User where mobilePhone =
:mobilePhone")
})
public class User extends AuditableBaseObject implements IdentifiableObject,
AddressableObject, CarrierableObject {
....
@ManyToMany(cascade = CascadeType.ALL)
@Cascade(org.hibernate.annotations.CascadeType.ALL)
@JoinTable(name="user_practiced_sports",
joinColumns = @JoinColumn(name = "user_id", referencedColumnName =
"id"),
inverseJoinColumns=@JoinColumn(name="sport_id",
referencedColumnName="id"))
@ForeignKey(name = "users_to_sports_fk", inverseName =
"sports_to_users_fk")
private Collection<Sport> practicedSports;
This is the code I'm executing into the session bean:
public void modifyUser(User user) {
entityManager.persist(userLogger.info(user,
interpolator.interpolate("#{messages['User.log.modify_data']}")));
log.debug(interpolator.interpolate("User #{user.name} (#{user.firstName}
#{user.lastName}), modify his registration data."));
entityManager.merge(user);
}
I'm also attaching the model and a TestNG test case: UserMergeTest
--
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....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira