Beginner |
|
Joined: Sun Oct 16, 2005 12:37 pm Posts: 47 Location: Romania, Galati
|
How can I resolve this an persist objects involved in many-to-many relation.
Thx.
Hibernate version:3.1
Mapping documents:
DocumenteGenerice <set name="miscaris" cascade="save-update" table="miscari_documente" inverse="false"> <key> <column name="documente_genericeId" length="15" /> </key> <many-to-many class="lotofsamples.model.Miscari" column="MiscareId"/> </set>
Miscari <set name="documenteGenerices" table="miscari_documente" inverse="true" cascade="save-update"> <key> <column name="MiscareId" length="17" /> </key> <many-to-many class="lotofsamples.model.MiscariDocumente" column="documente_genericeId"/> </set>
Code between sessionFactory.openSession() and session.close():
DocumenteGenerice docGen = new DocumenteGenerice(); docGen.setSerieDoc("DOCGEN00004"); docGen.setNumarDoc("00004"); docGen.setTipDocument("FA"); docGen.setObservatii("DocumentGeneric4"); docGen.setInGarantie(0);
Miscari miscare = new Miscari(); miscare.setObservatii("Miscare4"); miscare.setSensMiscare(1); docGen.getMiscaris().add(miscare); miscare.getDocumenteGenerices().add(docGen); session.persist(miscare); session.persist(docGen);
Full stack trace of any exception that occurs:
Exception in thread "main" java.lang.ClassCastException: lotofsamples.model.DocumenteGenerice at org.hibernate.type.EntityType.toLoggableString(EntityType.java:154) at org.hibernate.type.CollectionType.toLoggableString(CollectionType.java:146) at org.hibernate.pretty.Printer.toString(Printer.java:53) at org.hibernate.pretty.Printer.toString(Printer.java:90) at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:97) at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26) at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1009) at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:356) at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106) at lotofsamples.VerificareChei.main(VerificareChei.java:98)
Name and version of the database you are using:MySQL-4.17
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt:
|
|