Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 351791 - NPE occurs on specifying two kinds of primary key generators on orm.xml
Summary: NPE occurs on specifying two kinds of primary key generators on orm.xml
Status: CLOSED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P2 normal (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL:
Whiteboard: submitted_patch
Keywords:
: 331956 (view as bug list)
Depends on:
Blocks:
 
Reported: 2011-07-12 02:03 EDT by Masumi Ito CLA
Modified: 2022-06-09 10:36 EDT (History)
4 users (show)

See Also:


Attachments
Reproducible application (13.21 KB, application/x-zip-compressed)
2011-07-12 02:09 EDT, Masumi Ito CLA
no flags Details
Patch for this issue (2.08 KB, patch)
2011-07-12 02:24 EDT, Masumi Ito CLA
tom.ware: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Masumi Ito CLA 2011-07-12 02:03:21 EDT
Build Identifier: 

When defining both SequenceGenerator and TableGenerator on orm.xml, 
NullPointerException occurs on building its metadata if pkColumnValue of the TableGenerator is not specified.

EX) orm.xml

        <sequence-generator name="SEQ_GEN" allocation-size="1"/>
        <table-generator name="TBL_GEN" table="NAME_TBL"/>
        <attributes>
            <id name="id">
                <generated-value strategy="SEQUENCE" generator="SEQ_GEN"/>
            </id>
        </attributes>

EX) StackTrace of NPE

Internal Exception: java.lang.NullPointerException
	at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.predeploy(EntityManagerSetupImpl.java:1127)
	at org.eclipse.persistence.jpa.PersistenceProvider.createContainerEntityManagerFactory(PersistenceProvider.java:187)
	at org.glassfish.persistence.jpa.PersistenceUnitLoader.loadPU(PersistenceUnitLoader.java:205)
	at org.glassfish.persistence.jpa.PersistenceUnitLoader.<init>(PersistenceUnitLoader.java:119)
	at org.glassfish.persistence.jpa.JPADeployer$1.visitPUD(JPADeployer.java:214)
	at org.glassfish.persistence.jpa.JPADeployer$PersistenceUnitDescriptorIterator.iteratePUDs(JPADeployer.java:483)
	at org.glassfish.persistence.jpa.JPADeployer.createEMFs(JPADeployer.java:221)
	at org.glassfish.persistence.jpa.JPADeployer.prepare(JPADeployer.java:167)
         ...
Caused by: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.2.0.v20110202-r8913): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Predeployment of PersistenceUnit [pu1] failed.
Internal Exception: java.lang.NullPointerException
	at org.eclipse.persistence.exceptions.EntityManagerSetupException.predeployFailed(EntityManagerSetupException.java:210)
	... 62 more
Caused by: java.lang.NullPointerException
	at org.eclipse.persistence.internal.jpa.metadata.MetadataProject.addSequenceGenerator(MetadataProject.java:630)
	at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.MappedSuperclassAccessor.processSequenceGenerator(MappedSuperclassAccessor.java:1237)
	at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.MappedSuperclassAccessor.process(MappedSuperclassAccessor.java:655)
	at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.EntityAccessor.process(EntityAccessor.java:599)
	at org.eclipse.persistence.internal.jpa.metadata.MetadataProject.processStage2(MetadataProject.java:1541)
	at org.eclipse.persistence.internal.jpa.metadata.MetadataProcessor.processORMMetadata(MetadataProcessor.java:485)
	at org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProcessor.processORMetadata(PersistenceUnitProcessor.java:454)
	at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.predeploy(EntityManagerSetupImpl.java:1081)

Although this issue was originally detected when deploying a JPA2.0 app on GlassfishV3.2(EclipseLink2.2), the latest version of EclipseLink also seems to have same issue.

Reproducible: Always
Comment 1 Masumi Ito CLA 2011-07-12 02:09:15 EDT
Created attachment 199465 [details]
Reproducible application
Comment 2 Masumi Ito CLA 2011-07-12 02:18:43 EDT
The reason of this issue is to call getPkColumnValue() in MetadataProject class without checking null.

public void addSequenceGenerator(SequenceGeneratorMetadata sequenceGenerator, String defaultCatalog, String defaultSchema) {
  ...
            if ((tableGenerator != otherTableGenerator) && (otherTableGenerator.getPkColumnValue() != null) && otherTableGenerator.getPkColumnValue().equals(sequenceGenerator.getSequenceName())) {
    }
  ...
}

According to JPA2.0 spec, pkColumn Value is optional, so it is sometimes omitted.
Comment 3 Masumi Ito CLA 2011-07-12 02:24:20 EDT
Created attachment 199466 [details]
Patch for this issue

Attached a patch based on EclipseLink 2.2.0.v20110202-r8913.
Comment 4 Masumi Ito CLA 2011-07-12 02:34:01 EDT
About the attached patch:

Because MappedSuperclassAccessor#process() always calls processSequenceGenerator() after calling processTableGenerator(), MetadataProject#addTableGenerator() doesn't seem to throw NPE. However potentially addTableGenerator() also has similar issue in terms of optional SequenceName of SequenceGenerator.
Comment 5 Tom Ware CLA 2011-07-21 08:48:15 EDT
Setting target and priority.  See the following page for the meanings of these fields:

http://wiki.eclipse.org/EclipseLink/Development/Bugs/Guidelines

Community: Please vote for this bug if it is important to you.  Votes are one of the main criteria we use to determine which bugs to fix next.
Comment 6 Tom Ware CLA 2011-07-21 08:49:55 EDT
Assigning to myself with the goal of checking the supplied patch.
Comment 7 Tom Ware CLA 2011-08-09 13:50:56 EDT
Looking at including patch in 2.3.1
Comment 8 Tom Ware CLA 2011-08-09 16:11:48 EDT
Fixed in 2.3.1 and trunk.

Patch submitted as-is.  Added testing to our XML-only model through modification of the metadata files.  No specific test added.  Regressions will show up if deployment fails on test model.

Reviewed by: Tom Ware reviewed user submitted fix

Tested with JPA LRG
Comment 9 Guy Pelletier CLA 2011-10-04 08:12:37 EDT
*** Bug 331956 has been marked as a duplicate of this bug. ***
Comment 10 Eclipse Webmaster CLA 2022-06-09 10:36:23 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink