-->
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.  [ 2 posts ] 
Author Message
 Post subject: mapping name/value pair into java.util.Properties
PostPosted: Wed Feb 28, 2007 1:46 pm 
Newbie

Joined: Wed Feb 28, 2007 1:22 pm
Posts: 2
i have a case want to map building name/value pair, here is the mapping xml, sql and class(simplified).
i make 2 class for the mapping, but hibernate does map the name/vale pair in the properties.
how can i make hibernate map the buildingproperties in building

hibernate version:hibernate-3.2.2.ga

Code:
create table building
(
   id         integer         not null,
   address      varchar(256)   not null,
   primary key (id)
);

create table buildingproperty
(
   buildingid   integer         not null,
   name      varchar(32)      not null,
   value      varchar(256)   not null,
   primary key(buildingid, name)
);

public class Building
{
   private int id;
   private String address;
   private Properties buildingproperties;

   // getters and setters

   public String getProperty(String name)
   {
      return buildingproperties.getProperty(name);
   }

   public String setProperty(String name, String value)
   {
      buildingproperties.setProperty(name, value);
   }
}

// this class make for mapping
public class BuildingProperty
{
   private int buildingid;
   private String name;
   private String value;

   // getters and setters
}

<hibernate-mapping>
   <class name="Building" table="building">
      <id name="id" type="int">
         <generator class="native"/>
      </id>
      <property name="address" type="java.lang.String" not-null="true"/>
      <map name="buildingproperties">
         <key column="id"/>
         <map-key column="name" type="java.lang.String"/>
         <element column="value" type="java.lang.String"/>
<!--
         <one-to-many class="BuildingProperty"/>
-->
      </map>
   </class>
   <class name="BuildingProperty" table="buildingproperty">
      <composite-id>
         <key-property name="buildingid" type="int"/>
         <key-property name="name" type="java.lang.String"/>
      </composite-id>
      <property name="value" type="java.lang.String" not-null="true"/>
   </class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 28, 2007 2:01 pm 
Newbie

Joined: Wed Feb 28, 2007 1:22 pm
Posts: 2
i also modify the Building class to use Map<String, String> to hold the properties, but still no work.

Code:
public class Building
{
   private int id;
   private String address;
   private Map<String, String> buildingproperties;

   // getters and setters

   public String getProperty(String name)
   {
      return buildingproperties.get(name);
   }

   public String setProperty(String name, String value)
   {
      buildingproperties.put(name, value);
   }
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.