ArrayIndexOutOfBoundsException:0 at org.apache.openjpa.jdbc.sql.DBDictionary.getForeignKeyConstraintSQL(DBDictionary.java:3373)

10 Messages Forum Options Options
Embed this topic
Permalink
Gopalakrishnan U
ArrayIndexOutOfBoundsException:0 at org.apache.openjpa.jdbc.sql.DBDictionary.getForeignKeyConstraintSQL(DBDictionary.java:3373)
Reply Threaded MoreMore options
Print post
Permalink
Has anybody here seen the trace show below before? I am getting this when creating an EntityManager. I am trying to implement a slightly complex entity map with many composite identity relations. I am not yet sure what exactly is creating this problem so that I can write a test case reproducing the problem.

<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)

Any clues?

Thanks
Gopal
Gopalakrishnan U
Re: ArrayIndexOutOfBoundsException:0 at org.apache.openjpa.jdbc.sql.DBDictionary.getForeignKeyConstraintSQL(DBDictionary.java:3373)
Reply Threaded MoreMore options
Print post
Permalink
Gopalakrishnan U wrote:
>  I am not yet sure what exactly is creating this problem so that I can write a test case reproducing
> the problem.
Looks the @ForeignKey is causing the trouble. When I removed the
ForeignKey annotations the problem goes away. But I would like to keep
the @ForeignKey
as I am mapping to an existing table with foreign key definitions. Any
ideas?


catalina wei-2
Re: ArrayIndexOutOfBoundsException:0 at org.apache.openjpa.jdbc.sql.DBDictionary.getForeignKeyConstraintSQL(DBDictionary.java:3373)
Reply Threaded MoreMore options
Print post
Permalink
Gopal,
Could you post your entity source or test case that reproduces the problem ?
Also post  your existing table's DDL that contains the foreign key
definition.

Catalina Wei

On Mon, Aug 4, 2008 at 4:17 AM, Gopalakrishnan U
<gopalakrishnanu@...>wrote:

> Gopalakrishnan U wrote:
>
>>  I am not yet sure what exactly is creating this problem so that I can
>> write a test case reproducing
>> the problem.
>>
> Looks the @ForeignKey is causing the trouble. When I removed the ForeignKey
> annotations the problem goes away. But I would like to keep the @ForeignKey
> as I am mapping to an existing table with foreign key definitions. Any
> ideas?
>
>
>
Gopalakrishnan U
Re: ArrayIndexOutOfBoundsException:0 at org.apache.openjpa.jdbc.sql.DBDictionary.getForeignKeyConstraintSQL(DBDictionary.java:3373)
Reply Threaded MoreMore options
Print post
Permalink

>Could you post your entity source or test case that reproduces the problem ?
>Also post  your existing table's DDL that contains the foreign key
>definition.

Catalina,

Here is the test case that reproduces the problem: identifying_rel_test.zip. The ERD I am trying to implement and the corresponding ddl are also in the zip (ERD.jpeg and erd.sql).

The zip is an eclipse project export, do mvn install to run the test and reproduce the error.

Let me know if you have any questions.

Thanks
Gopal
Gopalakrishnan U
Re: ArrayIndexOutOfBoundsException:0 at org.apache.openjpa.jdbc.sql.DBDictionary.getForeignKeyConstraintSQL(DBDictionary.java:3373)
Reply Threaded MoreMore options
Print post
Permalink
Found some thing interesting (or weired?) today.

When I do the following renaming the problem is gone!

rename class C to class WC
rename class CM to WCM

i.e make those class names alphabetically higher than the classnames VC and VCS and update the persistance.xml with the new class names. (Changing the order of classes in the persistance.xml or changing the order of the fields in E etc didn't help). Any clues?


Fay Wang
Re: ArrayIndexOutOfBoundsException:0 at org.apache.openjpa.jdbc.sql.DBDictionary.getForeignKeyConstraintSQL(DBDictionary.java:3373)
Reply Threaded MoreMore options
Print post
Permalink
Hi,

Yes, the problem is that 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 go 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, it is also a relation field, the foreign key is constructed in this stage. 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 your experiment shows by manipulating the 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.

The possible fix is to delay the construction of the foreign key after the primary keys of all the entities get resolved. I think this is an openjpa bug. You can file a JIRA for it.      

-fay

--- On Thu, 8/7/08, Gopalakrishnan U <gopalakrishnanu@...> wrote:

> From: Gopalakrishnan U <gopalakrishnanu@...>
> Subject: Re: ArrayIndexOutOfBoundsException:0 at org.apache.openjpa.jdbc.sql.DBDictionary.getForeignKeyConstraintSQL(DBDictionary.java:3373)
> To: users@...
> Date: Thursday, August 7, 2008, 4:24 AM
> Found some thing interesting (or weired?) today.
>
> When I do the following renaming the problem is gone!
>
> rename class C to class WC
> rename class CM to WCM
>
> i.e make those class names alphabetically higher than the
> classnames VC and
> VCS and update the persistance.xml with the new class
> names. (Changing the
> order of classes in the persistance.xml or changing the
> order of the fields
> in E etc didn't help). Any clues?
>
>
>
> --
> View this message in context:
> http://n2.nabble.com/ArrayIndexOutOfBoundsException%3A0-at-org.apache.openjpa.jdbc.sql.DBDictionary.getForeignKeyConstraintSQL%28DBDictionary.java%3A3373%29-tp668199p678410.html
> Sent from the OpenJPA Users mailing list archive at
> Nabble.com.


     
Gopalakrishnan U
Re: ArrayIndexOutOfBoundsException:0 at org.apache.openjpa.jdbc.sql.DBDictionary.getForeignKeyConstraintSQL(DBDictionary.java:3373)
Reply Threaded MoreMore options
Print post
Permalink

The SQL generated for creating OPENJPASAMPLE.D table is wrong. Here is the SQL generated for creating the D table CREATE TABLE OPENJPASAMPLE.D (id INTEGER NOT NULL, C_CID INTEGER, C_CM_CMID INTEGER, C_CM_E_EID INTEGER, PRIMARY KEY (id)). It is missing fields from VC --< D relation and corresponding PKs
I think this is causing the problem when it is trying to generate the SQL for creating FK for the OPENJPASAMPLE.D table.

Opened a JIRA for this issue https://issues.apache.org/jira/browse/OPENJPA-682.

Gopal
Fay Wang
Re: ArrayIndexOutOfBoundsException:0 at org.apache.openjpa.jdbc.sql.DBDictionary.getForeignKeyConstraintSQL(DBDictionary.java:3373)
Reply Threaded MoreMore options
Print post
Permalink
Yes, you are right. This problem is caused by a relation field being annotated as a primary key and foreign key. You might want to apply the patch I put in JIRA-679. Before the patch:

CREATE TABLE D (id VARCHAR(254) NOT NULL, a VARCHAR(254), C_CID VARCHAR(254), C_CM_CMID VARCHAR(254), C_CM_E_EID VARCHAR(254), PRIMARY KEY (id))

After the patch:
CREATE TABLE D (id VARCHAR(254) NOT NULL, a VARCHAR(254), C_CID VARCHAR(254), C_CM_CMID VARCHAR(254), C_CM_E_EID VARCHAR(254), VC_VCID VARCHAR(254) NOT NULL, VC_VCS_E_EID VARCHAR(254) NOT NULL, VC_VCS_VCSID VARCHAR(254) NOT NULL, PRIMARY KEY (id, VC_VCID, VC_VCS_E_EID, VC_VCS_VCSID))



--- On Fri, 8/8/08, Gopalakrishnan U <gopalakrishnanu@...> wrote:

> From: Gopalakrishnan U <gopalakrishnanu@...>
> Subject: Re: ArrayIndexOutOfBoundsException:0 at org.apache.openjpa.jdbc.sql.DBDictionary.getForeignKeyConstraintSQL(DBDictionary.java:3373)
> To: users@...
> Date: Friday, August 8, 2008, 2:01 AM
> The SQL generated for creating OPENJPASAMPLE.D table is
> wrong. Here is the
> SQL generated for creating the D table CREATE TABLE
> OPENJPASAMPLE.D (id
> INTEGER NOT NULL, C_CID INTEGER, C_CM_CMID INTEGER,
> C_CM_E_EID INTEGER,
> PRIMARY KEY (id)). It is missing fields from VC --< D
> relation and
> corresponding PKs
> I think this is causing the problem when it is trying to
> generate the SQL
> for creating FK for the OPENJPASAMPLE.D table.
>
> Opened a JIRA for this issue
> https://issues.apache.org/jira/browse/OPENJPA-682.
>
> Gopal
> --
> View this message in context:
> http://n2.nabble.com/ArrayIndexOutOfBoundsException%3A0-at-org.apache.openjpa.jdbc.sql.DBDictionary.getForeignKeyConstraintSQL%28DBDictionary.java%3A3373%29-tp668199p680224.html
> Sent from the OpenJPA Users mailing list archive at
> Nabble.com.


     
Gopalakrishnan U
Re: ArrayIndexOutOfBoundsException:0 at org.apache.openjpa.jdbc.sql.DBDictionary.getForeignKeyConstraintSQL(DBDictionary.java:3373)
Reply Threaded MoreMore options
Print post
Permalink
Hi Fay,

Thanks for the patch, that should work! But I am not able to try the patch as the ClassMapping.java in openjpa svn has already moved to a newer version. Any suggestion on how could I build/try the patch?

Thanks
Gopal



Fay Wang wrote:
Yes, you are right. This problem is caused by a relation field being annotated as a primary key and foreign key. You might want to apply the patch I put in JIRA-679. Before the patch:

CREATE TABLE D (id VARCHAR(254) NOT NULL, a VARCHAR(254), C_CID VARCHAR(254), C_CM_CMID VARCHAR(254), C_CM_E_EID VARCHAR(254), PRIMARY KEY (id))

After the patch:
CREATE TABLE D (id VARCHAR(254) NOT NULL, a VARCHAR(254), C_CID VARCHAR(254), C_CM_CMID VARCHAR(254), C_CM_E_EID VARCHAR(254), VC_VCID VARCHAR(254) NOT NULL, VC_VCS_E_EID VARCHAR(254) NOT NULL, VC_VCS_VCSID VARCHAR(254) NOT NULL, PRIMARY KEY (id, VC_VCID, VC_VCS_E_EID, VC_VCS_VCSID))



--- On Fri, 8/8/08, Gopalakrishnan U <gopalakrishnanu@gmail.com> wrote:

> From: Gopalakrishnan U <gopalakrishnanu@gmail.com>
> Subject: Re: ArrayIndexOutOfBoundsException:0 at org.apache.openjpa.jdbc.sql.DBDictionary.getForeignKeyConstraintSQL(DBDictionary.java:3373)
> To: users@openjpa.apache.org
> Date: Friday, August 8, 2008, 2:01 AM
> The SQL generated for creating OPENJPASAMPLE.D table is
> wrong. Here is the
> SQL generated for creating the D table CREATE TABLE
> OPENJPASAMPLE.D (id
> INTEGER NOT NULL, C_CID INTEGER, C_CM_CMID INTEGER,
> C_CM_E_EID INTEGER,
> PRIMARY KEY (id)). It is missing fields from VC --< D
> relation and
> corresponding PKs
> I think this is causing the problem when it is trying to
> generate the SQL
> for creating FK for the OPENJPASAMPLE.D table.
>
> Opened a JIRA for this issue
> https://issues.apache.org/jira/browse/OPENJPA-682.
>
> Gopal
> --
> View this message in context:
> http://n2.nabble.com/ArrayIndexOutOfBoundsException%3A0-at-org.apache.openjpa.jdbc.sql.DBDictionary.getForeignKeyConstraintSQL%28DBDictionary.java%3A3373%29-tp668199p680224.html
> Sent from the OpenJPA Users mailing list archive at
> Nabble.com.


     
Fay Wang
Re: ArrayIndexOutOfBoundsException:0 at org.apache.openjpa.jdbc.sql.DBDictionary.getForeignKeyConstraintSQL(DBDictionary.java:3373)
Reply Threaded MoreMore options
Print post
Permalink
Hi Gopal,
   The fix has been committed to openjpa. You can just retrieve ClassMapping.java from svn. Let me know if you have further questions. Thanks!

-fay


--- On Mon, 8/11/08, Gopalakrishnan U <gopalakrishnanu@...> wrote:

> From: Gopalakrishnan U <gopalakrishnanu@...>
> Subject: Re: ArrayIndexOutOfBoundsException:0 at org.apache.openjpa.jdbc.sql.DBDictionary.getForeignKeyConstraintSQL(DBDictionary.java:3373)
> To: users@...
> Date: Monday, August 11, 2008, 8:24 PM
> Hi Fay,
>
> Thanks for the patch, that should work! But I am not able
> to try the patch
> as the ClassMapping.java in openjpa svn has already moved
> to a newer
> version. Any suggestion on how could I build/try the patch?
>
> Thanks
> Gopal
>
>
>
>
> Fay Wang wrote:
> >
> > Yes, you are right. This problem is caused by a
> relation field being
> > annotated as a primary key and foreign key. You might
> want to apply the
> > patch I put in JIRA-679. Before the patch:
> >
> > CREATE TABLE D (id VARCHAR(254) NOT NULL, a
> VARCHAR(254), C_CID
> > VARCHAR(254), C_CM_CMID VARCHAR(254), C_CM_E_EID
> VARCHAR(254), PRIMARY KEY
> > (id))
> >
> > After the patch:
> > CREATE TABLE D (id VARCHAR(254) NOT NULL, a
> VARCHAR(254), C_CID
> > VARCHAR(254), C_CM_CMID VARCHAR(254), C_CM_E_EID
> VARCHAR(254), VC_VCID
> > VARCHAR(254) NOT NULL, VC_VCS_E_EID VARCHAR(254) NOT
> NULL, VC_VCS_VCSID
> > VARCHAR(254) NOT NULL, PRIMARY KEY (id, VC_VCID,
> VC_VCS_E_EID,
> > VC_VCS_VCSID))
> >
> >
> >
> > --- On Fri, 8/8/08, Gopalakrishnan U
> <gopalakrishnanu@...> wrote:
> >
> >> From: Gopalakrishnan U
> <gopalakrishnanu@...>
> >> Subject: Re: ArrayIndexOutOfBoundsException:0 at
> >>
> org.apache.openjpa.jdbc.sql.DBDictionary.getForeignKeyConstraintSQL(DBDictionary.java:3373)
> >> To: users@...
> >> Date: Friday, August 8, 2008, 2:01 AM
> >> The SQL generated for creating OPENJPASAMPLE.D
> table is
> >> wrong. Here is the
> >> SQL generated for creating the D table CREATE
> TABLE
> >> OPENJPASAMPLE.D (id
> >> INTEGER NOT NULL, C_CID INTEGER, C_CM_CMID
> INTEGER,
> >> C_CM_E_EID INTEGER,
> >> PRIMARY KEY (id)). It is missing fields from VC
> --< D
> >> relation and
> >> corresponding PKs
> >> I think this is causing the problem when it is
> trying to
> >> generate the SQL
> >> for creating FK for the OPENJPASAMPLE.D table.
> >>
> >> Opened a JIRA for this issue
> >> https://issues.apache.org/jira/browse/OPENJPA-682.
> >>
> >> Gopal
> >> --
> >> View this message in context:
> >>
> http://n2.nabble.com/ArrayIndexOutOfBoundsException%3A0-at-org.apache.openjpa.jdbc.sql.DBDictionary.getForeignKeyConstraintSQL%28DBDictionary.java%3A3373%29-tp668199p680224.html
> >> Sent from the OpenJPA Users mailing list archive
> at
> >> Nabble.com.
> >
> >
> >      
> >
> >
>
> --
> View this message in context:
> http://n2.nabble.com/ArrayIndexOutOfBoundsException%3A0-at-org.apache.openjpa.jdbc.sql.DBDictionary.getForeignKeyConstraintSQL%28DBDictionary.java%3A3373%29-tp668199p687273.html
> Sent from the OpenJPA Users mailing list archive at
> Nabble.com.