-->
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.  [ 13 posts ] 
Author Message
 Post subject: initialize collections with hbm2java
PostPosted: Wed Jun 01, 2005 11:58 am 
Newbie

Joined: Wed Jun 01, 2005 11:39 am
Posts: 8
Hibernate version:
hibernate 2.1.8
hibernate-extensions 2.1.3

Hi,

is it possible to initialize my collections (set) in the classes generated with the hbm2java tool. because if i save an object with an uninitialized collection (set == null) and load it in another session, the collection is no more null but initialized (empty).
if i compare the saved and loaded object with equals (collection use-in-equals=true) i get therefore an false. (i know that collections should not be a equals element but there is no other way in this)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 01, 2005 3:25 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
not directly, but you can add a meta attribute="extra-code" where you can have a constructor block initialize your code.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 02, 2005 3:38 am 
Newbie

Joined: Wed Jun 01, 2005 11:39 am
Posts: 8
hi,

thanks for the answer, but i´m not sure i understand. the meta attribute is
"class-code" i think but how can i add some code which is called from my constructor. i can´t change the generated constructors i think. can you give a little example?

thommy


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 02, 2005 2:19 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
<class ...>
<meta attribute="extra-code">{ ..this code is in a constrcutor block, will be called when constructing the object... }</meta>
</class>

/max

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 03, 2005 3:51 am 
Newbie

Joined: Wed Jun 01, 2005 11:39 am
Posts: 8
hi again,

sorry if this is my fault but i think there isn´t a meta-attribute called extra-code. it´s neither in der reference manual nor in the hibernate in action book mentioned. and if i trie the following it doesn´t work.

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping package="src_base">

....
<class name="myclass table="MYCLASS"...>
...
<meta attribute="extra-code">{ initCollections(); }</meta>
...
</class>


if i generete my POJO´s the meta attribute="extra-code" is completely ignored. i think "extra-code" isn´t a standard meta attribute in hibernate-extensions 2.1.3.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 03, 2005 4:18 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
soory - its class-code (in the docs)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 03, 2005 4:27 am 
Newbie

Joined: Wed Jun 01, 2005 11:39 am
Posts: 8
hi,

ok. but with class-code i can´t add some code, that is automatically called in all (default, maximal, minmal) constructors, or? the problem is that we generate some base classes and our buisness classes extend from these.
so it would be appreciated when the initalization of collections is done in the generated pojo´s and not to write by hand in the business model. but in my opinion there is no way to do this in the moment, or? thanks.

thommy


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 03, 2005 4:39 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
please read the java lang spec about what {} does in class code.

If that is not enough then open jira requests for adding initialization code to the pojo (contributions will it make it more likely that it gets in there ;)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 03, 2005 4:56 am 
Newbie

Joined: Wed Jun 01, 2005 11:39 am
Posts: 8
ok, you are right ;-)

it seems {} is called from every constructor call (default, minimal, full).
peferct. thank you very much. by the way, why are all sets even if they are nullable in the generated minimal constructor?

thommy


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 03, 2005 5:01 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
didn't understand your question.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 03, 2005 5:40 am 
Newbie

Joined: Wed Jun 01, 2005 11:39 am
Posts: 8
i mean if i have some collections in my pojo which are (from buisness logic) nullable. i can´t tell hibernate that these objects (one-to-many) relation should be nullable and therefore the generated minimal constructor includes all collections...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 03, 2005 5:50 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
well in h3 tools we dont generate any constructors so no problem ;)

(the minimal constructor stuff logic were not good enough as you can see...contributions welcome to do it better)

/max

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 03, 2005 8:02 am 
Newbie

Joined: Wed Jun 01, 2005 11:39 am
Posts: 8
thanks again. so is it possible to not generate any constructors with hbm2java?


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