Eclipse Plugin Central

Hibernate Synchronizer - Using TreeSet without implement Comparable?

Anonymous - May 24, 2006 - 09:10 PM
Post subject: Using TreeSet without implement Comparable?
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?
steve40 - Aug 25, 2006 - 06:40 AM
Post subject: Re: Using TreeSet wo implement Comparable
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
TehOpenSourcerer - Jun 18, 2007 - 06:19 PM
Post subject: Re: Using TreeSet wo implement Comparable
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.
nasjam - May 28, 2008 - 08:21 AM
Post subject: RE: Re: Using TreeSet wo implement Comparable
Well i have not tried to use this code so far.
All times are GMT - 6 Hours
Powered by PNphpBB2 © 2003-2004 The PNphpBB Group
Credits