It was also noted that the second Building instance that EclipseLink is
inserting is different from the one in the object. Are any of the
model's getters returning a clone?
--Gordon
Gordon Yorke wrote:
"(insertable=false,updatable=false)" would be a bit of a hack. I
expected this to work as mapped and created a simple test case that
confirms this should be working. What else is going on? Is this
reproducible in a small testcase?
--Gordon
Tim Hollosy wrote:
Magnus,
I think your @ManyToOne needs a joincolumn annotation like:
@ManyToOne
@JoinColumn(name="comment_id") //or whatever your join column is
The other thing to try is setting one side of the relationship to
readonly (insertable=false,updatable=false).
Tim
On Tue, May 27, 2008 at 10:47 AM, Magnus Heino <magnus@xxxxxxxxx> wrote:
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
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users
|