[b]Hibernate version: 3.0.5[/b]
I am trying to update an object in the database from an external source. I have an object A with a collection (set) of objects B. I have a file with updated state of the object A and its collection of objects B.
I am doing the following:
1. creating a new A with
[code] A a = new A()[/code]
2. A has a set of B class:
[code] Set<B> bs = new HashSet<B>();
3. as I read the file, I create new objects B and add them to the set bs.
[code] B b = new B();
b.readFromFile();
bs.add(b);
Note that the object A I am constructing may or may not be in the database. Also note that the objects B in the collection may in part be in the database, or may not. My intension is to update all the objects in the database according to what I have read form the file.
4. Then I try to attach / update the instance a to an hibernate session.
The code I am using:
[code]
Session session = sessionFactory.openSession();
Transaction trans = session.beginTransaction();
try {
session.update(a);
}
finally {
trans.commit();
}
session.close();
5. when I run the code, I get the exception:
reassociated object has dirty collection reference (or an array)
at org.hibernate.event.def.OnLockVisitor.processCollection(OnLockVisitor.java:67)
at org.hibernate.event.def.AbstractVisitor.processValue(AbstractVisitor.java:104)
at org.hibernate.event.def.AbstractVisitor.processValue(AbstractVisitor.java:64)
at org.hibernate.event.def.AbstractVisitor.processEntityPropertyValues(AbstractVisitor.java:58)
at org.hibernate.event.def.AbstractVisitor.process(AbstractVisitor.java:129)
at org.hibernate.event.def.AbstractReassociateEventListener.reassociate(AbstractReassociateEventListener.java:75)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performUpdate(DefaultSaveOrUpdateEventListener.java:241)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsDetached(DefaultSaveOrUpdateEventListener.java:214)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:91)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:69)
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:468)
at org.hibernate.engine.Cascades$5.cascade(Cascades.java:154)
at org.hibernate.engine.Cascades.cascadeAssociation(Cascades.java:771)
at org.hibernate.engine.Cascades.cascade(Cascades.java:720)
at org.hibernate.engine.Cascades.cascadeCollection(Cascades.java:895)
at org.hibernate.engine.Cascades.cascadeAssociation(Cascades.java:792)
at org.hibernate.engine.Cascades.cascade(Cascades.java:720)
at org.hibernate.engine.Cascades.cascade(Cascades.java:847)
at org.hibernate.event.def.AbstractFlushingEventListener.cascadeOnFlush(AbstractFlushingEventListener.java:121)
at org.hibernate.event.def.AbstractFlushingEventListener.prepareEntityFlushes(AbstractFlushingEventListener.java:112)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:59)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:730)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:324)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:86)
at com.tsoft.metadata.repository.TsDBReposiroryContainer.persist(TsDBReposiroryContainer.java:58)
... 3 more
6. I have tries using session.persist, session.merge, session.saveOrUpdate, but nothing works. Everytime I am getting exceptions.
Do you know how to do the update from file to database I am trying?
Thanks, Yoav.
|