state-of-the art attribute initialization in persistent pojos?
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. is there any other-more elegant way to force new entity instance initialization? regards, HANS === virtually hanzz... http://hanzz.zapto.org http://hanzz.zapto.org (personal) http://www.cse.dmu.ac.uk/~hansp http://www.cse.dmu.ac.uk/~hansp (research)
Re: state-of-the art attribute initialization in persistent pojos?
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... Craig regards, HANS === virtually hanzz... http://hanzz.zapto.org http://hanzz.zapto.org (personal) http://www.cse.dmu.ac.uk/~hansp http://www.cse.dmu.ac.uk/~hansp (research) Craig Russell Architect, Sun Java Enterprise System http://java.sun.com/products/jdo 408 276-5638 mailto:[EMAIL PROTECTED] P.S. A good JDO? O, Gasp! smime.p7s Description: S/MIME cryptographic signature
Re: state-of-the art attribute initialization in persistent pojos?
I thought the no-arg constructor had to be public or protected - see 2.1 Requirements on the Entity Class section where this is mentioned. If that's not the case so much better, but I have been adding a protected constructor in my entities. Cheers, Thomas Craig L Russell wrote: 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... Craig regards, HANS === virtually hanzz... http://hanzz.zapto.org http://hanzz.zapto.org (personal) http://www.cse.dmu.ac.uk/~hansp http://www.cse.dmu.ac.uk/~hansp (research) Craig Russell Architect, Sun Java Enterprise System http://java.sun.com/products/jdo 408 276-5638 mailto:[EMAIL PROTECTED] P.S. A good JDO? O, Gasp!