I stand corrected. From the spec, 2.1:The entity class must have a no-argconstructor. The entity class may have other constructors as well.
The no-arg constructor must be public or protected.
Adding a protected no-arg constructor if your class is migrating from CMP to EJB 3 seems to be best practice if you want to encourage use of other constructors.
Craig On Apr 12, 2007, at 10:29 AM, Thomas Risberg wrote:
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 liketo 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 sothe implementation doesn't have to guess what the right values are forfinal 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... Craigregards, 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 RussellArchitect, Sun Java Enterprise System http://java.sun.com/products/ jdo408 276-5638 mailto:[EMAIL PROTECTED] P.S. A good JDO? O, Gasp!
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