openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Albert Lee (JIRA)" <>
Subject [jira] [Commented] (OPENJPA-2403) Enhancer yields "does not have a public no-args constructor." exception for entity with protected qualified constructor
Date Wed, 04 Sep 2013 13:49:52 GMT


Albert Lee commented on OPENJPA-2403:

The original exception is complaining the id class NOT the entity class not having a public
no-arg constructor. 

Here are the sections in the spec defining the requirements that a composite primary key MUST
have a public no-arg constructor.
2.1 The Entity Class
The entity class must have a no-arg constructor. The entity class may have other constructors
as well.
The no-arg constructor must be public or protected.

2.4 Primary Keys and Entity Identity
A composite primary key must correspond to either a single persistent field or property or
to a
set of such fields or properties as described below. A primary key class must be defined to
a composite primary key. Composite primary keys typically arise when mapping from
legacy databases when the database key is comprised of several columns. The EmbeddedId
or IdClass annotation is used to denote a composite primary key.

The following rules apply for composite primary keys:
• The primary key class must be public and must have a public no-arg constructor.

2.5 Embeddable Classes
Embeddable classes must adhere to the requirements specified in Section 2.1 for entities....
> Enhancer yields "does not have a public no-args constructor." exception for entity with
protected qualified constructor
> -----------------------------------------------------------------------------------------------------------------------
>                 Key: OPENJPA-2403
>                 URL:
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: Enhance
>    Affects Versions: 2.0.3, 2.1.2, 2.3.0, 2.2.3
>            Reporter: Albert Lee
>            Assignee: Albert Lee
>         Attachments: OPENJPA-2403.patch
> Entity with protected qualified constructor:
> @Entity 
> public class Kunde {
>     ....
> 	protected Kunde() {
> 		// jpa constructor
> 	}
>     ....
> }
> causes enhancer to fail with message like:
> C:\>wsenhancer test\Kun*.class
> 82  ConstructorDemoWeb  INFO   [main] openjpa.Tool - Enhancer running on type "class
> Exception in thread "main" <openjpa-2.2.3-SNAPSHOT-r422266:1485013 fatal user error>
org.apache.openjpa.util.MetaDataException: The id class "class test.Kundennummer"
>  specified by type "class test.Kunde" does not have a public no-args constructor.
>         at org.apache.openjpa.meta.ClassMetaData.validateAppIdClassMethods(
>         at org.apache.openjpa.meta.ClassMetaData.validateAppIdClass(
>         at org.apache.openjpa.meta.ClassMetaData.validateIdentity(
>         at org.apache.openjpa.meta.ClassMetaData.validateMeta(
>         at org.apache.openjpa.meta.ClassMetaData.resolve(
>         at org.apache.openjpa.meta.MetaDataRepository.processBuffer(
>         at org.apache.openjpa.meta.MetaDataRepository.resolveMeta(
>         at org.apache.openjpa.meta.MetaDataRepository.resolve(
>         at org.apache.openjpa.meta.MetaDataRepository.getMetaDataInternal(
>         at org.apache.openjpa.meta.MetaDataRepository.getMetaData(
>         at org.apache.openjpa.enhance.PCEnhancer.<init>(
>         at
>         at
>         at org.apache.openjpa.enhance.PCEnhancer$
>         at org.apache.openjpa.lib.conf.Configurations.launchRunnable(
>         at org.apache.openjpa.lib.conf.Configurations.runAgainstAllAnchors(
>         at
>         at org.apache.openjpa.enhance.PCEnhancer.main(
> Caused by: java.lang.NoSuchMethodException: test.Kundennummer.<init>()
>         at java.lang.Class.throwNoSuchMethodException(
>         at java.lang.Class.getConstructor(
>         at org.apache.openjpa.meta.ClassMetaData.validateAppIdClassMethods(
>         ... 17 more

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see:

View raw message