Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] bi-directional mapping causes two inserts


This is such a basic thing, but I cannot see what I'm doing wrong.

I have a annotation like this:

class Building
@OneToMany(cascade=CascadeType.ALL, mappedBy="building")
public Set<Comment> getComments() {}

And then

class Comment
@ManyToOne
public Building getBuilding() {}

I start a transaction, create a building, add a comment, and call entityManager.persist(building);

Now the INSERT is called twice for the Building. Why? If I remove the @ManyToOne and make it unidirectional using a join table, it works.

I'm using M7.

Thanks!

/Magnus


2008-05-27 16:34:37,792 [main] INFO  Began transaction (1): transaction manager [org.springframework.orm.jpa.JpaTransactionManager@11d2066]; rollback [true] at org.springframework.test.context.transaction.TransactionalTestExecutionListener.startNewTransaction(TransactionalTestExecutionListener.java:259)
2008-05-27 16:34:37,964 [main] TRACE [EL Finest]: UnitOfWork(24440876)--Execute query DoesExistQuery() at ?.?(?:?)
2008-05-27 16:34:37,964 [main] TRACE [EL Finest]: UnitOfWork(24440876)--PERSIST operation called on: [Building@51064e objectId = 25da2090-9b5e-4b8d-81c3-2197c0ca4e01, objectVersion = 1]. at ?.?(?:?)
2008-05-27 16:34:37,964 [main] TRACE [EL Finest]: ClientSession(30168161)--Execute query ValueReadQuery() at ?.?(?:?)
2008-05-27 16:34:37,964 [main] DEBUG [EL Fine]: ClientSession(30168161)--Connection(6881863)--SELECT id_seq.NEXTVAL FROM DUAL at ?.?(?:?)
2008-05-27 16:34:37,979 [main] TRACE [EL Finest]: ServerSession(25218858)--sequencing preallocation for id_seq: objects: 50 , first: 1, last: 50 at ?.?(?:?)
2008-05-27 16:34:37,979 [main] TRACE [EL Finest]: UnitOfWork(24440876)--assign sequence to the object (1 -> [Building@51064e objectId = 25da2090-9b5e-4b8d-81c3-2197c0ca4e01, objectVersion = 1]) at ?.?(?:?)
2008-05-27 16:34:37,979 [main] TRACE [EL Finest]: UnitOfWork(24440876)--Execute query DoesExistQuery() at ?.?(?:?)
2008-05-27 16:34:37,979 [main] TRACE [EL Finest]: UnitOfWork(24440876)--PERSIST operation called on: se.lantmateriet.origo.domain.model.building.Comment@1b3278a. at ?.?(?:?)
2008-05-27 16:34:37,979 [main] TRACE [EL Finest]: UnitOfWork(24440876)--assign sequence to the object (2 -> se.lantmateriet.origo.domain.model.building.Comment@1b3278a) at ?.?(?:?)
2008-05-27 16:34:37,995 [main] TRACE [EL Finest]: UnitOfWork(24440876)--Execute query InsertObjectQuery([Building@51064e objectId = 25da2090-9b5e-4b8d-81c3-2197c0ca4e01, objectVersion = 1]) at ?.?(?:?)
2008-05-27 16:34:37,995 [main] DEBUG [EL Fine]: ClientSession(30168161)--Connection(6881863)--INSERT INTO BUILDING (ID, OBJECTID, OBJECTVERSION, VERSION, OBJECTSTATUS, CONSTRUCTIONYEAR, HOUSENUMBER, EXTENSIONYEAR, REALPROPERTYKEY, VERSIONVALIDFROM, VERSIONVALIDTO, NOADDRESSNEEDED, MAINBUILDING, PREFIX, IDENTITY) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
    bind => [1, 25da2090-9b5e-4b8d-81c3-2197c0ca4e01, 1, 1, 0, 2008, null, null, null, 2008-05-27 16:34:37.979, null, true, true, null, null] at ?.?(?:?)
2008-05-27 16:34:38,026 [main] TRACE [EL Finest]: UnitOfWork(24440876)--Execute query InsertObjectQuery(se.lantmateriet.origo.domain.model.building.Comment@1b3278a) at ?.?(?:?)
2008-05-27 16:34:38,026 [main] TRACE [EL Finest]: UnitOfWork(24440876)--Execute query WriteObjectQuery([Building@24c672 objectId = 25da2090-9b5e-4b8d-81c3-2197c0ca4e01, objectVersion = 1]) at ?.?(?:?)
2008-05-27 16:34:38,026 [main] DEBUG [EL Fine]: ClientSession(30168161)--Connection(6881863)--INSERT INTO BUILDING (ID, OBJECTID, OBJECTVERSION, VERSION, OBJECTSTATUS, CONSTRUCTIONYEAR, HOUSENUMBER, EXTENSIONYEAR, REALPROPERTYKEY, VERSIONVALIDFROM, VERSIONVALIDTO, NOADDRESSNEEDED, MAINBUILDING, PREFIX, IDENTITY) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
    bind => [1, 25da2090-9b5e-4b8d-81c3-2197c0ca4e01, 1, 1, 0, 2008, null, null, null, 2008-05-27 16:34:37.979, null, true, true, null, null] at ?.?(?:?)
2008-05-27 16:34:38,042 [main] DEBUG [EL Fine]: ClientSession(30168161)--SELECT 1 FROM DUAL at ?.?(?:?)
2008-05-27 16:34:38,042 [main] WARN  [EL Warning]: UnitOfWork(24440876)--Local Exception Stack:
Exception [EclipseLink-4002] (Eclipse Persistence Services - 1.0 (Build SNAPSHOT - 20080508)): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: ORA-00001: brott mot unik begränsning (MAGHEI.SYS_C00135499)

--

/Magnus Heino

Back to the top