]
Célio commented on EJBTHREE-1049:
---------------------------------
I'm having the same problem.
wrong insert/delete order when updating record-set
--------------------------------------------------
Key: EJBTHREE-1049
URL:
http://jira.jboss.com/jira/browse/EJBTHREE-1049
Project: EJB 3.0
Issue Type: Bug
Affects Versions: AS 4.2.1.GA
Environment: jboss-4.2.1.GA , Fedora 6
Reporter: Imran Pariyani
Overview: I have a record with a OneToMany association. From this associated record-set a
record is removed and added again, both records identified with the same key. When doing a
merge, I get a Unique constraint violation, because EJB first tries to insert the new
record. It should first delete the old record, and after this insert the new record,
avoiding the unique constraint violation.
Detailed description: I have the following entities: Location and LocationI18n.
Location has onetomany mapping with locationi18n as follows
@OneToMany(cascade = CascadeType.ALL, mappedBy = "location", fetch =
FetchType.EAGER)
private List<LocationI18n> translations;
And the mapping in the locationi18n is :
@ManyToOne(cascade = {CascadeType.MERGE, CascadeType.PERSIST },fetch = FetchType.LAZY,
optional = false)
@JoinColumn(name = "loc_id", referencedColumnName = "id", nullable =
false, columnDefinition = "loc_id INT NOT NULL")
private Location location;
In the locationI18n table i have a unique key UNIQUE KEY (language, loc_id),
So now if i get a location and inside the location i have the collection of locationi18n
.. if from that collection i remove one object with language lets say 'EN' and
insert a new locationi18n object with the same language 'EN' then it first inserts
the new record and then delets the records which has been removed from the collection
Below is the stack trace:
2007-09-07 02:17:24,847 DEBUG [org.hibernate.SQL] insert into location_i18n (loc_id,
language, date_created, date_updated, province, city, worldregion, region, subregion,
quarter) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
2007-09-07 02:17:24,848 TRACE [org.hibernate.type.IntegerType] binding '1' to
parameter: 1
2007-09-07 02:17:24,848 DEBUG [org.hibernate.type.EnumType] Binding 'EN' to
parameter: 2
2007-09-07 02:17:24,848 TRACE [org.hibernate.type.TimestampType] binding '2007-09-07
02:17:24' to parameter: 3
2007-09-07 02:17:24,848 TRACE [org.hibernate.type.TimestampType] binding '2007-09-07
02:17:24' to parameter: 4
2007-09-07 02:17:24,848 TRACE [org.hibernate.type.StringType] binding null to parameter:
5
2007-09-07 02:17:24,848 TRACE [org.hibernate.type.StringType] binding null to parameter:
6
2007-09-07 02:17:24,849 TRACE [org.hibernate.type.StringType] binding null to parameter:
7
2007-09-07 02:17:24,849 TRACE [org.hibernate.type.StringType] binding 'afsdfa' to
parameter: 8
2007-09-07 02:17:24,849 TRACE [org.hibernate.type.StringType] binding null to parameter:
9
2007-09-07 02:17:24,849 TRACE [org.hibernate.type.StringType] binding null to parameter:
10
2007-09-07 02:17:24,873 WARN [org.hibernate.util.JDBCExceptionReporter] SQL Error: 1062,
SQLState: 23000
2007-09-07 02:17:24,874 ERROR [org.hibernate.util.JDBCExceptionReporter] Duplicate entry
'EN-1' for key 2
2007-09-07 02:17:24,874 ERROR [STDERR] javax.persistence.EntityExistsException:
org.hibernate.exception.ConstraintViolationException: could not insert:
[com.triple.LocationI18n]
2007-09-07 02:17:24,874 ERROR [STDERR] at
org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:604)
2007-09-07 02:17:24,874 ERROR [STDERR] at
org.hibernate.ejb.AbstractEntityManagerImpl.merge(AbstractEntityManagerImpl.java:236)
2007-09-07 02:17:24,874 ERROR [STDERR] at
org.jboss.ejb3.entity.TransactionScopedEntityManager.merge(TransactionScopedEntityManager.java:188)
2007-09-07 02:17:24,874 ERROR [STDERR] at
com.triple.LocationBean.updateLocation(LocationBean.java:83)
2007-09-07 02:17:24,874 ERROR [STDERR] at
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
2007-09-07 02:17:24,874 ERROR [STDERR] at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
2007-09-07 02:17:24,875 ERROR [STDERR] at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
Test case of the same is present at
http://opensource.atlassian.com/projects/hibernate/secure/attachment/1346...
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: