org.hibernate.AssertionFailure

Hi,

I am currently evaluating DB-VA and have some problems when generating code & database from UML.

Whenever I use the One-to-One / Many-to-Many / One-to-Many Associations in UML, I can generate the code just fine. But when I try insert data into the database (either from my own class or using the sample), I get the following exception:

17:56:11,515 ERROR AssertionFailure:22 - an assertion failure occured (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session)
org.hibernate.AssertionFailure: null id in persisttest.Publication entry (don't flush the Session after an exception occurs)
        at org.hibernate.event.def.DefaultFlushEntityEventListener.checkId(DefaultFlushEntityEventListener.java:48)
        at org.hibernate.event.def.DefaultFlushEntityEventListener.getValues(DefaultFlushEntityEventListener.java:150)
        at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:106)
        at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:195)
        at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:76)
        at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
        at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1011)
        at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:356)
        at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
        at org.orm.PersistentTransaction.commit(PersistentTransaction.java:34)
        at ormsamples.CreateTestData.createTestData(CreateTestData.java:18)
        at ormsamples.CreateTestData.main(CreateTestData.java:30)

It seems that the primary key is not set at all. For some reason I always get this error when I try to associate two classes. What am I doing wrong? Am I missing something obvious?

I have attached the project file and the mapping for one of the two classes I try to associate.

Thanks for the help,

Michael
Test.vpp
Publication.hbm.xml

A new day brought the solution…

In my (a lot more complex) use case, I forgot to fulfill an association with muliplicity 1 on one side and 1…* on the other. This resulted in the error.

When using the test project, it was easy to reproduce this behavior, since all associations mentioned above have a multiplicity of 1 on one side. The auto-generated samples don’t take this into account and therefore you get the same error. I would have thought the samples would consider this. As it is, I am happy that they didn’t because that pointed me directly to the problem in my code.

Michael

Thanks Michael
Do you mean that the problem is solved now?

The problem is solved, for me. However, in the situation described above, the auto-generated sample code will not work - something which might be frustrating for new users…

Documentation on this topic would be nice, or, if possible, working sample code.