| Author |
Message |
|
|
Post subject: Using TreeSet without implement Comparable?
Posted: May 24, 2006 - 09:10 PM
|
|
|
|
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? |
|
|
| |
|
|
|
 |
|
|
Post subject: Re: Using TreeSet wo implement Comparable
Posted: 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 |
|
|
| |
|
|
|
 |
|
|
Post subject: Re: Using TreeSet wo implement Comparable
Posted: 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. |
|
|
| |
|
|
|
 |
|
|
Post subject: RE: Re: Using TreeSet wo implement Comparable
Posted: May 28, 2008 - 08:21 AM
|
|
Joined: May 28, 2008
Posts: 4
|
|
| Well i have not tried to use this code so far. |
|
|
| |
|
|
|
 |
|
|
| |