I'm trying to export/import to/from XML and MS SQL Server using the new EntityMode.DOM4J. It works great for most of the tables and even creates the appropriate XML for one of our link (a.ka. join) tables. I ahve a requirement to just import/export the join table and that fails with a ClassCastException. I have already searched the forums and have seen HHH-393. It looked similar and is fixed in 3.0.5 so I should have the fix (if that's the same problem).
Thanks.
Eric.
Hibernate version: 3.1beta2
Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping package="com.marketlive.entity.helper">
<class name="com.marketlive.entity.helper.ProductSkuLink" table="PRODUCT_SKU_LINK" lazy="false">
<composite-id name="pk" class="com.marketlive.entity.helper.ProductSkuLinkPk">
<key-property name="productPk" column="PRODUCT_ID" type="com.marketlive.entity.IntegerPkType"/>
<key-property name="skuPk" column="SKU_ID" type="com.marketlive.entity.IntegerPkType"/>
</composite-id>
<version name="version" column="VERSION" type="integer" unsaved-value="negative"/>
<property name="defaultProd" type="boolean" column="IS_DEFAULT"/>
<property name="dateCreated" type="timestamp" column="DATE_CREATED" update="false"/>
<!-- bi-directional many-to-one association to Category -->
<many-to-one name="sku" column="SKU_ID" insert="false" update="false" not-null="true"
class="com.marketlive.entity.sku.Sku"
foreign-key="PRODUCT_SKU_LINK_FK02"/>
<!-- bi-directional many-to-one association to Product -->
<many-to-one name="product" column="PRODUCT_ID" insert="false" update="false" not-null="true"
class="com.marketlive.entity.product.Product"
foreign-key="PRODUCT_SKU_LINK_FK01"
embed-xml="false"
/>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
SAXReader reader = new SAXReader();
Document doc = reader.read(new File("c:\\productSkuLinks.xml"));
Session session = HibernateUtil.currentSession();
Session s = session.getSession(EntityMode.DOM4J);
Transaction txn = session.beginTransaction();
{
List elems = doc.getRootElement().elements();
System.out.println("Number of elems: " + elems.size());
Iterator it = elems.iterator();
while(it.hasNext())
{
Element e = (Element)it.next();
s.replicate("com.marketlive.entity.helper.ProductSkuLink", e, ReplicationMode.OVERWRITE);
}
}
txn.commit();
HibernateUtil.closeSession();
Full stack trace of any exception that occurs:
java.lang.ClassCastException: com.marketlive.entity.helper.ProductSkuLinkPk
at org.hibernate.property.Dom4jAccessor$ElementGetter.get(Dom4jAccessor.java:191)
at org.hibernate.tuple.AbstractComponentTuplizer.getPropertyValue(AbstractComponentTuplizer.java:61)
at org.hibernate.tuple.AbstractComponentTuplizer.getPropertyValues(AbstractComponentTuplizer.java:67)
at org.hibernate.type.ComponentType.getPropertyValues(ComponentType.java:257)
at org.hibernate.type.ComponentType.nullSafeGetValues(ComponentType.java:230)
at org.hibernate.type.ComponentType.nullSafeSet(ComponentType.java:188)
at org.hibernate.loader.Loader.bindPositionalParameters(Loader.java:1456)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1518)
at org.hibernate.loader.Loader.doQuery(Loader.java:638)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:221)
at org.hibernate.loader.Loader.doList(Loader.java:1959)
at org.hibernate.loader.Loader.list(Loader.java:1943)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:94)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1314)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:298)
at com.marketlive.entity.product.ProductTest.testExportProductSkuLinks(ProductTest.java:163)
|