-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Question about <map> definitions when using composite
PostPosted: Tue Oct 11, 2005 10:55 am 
Newbie

Joined: Tue Oct 11, 2005 10:45 am
Posts: 6
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?


Top
 Profile  
 
 Post subject: Re: Question about <map> definitions when using compos
PostPosted: Tue Oct 11, 2005 10:58 am 
Newbie

Joined: Tue Oct 11, 2005 10:45 am
Posts: 6
dune wrote:
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?


Just to clarify, both dataflow and parameter have a "name" attribute, but they are unrelated.


Top
 Profile  
 
 Post subject: solved
PostPosted: Tue Oct 11, 2005 3:23 pm 
Newbie

Joined: Tue Oct 11, 2005 10:45 am
Posts: 6
I was able to solve the problem by changing the mapping (and underlying db structure). Instead of using a composite pk, I changed it to have an auto-increment id and a natural-key. Uniqueness is implicitly enforced by the fact that the params are stored in a map (a new param of the same name would just replace the existing one).

Code:
<class name="gov.epa.cdx.model.common.Parameter" table="parameter">
      <id name="id" column="id" type="long">
         <generator class="increment"/>
      </id>
      <natural-id>
         <property name="parentId" column="parent_id" type="string" insert="false" update="false"/>
         <property name="name" column="name" type="string"/>
      </natural-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" cascade="all">
         <key column="parent_id" not-null="true"/>
         <map-key formula="name" type="string"/>
         <one-to-many class="gov.epa.cdx.model.common.Parameter"/>
      </map>
   </class>


Top
 Profile  
 
 Post subject: Spoke to soon...
PostPosted: Tue Oct 11, 2005 4:11 pm 
Newbie

Joined: Tue Oct 11, 2005 10:45 am
Posts: 6
Now I'm getting the following error when I add an additional mapping. I guess the general question is how do you specify an "open-ended" many-to-one relationship (i.e. multiple parent tables)?

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>
   <!-- ============================================================================ -->
   <!--                             Parameter Definition                             -->
   <!-- ============================================================================ -->
   <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">
      <id name="id" column="id" type="long">
         <generator class="increment"/>
      </id>
      <natural-id>
         <property name="parentId" column="parent_id" type="string" insert="false" update="false"/>
         <property name="name" column="name" type="string"/>
      </natural-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>
   <!-- ============================================================================ -->
   <!--                             Dataflow Definition                              -->
   <!-- ============================================================================ -->
   <class name="gov.epa.cdx.model.dataflow.Dataflow" table="dataflow">
      <id name="id" column="id" type="string"/>
      <property name="name" column="name" type="string"/>
      <bag name="services" table="dataflow_services" lazy="false" cascade="delete" inverse="true">
         <key column="dataflow_id"/>
         <one-to-many class="gov.epa.cdx.model.dataflow.Service"/>
      </bag>
      <map name="parameters" table="parameter" lazy="false" cascade="all">
         <key column="parent_id" not-null="true"/>
         <map-key formula="name" type="string"/>
         <one-to-many class="gov.epa.cdx.model.common.Parameter"/>
      </map>
   </class>
   <class name="gov.epa.cdx.model.dataflow.Service" table="dataflow_service">
      <id name="id" column="id" type="string"/>
      <property name="name" column="name" type="string"/>
      <many-to-one name="dataflow" class="gov.epa.cdx.model.dataflow.Dataflow" column="dataflow_id" not-null="true"/>
   </class>
   <!-- ============================================================================ -->
   <!--                             Activity Definition                              -->
   <!-- ============================================================================ -->
   <class name="gov.epa.cdx.model.activity.ActivityStatus" table="activity_status">
      <id name="id" column="id" type="string"/>
   </class>
   <class name="gov.epa.cdx.model.activity.ActivityType" table="activity_type">
      <id name="id" column="id" type="string"/>
   </class>
   <class name="gov.epa.cdx.model.activity.Activity" table="activity">
      <id name="id" column="id" type="string"/>
      <property name="description" column="description" type="string" lazy="false"/>
      <property name="dateCreated" column="date_created" type="long" lazy="false"/>
      <many-to-one name="type" class="gov.epa.cdx.model.activity.ActivityType" column="type_id" lazy="false"/>
      <many-to-one name="status" class="gov.epa.cdx.model.activity.ActivityStatus" column="status_id" lazy="false"/>
      <many-to-one name="dataflow" class="gov.epa.cdx.model.dataflow.Dataflow" column="dataflow_id" lazy="false"/>
      <component name="user" class="gov.epa.cdx.model.user.User" insert="true" update="true" lazy="false">
         <property name="id" column="initiator_id"/>
      </component>
      <map name="parameters" table="parameter" lazy="false" cascade="all">
         <key column="parent_id" not-null="true"/>
         <map-key formula="name" type="string"/>
         <one-to-many class="gov.epa.cdx.model.common.Parameter"/>
      </map>
   </class>
</hibernate-mapping>



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: duplicate property mapping: _parametersBackref


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.