[hibernate-issues] [Hibernate-JIRA] Created: (HHH-4496) Entity with composite-id and serial foreign-key one-to-many set mapping can't be saved under 3.3.x and under 3.2.x can be saved but can't fetch set to father object
Yi, Han (JIRA)
noreply at atlassian.com
Fri Oct 16 05:03:41 EDT 2009
Entity with composite-id and serial foreign-key one-to-many set mapping can't be saved under 3.3.x and under 3.2.x can be saved but can't fetch set to father object
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
Key: HHH-4496
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-4496
Project: Hibernate Core
Issue Type: Bug
Affects Versions: 3.3.2, 3.3.1, 3.2.5
Environment: jdk1.6.0_13
windows 2003 server
hibernate 3.2.5, 3.3.1, 3.3.2
database: postgreSQL8.4
Reporter: Yi, Han
Mapping:
<class name="ExtraInfo" table="extrainfo">
<composite-id class="ExtraInfoId" name="key">
<key-property column="sn" length="20" name="cid" type="string"/>
<key-property column="composite" length="2" name="composite" type="string"/>
<key-property column="fileName" length="300" name="fileName" type="string"/>
</composite-id>
<property name="id" generated="insert" insert="false" type="java.lang.Integer" unique="true" update="false">
<column name="id" not-null="true"/>
</property>
...
<setinverse="true" name="scanDatas">
<key property-ref="id">
<column name="id"/>
</key>
<one-to-many class="ScanData"/>
</set>
</class>
<class name="ScanData" table="scandata">
<composite-id class="net.vuniverse.app.biochemanalysis.db.model.ScanDataId" name="key">
<key-property column="id" name="id" type="java.lang.Integer"/>
<key-property column="idx" name="idx" type="java.lang.Integer"/>
</composite-id>
<many-to-one fetch="join" insert="false" name="extraInfo" property-ref="id" update="false">
<column name="id"/>
</many-to-one>
<property name="data" type="java.lang.Float">
<column name="data" precision="8" scale="8"/>
</property>
</class>
Code:
ExtraInfoId eid = new ExtraInfoId("a", "1", "aa.txt");
ExtraInfo extra = new ExtraInfo(eid);
session.save(extra);
session.flush();
int id = extra.getId();
for (int i = 0; i < 3; i++) {
ScanData sd = new ScanData(new ScanDataId(id, 1));
sd.setData(0.5f * (i + 1));
session.save(sd);
}
session.flush();
extra = session.createQuery("from ExtraInfo a left join fetch a.scandatas b where a.id='" + id + "'").list().get(0);
Set<ScanData> scandatas = extra.getScanDatas();
for (ScanData sd : scandatas) {
System.out.println(sd.getData());
}
under all version, mapping can be varified correctly.
under version 3.2.5, new ExtraInfo can be saved. but the query with "left join fetch" can't return a Extra with set full of ScanData. the size of scandatas is 0.
under version 3.3.x, new ExtraInfo can't be saved. and the following exception is thrown:
java.lang.ClassCastException: java.lang.Integer
at org.hibernate.type.ComponentType.toLoggableString(ComponentType.java:400)
at org.hibernate.pretty.MessageHelper.collectionInfoString(MessageHelper.java:307)
at org.hibernate.engine.Collections.processReachableCollection(Collections.java:199)
at org.hibernate.event.def.FlushVisitor.processCollection(FlushVisitor.java:60)
at org.hibernate.event.def.AbstractVisitor.processValue(AbstractVisitor.java:124)
at org.hibernate.event.def.AbstractVisitor.processValue(AbstractVisitor.java:84)
at org.hibernate.event.def.AbstractVisitor.processEntityPropertyValues(AbstractVisitor.java:78)
at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:161)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:219)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:99)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:49)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1027)
.........
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the hibernate-issues
mailing list