Plugins (1057)


Training and Consulting (44)



EPIC Poll

What is your favourite developer portal?

[ Results | Polls ]

Votes: 541
Comments: 0

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
lueo
Post subject: Using TreeSet without implement Comparable?  PostPosted: May 24, 2006 - 09:10 PM
Guest





The following code described a relationship between "Components" and "Configurations" is generated automatically by HS (3.1.9):
Code:
   public void addToConfigurations (org.lueo.cr.Configurations configurations) {
      if (null == getConfigurations()) setConfigurations(new java.util.TreeSet<org.lueo.cr.Configurations>());
      getConfigurations().add(configurations);
   }

If you use this method like this:
Code:
Components comp = new Components();
comp.addToConfigurations(conf1);
comp.addToConfigurations(conf2);

The question is, the POJO class "Configurations" hadn't implemented Comparable, so if we added the second element to the TreeSet (using addToConfigurations() ), we would get a ClassCastException.

Fortunately, there is another method:
Code:
   /**
    * Set the value related to the column: Configurations
    * @param configurations the Configurations value
    */
   public void setConfigurations (java.util.Set<org.lueo.cr.Configurations> configurations) {
      this.configurations = configurations;
   }

Thus I came up a workaround:
Code:
Components comp = new Components();
Set<Configurations> confs = new HashSet<Configurations>();
confs.add(conf1);
confs.add(conf2);
comp.setConfigurations(conf);

Any suggestions?
 
   
Reply with quote Back to top
steve40
Post subject: Re: Using TreeSet wo implement Comparable  PostPosted: Aug 25, 2006 - 06:40 AM



Joined: Aug 25, 2006
Posts: 1

you have to include a meta-tag in your mapping document, to give HS a hint what kind of implementing class to use. e.g.

<set name="accounts" inverse="true">
<key column="ID"/>
<one-to-many class="Account"/>
<meta attribute="implementation-class">java.util.HashSet</meta>
</set>

hth steve
 
 View user's profile Send private message  
Reply with quote Back to top
TehOpenSourcerer
Post subject: Re: Using TreeSet wo implement Comparable  PostPosted: Jun 18, 2007 - 06:19 PM



Joined: Jun 18, 2007
Posts: 1

steve40 wrote:
you have to include a meta-tag in your mapping document, to give HS a hint what kind of implementing class to use. e.g.

<set name="accounts" inverse="true">
<key column="ID"/>
<one-to-many class="Account"/>
<meta attribute="implementation-class">java.util.HashSet</meta>
</set>

hth steve


Thanks for this! I've been looking for a way to do this for a week or so now. This makes me a very happy person.
 
 View user's profile Send private message  
Reply with quote Back to top
nasjam
Post subject: RE: Re: Using TreeSet wo implement Comparable  PostPosted: May 28, 2008 - 08:21 AM



Joined: May 28, 2008
Posts: 4

Well i have not tried to use this code so far.
 
 View user's profile Send private message  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT - 6 Hours
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2004 The PNphpBB Group
Credits