Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:
3.0.5
Mapping documents:
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">
<hibernate-mapping>
<class name="gov.epa.cdx.model.common.ParameterType" table="parameter_type">
<id name="id" column="id" type="string"/>
</class>
<class name="gov.epa.cdx.model.common.Parameter" table="parameter">
<composite-id>
<key-many-to-one name="parentId" column="parent_id" lazy="false"/>
<key-property name="name" column="name" type="string"/>
</composite-id>
<property name="value" column="value" type="string"/>
<property name="physicalType" column="value_type" type="string"/>
<many-to-one name="type" class="gov.epa.cdx.model.common.ParameterType" column="type_id" lazy="false"/>
</class>
<class name="gov.epa.cdx.model.dataflow.Dataflow" table="dataflow">
<id name="id" column="id" type="string"/>
<property name="name" column="name" type="string"/>
<map name="parameters" table="parameter" lazy="false">
<key column="parent_id"/>
<map-key formula="name" type="string"/>
<one-to-many class="gov.epa.cdx.model.common.Parameter"/>
</map>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():Code:
// hibernate configured through spring
public static Dataflow createDataflow(Dataflow dataflow)
throws DataAccessException {
if (dataflow.getId() == null) {
dataflow.setId(UUIDGenerator.getInstance()
.generateRandomBasedUUID().toString());
}
HibernateTemplate ht = new HibernateTemplate(ComponentBuilder
.getCoreSessionFactory());
ht.save(dataflow);
return dataflow;
}
Full stack trace of any exception that occurs:Code:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'coreSessionFactory' defined in class path resource [cdxcore2-components.xml]: Initialization of bean failed; nested exception is org.hibernate.MappingException: An association from the table parameter refers to an unmapped class: java.lang.String
Name and version of the database you are using:
MySql 5.0
What I want to do is use a generic parameter persistence mechanism for various objects in my domain. These objects are unrelated other than the fact that they have parameters. I would like the parameters to be stored in a map keyed by name. The dataflow object is the first of many that I would like to configure like this, which is why I don't explicitly name a class in the key-many-to-one attribute. What exactly am I doing wrong here? Is there another way I should be trying to accomplish the desired functionality?