Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 341297 - NullpointerException occurs on DatabaseObjectDefinition.getFullName(...) when specifying the @Index annotation in an Entity class
Summary: NullpointerException occurs on DatabaseObjectDefinition.getFullName(...) when...
Status: NEW
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 7
: P3 major (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-03-29 20:06 EDT by Aaron Dockter CLA
Modified: 2022-06-09 10:34 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Aaron Dockter CLA 2011-03-29 20:06:25 EDT
Build Identifier: eclipselink-plugins-2.2.0.v20110202-r8913

Found a bug in the EntityAccessor.java class where one of the conditional statement that sets the qualifier for an Index is checking for null against "getDescriptor().getDefaultSchema()", but setting the qualifier to "getDescriptor().getDefaultSchema()", which had already been determined as null.

This is preventing indexes from being created properly while interpreting the metadata.  As a result a simple composite index on an Entity cannot be created.

For Example:

@Entity
@Indexes({
	@Index(name="IDX_COG_POR_ATYPE", columnNames={"CALLOUTGUID","PRIORITYORDER","ACTIONTYPE"}, unique=true),
	@Index(name="IDX_COGUID", columnNames={"CALLOUTGUID","PRIORITYORDER","ACTIONTYPE"}, unique=true)})
public class Task  implements Serializable
{
	/**
	 * Default id 
	 */
	private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @Column(name="BUSINESSSERVICEID", nullable=false)
    private Long businessServiceId;
    
    @Index
    @Column(name="CALLOUTGUID", nullable=false)
    private Long calloutGUID;
    
    @Index
    @Column(name="PRIORITYORDER", nullable=false)
    private Integer priorityOrder;

    @Index
    @Column(name="ACTIONTYPE", length=100, nullable=false)
    private String actionType;
...
}

As the tables are being created, you will experience the following error:

Query: DataModifyQuery(sql="DROP TABLE NOVELL.TASK")
[EL Severe]: 2011-03-29 16:18:11.114--ServerSession(505066727)--Thread(Thread[Karaf Shell Console Thread,5,main])--java.lang.NullP
ointerException
        at org.eclipse.persistence.tools.schemaframework.DatabaseObjectDefinition.getFullName(DatabaseObjectDefinition.java:111)
        at org.eclipse.persistence.tools.schemaframework.IndexDefinition.buildCreationWriter(IndexDefinition.java:71)
        at org.eclipse.persistence.tools.schemaframework.DatabaseObjectDefinition.createOnDatabase(DatabaseObjectDefinition.java:8
1)
        at org.eclipse.persistence.tools.schemaframework.TableDefinition.createIndexes(TableDefinition.java:802)
        at org.eclipse.persistence.tools.schemaframework.TableDefinition.postCreateObject(TableDefinition.java:1042)
        at org.eclipse.persistence.tools.schemaframework.SchemaManager.createObject(SchemaManager.java:196)
        at org.eclipse.persistence.tools.schemaframework.SchemaManager.replaceObject(SchemaManager.java:892)
        at org.eclipse.persistence.tools.schemaframework.TableCreator.replaceTablesAndConstraints(TableCreator.java:297)
        at org.eclipse.persistence.tools.schemaframework.TableCreator.replaceTables(TableCreator.java:260)
        at org.eclipse.persistence.tools.schemaframework.SchemaManager.replaceDefaultTables(SchemaManager.java:954)
        at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.createOrReplaceDefaultTables(EntityManagerFactoryProv
ider.java:90)
        at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.writeDDLToDatabase(EntityManagerFactoryProvider.java:
357)
        at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.generateDDL(EntityManagerFactoryProvider.java:127)
        at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:399)
        at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getServerSession(EntityManagerFactoryImpl.java:185)
        at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:242
)
        at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:230)



RESOLUTION:

In EntityAccessor.java the "processIndexes()" method, change 

else if ((getDescriptor().getDefaultSchema() != null) &&              (getDescriptor().getDefaultSchema().length() != 0)) {
                indexDefinition.setQualifier(indexMetadata.getSchema());                
}


to 

else if ((getDescriptor().getDefaultSchema() != null) &&              (getDescriptor().getDefaultSchema().length() != 0)) {
                indexDefinition.setQualifier(getDescriptor().getDefaultSchema());                
}

~line 936 in EntityAccessor.java

I might also suggest changing the DatabasesObjectDefinition.java "getFullName()" method to handle a null qualifier:

 public String getFullName() {
        if (getQualifier() == null 
        		|| (getQualifier() != null && getQualifier().equals(""))) {
            return getName();
        } else {
            return getQualifier() + "." + getName();
        }
    }

~line 110 in DatabaseObjectDefinition.java



Reproducible: Always

Steps to Reproduce:
1. Create an entity class with some composite index as per:
http://wiki.eclipse.org/EclipseLink/Examples/JPA/Indexes
2. Create an osgi bundle and start the module
3. Kick off the table creation and see the NullPointerException in DatabaseObjectDefinition.getFullName()
Comment 1 Aaron Dockter CLA 2011-03-29 20:09:53 EDT
Apologies... the first line in my bug description should read:

Found a bug in the EntityAccessor.java class where one of the conditional
statements, that sets the qualifier for an Index, is checking for null against
"getDescriptor().getDefaultSchema()", but setting the qualifier to the value of
"indexMetadata.getSchema()", which had already been determined as
null.

Thanks so much!
Comment 2 Aaron Dockter CLA 2011-03-30 03:12:43 EDT
Note:  I downloaded the latest source code for 2.2.1 (eclipselink-src-2.2.1.v20110325-r9169) and still see the problem.
Comment 3 Tom Ware CLA 2011-04-06 08:32:45 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 4 Eclipse Webmaster CLA 2022-06-09 10:14:19 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink
Comment 5 Eclipse Webmaster CLA 2022-06-09 10:34:31 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink