-->
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.  [ 5 posts ] 
Author Message
 Post subject: Instanciation of POJOs
PostPosted: Mon Nov 10, 2003 5:54 am 
Regular
Regular

Joined: Mon Oct 06, 2003 1:59 am
Posts: 52
Hi Folks,

I want to have mapped POJOs with a parameterized constructor in order to get Good Citziens (Objects with correct state - Not Nullable DB Fields).

First of all I read in Hibernate2 Reference that a Default Constructor is necessary for hibernate. Is there any way to get around this behavior?

Thx
Toby

_________________
"Wisest of the Maia was Ol


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 10, 2003 7:36 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Imagin
A has a reference to B
B has a reference to A

How to do that with good citizens strategy. We're not talking about components but objects.

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Instanciation of POJOs
PostPosted: Mon Nov 10, 2003 8:06 am 
Regular
Regular

Joined: Mon Oct 06, 2003 1:59 am
Posts: 52
epbernard wrote:
Imagin
A has a reference to B
B has a reference to A

How to do that with good citizens strategy. We're not talking about components but objects.


Do you really thing that cyclic references are a good desing technique?

In fact the strategy avoids to run into the problems with nullable datbase fields and safes us form adding hundrets of if != null assertions before persisting to database.

_________________
"Wisest of the Maia was Ol


Top
 Profile  
 
 Post subject: Re: Instanciation of POJOs
PostPosted: Mon Nov 10, 2003 8:44 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
tradem wrote:
Do you really thing that cyclic references are a good desing technique?

Yes, I'm positive.
As I told you, I think this is a design error to have such circular deps between components, and having constructor deps design seems better than bean deps design (Pico container tries to demonstrate that). But we're talking about object level design : this is called bidirectional relationship.

tradem wrote:
In fact the strategy avoids to run into the problems with nullable datbase fields and safes us form adding hundrets of if != null assertions before persisting to database.

Hum, what is the difference between that
Code:
if (myString1 != null) {
  myObj1.setString1(myString1);
}

and
Code:
if (myString1 != null) {
  myObj1 = new MyObj1(myString1);
}


Same number of if != null.

BTW, You can set to a private level your POJO setters, Hibernate can deal with that. Thus, common users must use your parameterized constructor.

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Re: Instanciation of POJOs
PostPosted: Mon Nov 10, 2003 10:36 am 
Regular
Regular

Joined: Mon Oct 06, 2003 1:59 am
Posts: 52
Quote:
Same number of if != null.


Of course you have to code your assertions, but with a assertive constructor you forbidd to get an object with incorrect state. It can be a ticking bomb leading to incorred data. All I want to do is to make it simple not not simply to follow a desing priciple blindly.

Quote:
BTW, You can set to a private level your POJO setters, Hibernate can deal with that. Thus, common users must use your parameterized constructor.


Ah! Then I now what to have to do.

_________________
"Wisest of the Maia was Ol


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