-->
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.  [ 1 post ] 
Author Message
 Post subject: Mapping Generic Properties
PostPosted: Tue Mar 11, 2008 9:52 am 
Newbie

Joined: Tue Mar 11, 2008 9:22 am
Posts: 3
Hi Guys

I am attempting to map a many-to-many relationship so that a Customer can have many "Properties" and each property is of a specific PropertyType.

The mapping looks like:
Code:
  <class name="Customer" table="customer">
    <id name="id">
      <generator class="sequence">
        <param name="sequence">CUSTOMER_ID_SEQ</param>
      </generator>
    </id>

    <bag name="properties" lazy="false" cascade="save-update" table="customer_property">
      <key column="customer_id"/>
      <one-to-many class="CustomerProperty"/>
    </bag>
  </class>


  <class name="PropertyType" table="property_type" mutable="false">
    <id name="id">
      <generator class="assigned"/>
    </id>
    <property name="name" column="name"/>
  </class>


  <class name="CustomerProperty" table="customer_property">
    <id name="id">
      <generator class="sequence">
        <param name="sequence">CP_ID_SEQ</param>
      </generator>
    </id>
    <property name="value" column="value"/>
    <many-to-one name="propertyType" column="property_type_id" class="PropertyType" lazy="false" fetch="join"/>
  </class>


This mapping works fine and allows me to fetch and update a Customer and their properties but my issue arises when I want to add a Property to a Customer.

I need a method on my Customer entity like addProperty( final String propertyName, final String value) (i.e. I know the name of the property type but I don't have the PropertyType object or it's primary key).

I think I need to define a UserType for the PropertyType column but I can't see any way that I can get a Session in a UserType so that I can load the appropriate PropertyType from the database.

Can anyone steer me in the best direction ?

Thanks
Andy


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

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.