-->
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: Best way to implement "features" column
PostPosted: Mon Jan 22, 2007 6:14 pm 
Newbie

Joined: Tue Jan 16, 2007 8:43 pm
Posts: 5
I'd like to get some opinions on what would be the best way to implement a features property. I have an object that has many "features" associated with it, properties such as "supports_xml" or "uses_department_code". I'd like to avoid a separate column for each feature, since there are so many of them. I'd also like to avoid creating a table linking features to objects.

Is there a way to implement this in an .hbm.xml? Prior to hibernate, we would store an integer in the database and logical-or it with powers of 2 to extract the state of a property, but I suspect with hibernate there is a more elegant solution.

Thanks for any suggestions.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 22, 2007 7:47 pm 
Newbie

Joined: Tue Dec 12, 2006 2:07 pm
Posts: 8
Storing an integer and ORing is fine. To incorporate this into hibernate you should create a dedicated type (e.g. org.hibernate.usertype.UserType) and a corresponding object.

Once you have create your type and the object (say FetauresType and Features) you can do something like

Code:
  MyEntity {
    @Type(type = "whatever.FeaturesType")
    Features features;
  }


and from you description I would suppose that the Features object would be simply

Code:
  Features {
    private final static SUPPORTS_XML = 0x80;
    ...

    private final int featuresCode;

    public boolean supportsXml() {
      return featuresCode & SUPPORTS_XML == SUPPORTS_XML;
    }
  }


HTH, PL


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 25, 2007 4:57 pm 
Newbie

Joined: Tue Jan 16, 2007 8:43 pm
Posts: 5
If I wanted to create a direct method such as entity.supportsXml() instead of entity.getFeatures().supportsXml(), is this possible within the .hbm.xml? I am using the hbm2java for POJO generation and my understanding is that the only way to use .supportsXml() as an abbreviation for .getFeatures().supportsXml() would be to add it into the POJO.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 25, 2007 8:38 pm 
Regular
Regular

Joined: Sun Sep 17, 2006 2:48 am
Posts: 81
Location: California
Another option could be to store those data as 1 XML (and if you want OO feature use JAXB). However you will lose the option of sorting/searching by those attributes.


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.