Hmm, that didn't work: whether public oder protected..
It must be the <list> mapping.
Data.hbm.xml
Code:
<class name="de.bla.Data" table="ADET_ID_DATA"
discriminator-value="D">
<id name="id" column="ID_">
<generator class="native" />
</id>
<discriminator type="char" column="CLASS_" />
...
<list name="comments" cascade="all" inverse="true">
<key column="ID_" />
<list-index column="COMMENT_INDEX"/>
<one-to-many class="de.bla.Comment"/>
</list>
...
What I dont understand at all:
Code:
mysql> DESCRIBE adet_id_data;
+------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+----------------+
| ID_ | bigint(20) | NO | PRI | NULL | auto_increment |
| CLASS_ | char(1) | NO | | | |
| NAME_ | varchar(255) | YES | | NULL | |
| INITDATE_ | datetime | YES | | NULL | |
| REQDATE_ | datetime | YES | | NULL | |
| OMRESP_ | bigint(20) | YES | MUL | NULL | |
| REQUESTOR_ | bigint(20) | YES | MUL | NULL | |
| VERSION_ | bigint(20) | YES | MUL | NULL | |
+------------+--------------+------+-----+---------+----------------+
8 rows in set (0.02 sec)
mysql> DESCRIBE adet_id_comment;
+---------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------------+--------------+------+-----+---------+----------------+
| ID_ | bigint(20) | NO | PRI | NULL | auto_increment |
| CLASS_ | char(1) | NO | | | |
| NAME_ | varchar(255) | YES | | NULL | |
| CONTENT_ | text | YES | | NULL | |
| DATE_ | datetime | YES | | NULL | |
| CREATOR_ | bigint(20) | YES | MUL | NULL | |
| COMMENT_INDEX | int(11) | YES | | NULL | |
+---------------+--------------+------+-----+---------+----------------+
7 rows in set (0.02 sec)
I dont understand why there is NO entry in the 'Data' table and there IS A entry in the 'Comment' Table. It should be the other way round, shouldn't it? A 'Data' knows its 'Comments' and thats all.
btw, the current error is when I am trying to add a Comment-Instance to the Data Object (= ArrayList.add( ))
Caused by: java.lang.ClassCastException: org.hibernate.collection.PersistentList
at org.hibernate.engine.StatefulPersistenceContext.reassociateIfUninitializedProxy(StatefulPersistenceContext.ja
va:490)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.reassociateIfUninitializedProxy(DefaultSaveOrUpdateE
ventListener.java:76)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:59)
at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:502)
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:496)
at org.hibernate.engine.CascadingAction$1.cascade(CascadingAction.java:134)
at org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:213)
at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:157)
at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:108)
at org.hibernate.engine.Cascade.cascadeCollectionElements(Cascade.java:290)
at org.hibernate.engine.Cascade.cascadeCollection(Cascade.java:185)
at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:160)
at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:108)
at org.hibernate.engine.Cascade.cascade(Cascade.java:248)
at org.hibernate.event.def.AbstractFlushingEventListener.cascadeOnFlush(AbstractFlushingEventListener.java:130)
at org.hibernate.event.def.AbstractFlushingEventListener.prepareEntityFlushes(AbstractFlushingEventListener.java:121)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:65)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:908)
at de.bla.DataSession.commitTransaction(DataSession.java:51)
at de.bla.DataSession.commitTransactionAndClose(DataSession.java:75)
at de.bla.DataService.addComment(DataService.java:192)
The Code: