-->
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.  [ 6 posts ] 
Author Message
 Post subject: Generating Collections instead of Sets
PostPosted: Fri Jun 09, 2006 6:09 am 
Newbie

Joined: Tue Apr 18, 2006 6:11 am
Posts: 11
Hi,

is it currently possible to change the generated Set type to Collection type?

So instead of writing:

private Set<Person> personSet = new HashSet<Person>(0);

generate:

private Collection<Person> personSet = new HashSet<Person>(0);

Obviously setters and getters should also change.

cheers,

Gerald


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 09, 2006 6:58 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
wow that is the first time someone asked me to generate more abstract than specific code - congratulations! :)

You can control the property type via <meta attribute="property-type">java.util.Collection</meta>

(in current release it won't handle the generics part automatically, but the SVN version does)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 09, 2006 7:08 am 
Newbie

Joined: Tue Apr 18, 2006 6:11 am
Posts: 11
Thx for reply, but I need the other way round.

Think you mean putting the meta attribute to the mapping file. But we are generating mappings and pojos from db. I have already introduced a reveng.xml file, a custom strategy and templates.

Is it possible with some hacking in the templates?

cheers,

Gerald


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 09, 2006 7:21 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
currently we don't support injecting meta attributes into the reverse engineered result.

But hacking the templates is always possible ;)

Should be doable by just inserting the <meta attribute="property-type">java.util.Collection</meta> the right place in set.hbm.ftl

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 11, 2006 6:26 am 
Newbie

Joined: Tue Apr 18, 2006 6:11 am
Posts: 11
Many thanks, generating type of collection does work now.

A new problem is that supporting generics doesn`t work now, which actually works before in case of the sets.

First i generate mapping files through jdbc connection like this:

Code:
<hbm2hbmxml destdir="${hbm-output.dir}" templatepath="${template.dir}" /> 


With help of your suggested template, generated mapping fragment looks like:

Code:
<set name="persons" inverse="true">
            <meta attribute="property-type">java.util.Collection</meta>

            <key>
                <column name="ADR_ID" precision="10" scale="0" not-null="true" />
            </key>

            <one-to-many class="xx.yy.zz.Person" />
        </set>


After it, pojos are generated from mappings with a simple configuration:

Code:
<hbm2java destdir="${pojo-output.dir}" templatepath="${template.dir}" jdk5="true" />


Result is really nice, but generics are not inserted:

Code:
private Collection persons;


instead of:

Code:
private Collection<Person> persons;


Any well-known reason why?

cheers,

Gerald


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 11, 2006 12:12 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
Quote:
(in current release it won't handle the generics part automatically, but the SVN version does)


...repeat of posting ;)

_________________
Max
Don't forget to rate


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.