openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Craig L Russell <Craig.Russ...@Sun.COM>
Subject Re: state-of-the art attribute initialization in persistent pojos?
Date Thu, 12 Apr 2007 15:57:56 GMT
Hi Hans,

On Apr 12, 2007, at 8:43 AM, Hans J. Prueller wrote:

> hi,
> as you know I am switching from EJB2.1 CMP to JPA (OpenJPA). I'd  
> like to know the preferred way to perform attribute initialisation  
> of newly created entity instances, e.g. we initialized our EJB2.1  
> CMP entity beans with
> ejbCreate(String cid, Integer someOtherValue)
> {
> setabc();
> setdef();
> }
> //and ejbPostCreate optionally
> as far as I know, the JPA spec requires a no-arg constructor - so  
> when providing a constructor with the same args that we have used  
> in ejbCreate before, we cannot ensure that some developer calls the  
> no-arg constructor by default.

The no-arg constructor can be private. The reason it's required is so  
the implementation doesn't have to guess what the right values are  
for final variables. But there's no requirement to make this  
constructor available to your applications.
> is there any other-more elegant way to force new entity instance  
> initialization?

There's no requirement for an ejbCreate and a separate ejbPostCreate  
for relationships. So you are really free to do whatever you like for  
the application contract. Have as many constructors as you like and  
put whatever initialization into them.

Just don't initialize the values of generated fields...

> regards,
> ===========================
> virtually hanzz...
>  <> (personal)
>  <>
> (research)

Craig Russell
Architect, Sun Java Enterprise System
408 276-5638
P.S. A good JDO? O, Gasp!

View raw message