persistence@glassfish.java.net

Re: Does "the class must have a public no-argument constructor" mean that I must declare it, even if it is the sole constructor?

From: Aleksei Valikov <aleksei.valikov_at_gmail.com>
Date: Fri, 25 Apr 2008 14:31:56 +0200

Hi.

> The EJB 3.0 Persistence specification says for entities and primary keys,
> that those classes must "have" a public no-argument constructor.
>
> In the case that I do not have any other constructors, does "have" mean
> that I must declare such a constructor (even if it is useless, since the
> default constructor can serve the same purpose), or is the implicit default
> constructor enough to "have"? In other words, can I omit my empty
> constructor IN THAT CASE in favour of the default constructor?

In this case the default constructor is the public no-arg constructor,
you don't need to redeclare anything.
The idea is that the EJB layer could call yourClass.newInstance() to
construct a new instance.

Bye.
/lexi