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

Fay Wang commented on OPENJPA-679:
----------------------------------

This problem is found by Gopalakrishnan U. A JIRA is open on behalf on him. 
This problem may happen when a relation field is annotated as both a primary 
key and a foreign key. When Openjpa resolves the class matedata, it first 
resolves the primary keys of all the entities in the persistent unit. After the 
primary keys of all the entities are resolved, it then goes ahead to resolve 
the non-relation field. It is normally in the stage of resolving non-relation 
fields that the foreign key is constructed.

Since  a relation field is a primary key, it gets resolved in the first stage. 
However, since it is also a relation field, the foreign key construction is 
triggered when setting the strategy  to this field. If the primary key 
information of the parent entity is not yet available, some of the foreign key 
fields will be missing. If it happens that the primary key information of the 
parent entity is already resolved (just as some experiment shows by 
manipulating the entity class name so that the primary key of the parent entity 
gets resolved first before the child entity), then the foreign key constructed 
in this stage will be good and complete.



> java.lang.ArrayIndexOutOfBoundsException may occur when a relation field is 
> annotated as a primary key and a foreign key
> ------------------------------------------------------------------------------------------------------------------------
>
>                 Key: OPENJPA-679
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-679
>             Project: OpenJPA
>          Issue Type: Bug
>            Reporter: Fay Wang
>
> <openjpa-1.2.0-SNAPSHOT-rexported nonfatal general error>
> org.apache.openjpa.persistence.PersistenceException: 0
>     at
> org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:196)
>     at
> org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker(DelegatingBrokerFactory.java:142)
>     at
> org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:192)
>     at
> org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:145)
> ....
> Caused by: java.lang.ArrayIndexOutOfBoundsException: 0
>     at
> org.apache.openjpa.jdbc.sql.DBDictionary.getForeignKeyConstraintSQL(DBDictionary.java:3373)
>     at
> org.apache.openjpa.jdbc.sql.DBDictionary.getAddForeignKeySQL(DBDictionary.java:3252)
>     at
> org.apache.openjpa.jdbc.schema.SchemaTool.addForeignKey(SchemaTool.java:1066)
>     at org.apache.openjpa.jdbc.schema.SchemaTool.add(SchemaTool.java:604)
>     at org.apache.openjpa.jdbc.schema.SchemaTool.add(SchemaTool.java:344)
>     at org.apache.openjpa.jdbc.schema.SchemaTool.run(SchemaTool.java:321)
>     at org.apache.openjpa.jdbc.meta.MappingTool.record(MappingTool.java:501)
>     at org.apache.openjpa.jdbc.meta.MappingTool.record(MappingTool.java:453)
>     at
> org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory.synchronizeMappings(JDBCBrokerFactory.java:159)
>     at
> org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory.newBrokerImpl(JDBCBrokerFactory.java:119)
>     at
> org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:189)

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to