Hi all,
During insertion I have exception:
Quote:
java.lang.ClassCastException: org.phibase.database.schema.GeneNamesId cannot be cast to java.lang.Integer
The values are inserted to the database.
GeneNamesId is related with Gene Name table which is mapped:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 01-Dec-2010 22:43:46 by Hibernate Tools 3.4.0.Beta1 -->
<hibernate-mapping>
<class name="org.phibase.database.schema.GeneNames" table="GeneNames">
<composite-id name="id" class="org.phibase.database.schema.GeneNamesId">
<key-property name="referenceGeneId" type="int">
<column name="referenceGeneID" />
</key-property>
<key-property name="name" type="string">
<column name="name" />
</key-property>
<key-property name="pragmaDisplay" type="boolean">
<column name="pragmaDisplay" />
</key-property>
</composite-id>
<many-to-one name="referencePhysicalGene" class="org.phibase.database.schema.ReferencePhysicalGene" update="false" insert="false" fetch="select">
<column name="referenceGeneID" not-null="true" />
</many-to-one>
</class>
</hibernate-mapping>
I am not fluent in hibernate but IMHO it looks correct.
I load the values using save from dao:
Code:
...
@Transactional
@Override
public Integer save(T item) {
return (Integer) getHibernateTemplate().save(item);
}
...
Fist I save ReferencePhysicalGene. Than I save to database and method returns gene id. After that I do that:
Code:
String[] geneNames = { "name1", "name2", "name3", "name4" };
for (String name : geneNames) {
try {
GeneNamesId geneNamesIdObject = new GeneNamesId(refGeneId,
name, false);
GeneNames geneNamesObject = new GeneNames();
geneNamesObject.setId(geneNamesIdObject);
geneNamesDAO.save(geneNamesObject);
session.flush();
} catch (Exception e) {
log.error("Error with name: " + name, e);
}
}
After each insertion I do flush. IMHO everything is OK. For me it looks like a bug.
Regards,
Jacek