-->
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: How to map a set of Enum's?
PostPosted: Thu Jan 25, 2007 6:01 am 
Newbie

Joined: Thu Jun 15, 2006 8:32 am
Posts: 6
Hibernate version: 3.1.3

I used the Enhanced UserType described in: http://www.hibernate.org/272.html. Mapping a Enum works fine.

Now I want to map a set of Enum's. But I don't know how to do it.

Mapping documents:

Mapping file to store a Enum property

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 package="nl.tesis">
   <class name="License" table="license">

        <id name="key" type="string" column="licensekey" />
       
        <property name="description" type="string"/>
        <property name="categoryHierarchy" type="string"/>

        <property name="serviceAccessTest">
           <type name="nl.tesis.dao.impl.EnumUserType">
              <param name="enumClassName">nl.tesis.ServiceAccess</param>
           </type>
        </property>
       
   </class>
</hibernate-mapping>


Class:
Here is the class I'am using. I want to map the "private Set<ServiceAccess> serviceAccess" but I don't have a clue how.

Code:
public class License implements Serializable {
   private static final long serialVersionUID = 1L;
   
   private String key;
   private String description;
   private String categoryHierarchy;

   private ServiceAccess serviceAccessTest;

   private Set<ServiceAccess> serviceAccess;   
   
   /**
    * @return
    */
   public String getDescription() {
      return description;
   }

   public void setDescription(String description) {
      this.description = description;
   }
   
   /**
    * @return the categoryHierarchy
    */
   public String getCategoryHierarchy() {
      return categoryHierarchy;
   }

   /**
    * @param categoryHierarchy the categoryHierarchy to set
    */
   public void setCategoryHierarchy(String categoryHierarchy) {
      this.categoryHierarchy = categoryHierarchy;
   }
   
   /**
    * @return Returns the key.
    */
   public String getKey() {
      return key;
   }

   /**
    * @param key The key to set.
    */
   public void setKey(String key) {
      this.key = key;
   }
   
   /**
    * @return the serviceAccess
    */
   public Set<ServiceAccess> getServiceAccess() {
      return serviceAccess;
   }

   /**
    * @param serviceAccess the serviceAccess to set
    */
   public void setServiceAccess(Set<ServiceAccess> serviceAccess) {
      this.serviceAccess = serviceAccess;
   }

   @Override
   public boolean equals(Object obj) {
      if (obj instanceof License == false) {
         return false;
      }
      if (this == obj) {
         return true;
      }
      License license = (License) obj;
      return new EqualsBuilder()
         .append(key,license.getKey())
         .isEquals();
   }

   @Override
   public int hashCode() {
      return new HashCodeBuilder(17,37)
      .append(key)
      .toHashCode();
   }

   @Override
   public String toString() {
      return "license(" + (key == null ? "null" : key) + ")";
   }

   /**
    * @return the serviceAccessTest
    */
   public ServiceAccess getServiceAccessTest() {
      return serviceAccessTest;
   }

   /**
    * @param serviceAccessTest the serviceAccessTest to set
    */
   public void setServiceAccessTest(ServiceAccess serviceAccessTest) {
      this.serviceAccessTest = serviceAccessTest;
   }
}


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 25, 2007 6:57 am 
Newbie

Joined: Thu Jun 15, 2006 8:32 am
Posts: 6
I found the solution in this thread: http://forum.hibernate.org/viewtopic.php?t=949733

The set:
Code:
private Set<ServiceAccess> serviceAccess = EnumSet.noneOf(ServiceAccess.class);


Mapping part:

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 package="nl.tesis">

             <typedef name="serviceAccessType" class="nl.tesis.dao.impl.EnumUserType">
              <param name="enumClassName">nl.tesis.ServiceAccess</param>
           </typedef>

   <class
      name="License"
      table="license">



      <!-- Identifier -->
        <id name="key" type="string" column="licensekey" />
       
        <!-- Simple properties -->       
        <property name="description" type="string"/>
        <property name="categoryHierarchy" type="string"/>

        <set name="serviceAccess" cascade="all" table="service_access">
           <key column="licensekey"></key>
         <element column="serviceAccess" type="serviceAccessType" />
        </set>
   </class>
   
</hibernate-mapping>


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.