openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Albert Lee (JIRA)" <j...@apache.org>
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

    [ https://issues.apache.org/jira/browse/OPENJPA-2403?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13757769#comment-13757769
] 

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
represent
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: https://issues.apache.org/jira/browse/OPENJPA-2403
>             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
at.arz.domain.core.Kunde".
> 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(ClassMetaData.java:2161)
>         at org.apache.openjpa.meta.ClassMetaData.validateAppIdClass(ClassMetaData.java:2067)
>         at org.apache.openjpa.meta.ClassMetaData.validateIdentity(ClassMetaData.java:2034)
>         at org.apache.openjpa.meta.ClassMetaData.validateMeta(ClassMetaData.java:1946)
>         at org.apache.openjpa.meta.ClassMetaData.resolve(ClassMetaData.java:1807)
>         at org.apache.openjpa.meta.MetaDataRepository.processBuffer(MetaDataRepository.java:828)
>         at org.apache.openjpa.meta.MetaDataRepository.resolveMeta(MetaDataRepository.java:725)
>         at org.apache.openjpa.meta.MetaDataRepository.resolve(MetaDataRepository.java:649)
>         at org.apache.openjpa.meta.MetaDataRepository.getMetaDataInternal(MetaDataRepository.java:417)
>         at org.apache.openjpa.meta.MetaDataRepository.getMetaData(MetaDataRepository.java:388)
>         at org.apache.openjpa.enhance.PCEnhancer.<init>(PCEnhancer.java:286)
>         at org.apache.openjpa.enhance.PCEnhancer.run(PCEnhancer.java:4885)
>         at org.apache.openjpa.enhance.PCEnhancer.run(PCEnhancer.java:4831)
>         at org.apache.openjpa.enhance.PCEnhancer$1.run(PCEnhancer.java:4801)
>         at org.apache.openjpa.lib.conf.Configurations.launchRunnable(Configurations.java:761)
>         at org.apache.openjpa.lib.conf.Configurations.runAgainstAllAnchors(Configurations.java:751)
>         at org.apache.openjpa.enhance.PCEnhancer.run(PCEnhancer.java:4796)
>         at org.apache.openjpa.enhance.PCEnhancer.main(PCEnhancer.java:4787)
> Caused by: java.lang.NoSuchMethodException: test.Kundennummer.<init>()
>         at java.lang.Class.throwNoSuchMethodException(Class.java:327)
>         at java.lang.Class.getConstructor(Class.java:354)
>         at org.apache.openjpa.meta.ClassMetaData.validateAppIdClassMethods(ClassMetaData.java:2159)
>         ... 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: http://www.atlassian.com/software/jira

Mime
View raw message