-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 posts ] 
Author Message
 Post subject: Foreign key constraint problem
PostPosted: Wed Oct 12, 2005 11:14 am 
Newbie

Joined: Wed Oct 12, 2005 10:56 am
Posts: 6
I'm getting the follwoing exception. Can somebody help me out with this.

org.hibernate.MappingException: Foreign key (FKDF4FDF95484A979C:APPLICATION_STATEMENT_ADDRESS [UNIQUE_PARTY_ADDRESS_ID])) must have same number of columns as the referenced primary key (PARTY_ADDRESS [PARTY_ID,ADDRESS_ID])
at org.hibernate.mapping.ForeignKey.alignColumns(ForeignKey.java:86)
at org.hibernate.mapping.ForeignKey.setReferencedTable(ForeignKey.java:51)
at org.hibernate.cfg.Configuration.secondPassCompileForeignKeys(Configuration.java:940)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:888)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1036)
at com.vsoftcorp.utils.hibernate.HibernateUtil.<clinit>(HibernateUtil.java:40)


The mappings looks like this:
<class name="com.vsoftcorp.coresoft.model.AccountApplStmtAddress" table="APPLICATION_STATEMENT_ADDRESS">

<id name="applStmtAddressId" type="int">
<column name="UNIQUE_APPL_STMT_ADDRESS_ID" sql-type="NUMBER" not-null="true"/>
</id>

<many-to-one name="address" class="com.vsoftcorp.coresoft.model.party.PartyAddress"
column="UNIQUE_PARTY_ADDRESS_ID"/>
</class>
--------------------------------------------------------------
<class name="com.vsoftcorp.coresoft.model.party.PartyAddress" table="PARTY_ADDRESS" >

<id name="partyAddressId" column="UNIQUE_PARTY_ADDRESS_ID">
<generator class="sequence" >
<param name="sequence">PARTY_ADDRESS_ID_SEQ</param>
</generator>
</id>

<property name="forUseOf" type="string">
<column name="ADDRESS_USE" sql-type="VARCHAR2"/>
</property>

<!--<many-to-one name="party" class="com.vsoftcorp.coresoft.model.party.hibernate.Party" column="PARTY_ID" insert="false" update="false" lazy="false"/>
<many-to-one name="address" class="com.vsoftcorp.coresoft.model.party.hibernate.NewAddress" column="ADDRESS_ID" insert="false" update="false" lazy="false"/>
-->
</class>
----------------------------------------------------------------

The PARTY_ADDRESS table has two columns called PARTY_ID and ADDRESS_ID but in the mapping i've commented those two still it is giving the above error.

Thanks,
nitin


Top
 Profile  
 
 Post subject: Re: Foreign key constraint problem
PostPosted: Wed Oct 12, 2005 2:22 pm 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
A many-to-one mapping assumes that your current object has a key to the One side.

You're trying to tell Hibernate to map the UNIQUE_PARTY_ADDRESS_ID column from APPLICATION_STATEMENT_ADDRESS to the 2 columns (PARTY_ID, ADDRESS_ID) on the PARTY_ADDRESS table. That won't work.

For a many-to-one mapping, the column= field name is must match the PK of the One table.

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 13, 2005 6:11 am 
Newbie

Joined: Wed Oct 12, 2005 10:56 am
Posts: 6
HI pksiv,

as you see in the mapping of "PartyAddress" the ID is defined as a single column. How come hibernate is picking up two columns as the primary key to the "One" table.

nitin


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 13, 2005 6:13 am 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
nitinsjainid wrote:
HI pksiv,

as you see in the mapping of "PartyAddress" the ID is defined as a single column. How come hibernate is picking up two columns as the primary key to the "One" table.

nitin


Hibernate is telling you what the Database is telling it.

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 13, 2005 10:13 am 
Newbie

Joined: Wed Oct 12, 2005 10:56 am
Posts: 6
But this happens during the build session factory routine even if my database is turned off. Also, i have checked by database constraints and they are fine.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 13, 2005 10:22 am 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
The build is trying to confirm that all the associations are correct and it is determining that they are not.

Sorry that I can't be more help without seeing more information but trust me, Hibernate isn't deciding that the PK of the PARTY_ADDRESS table is those 2 columns on it's own. It's getting the information from somewhere.

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 13, 2005 10:30 am 
Newbie

Joined: Wed Oct 12, 2005 10:56 am
Posts: 6
Here are the create scripts for the tables. Any idea where else should i be looking?


Script for PARTY_ADDRESS
-------------------------------

CREATE TABLE PARTY_ADDRESS (
PARTY_ID NVARCHAR2(60) NULL,
ADDRESS_USE NVARCHAR2(60) NULL,
ADDRESS_ID NVARCHAR2(60) NULL,
UNIQUE_PARTY_ADDRESS_ID NUMBER(20,0) NOT NULL,
PRIMARY KEY(UNIQUE_PARTY_ADDRESS_ID)
)
GO
ALTER TABLE PARTY_ADDRESS
ADD ( CONSTRAINT PARTYADDR_PARTYID_FK
FOREIGN KEY(PARTY_ID)
REFERENCES CORESOFT.PARTY(PARTY_ID) )
GO
ALTER TABLE PARTY_ADDRESS
ADD ( CONSTRAINT PARTYADDR_ADDRID_FK
FOREIGN KEY(ADDRESS_ID)
REFERENCES CORESOFT.ADDRESS(ADDRESS_ID) )
GO

Script for APPLICATION_STATEMENT_ADDRESS
-------------------------------------------------------

CREATE TABLE APPLICATION_STATEMENT_ADDRESS (
UNIQUE_APPL_STMT_ADDRESS_ID NUMBER(20,0) NOT NULL,
STATEMENT_ID NUMBER(20,0) NULL,
UNIQUE_PARTY_ADDRESS_ID NUMBER(20,0) NULL,
PRIMARY KEY(UNIQUE_APPL_STMT_ADDRESS_ID)
)
GO
ALTER TABLE APPLICATION_STATEMENT_ADDRESS
ADD ( CONSTRAINT STATE_APP_PARTY_ADD_ID
UNIQUE (STATEMENT_ID, UNIQUE_PARTY_ADDRESS_ID) )
GO
ALTER TABLE APPLICATION_STATEMENT_ADDRESS
ADD ( CONSTRAINT UPARTY_ADD_ID_FK
FOREIGN KEY(UNIQUE_PARTY_ADDRESS_ID)
REFERENCES PARTY_ADDRESS(UNIQUE_PARTY_ADDRESS_ID) )
GO
ALTER TABLE APPLICATION_STATEMENT_ADDRESS
ADD ( CONSTRAINT USTATE_ADD_ID_FK
FOREIGN KEY(STATEMENT_ID)
REFERENCES APPLICATION_STATEMENT(STATEMENT_ID) )
GO


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 13, 2005 10:41 am 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
Can you show the complete StackTrace ?

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 13, 2005 10:42 am 
Newbie

Joined: Wed Oct 12, 2005 10:56 am
Posts: 6
Here is the complete stack trace:

20:12:49,971 DEBUG Configuration:928 - resolving reference to class: com.vsoftcorp.coresoft.model.party.PartyAddress
20:12:49,981 ERROR HibernateUtil:43 - Initial SessionFactory creation failed.
org.hibernate.MappingException: Foreign key (FKDF4FDF95484A979C:APPLICATION_STATEMENT_ADDRESS [UNIQUE_PARTY_ADDRESS_ID])) must have same number of columns as the referenced primary key (PARTY_ADDRESS [PARTY_ID,ADDRESS_ID])
at org.hibernate.mapping.ForeignKey.alignColumns(ForeignKey.java:86)
at org.hibernate.mapping.ForeignKey.setReferencedTable(ForeignKey.java:51)
at org.hibernate.cfg.Configuration.secondPassCompileForeignKeys(Configuration.java:940)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:888)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1036)
at com.vsoftcorp.utils.hibernate.HibernateUtil.<clinit>(HibernateUtil.java:40)
java.lang.ExceptionInInitializerError
at com.vsoftcorp.utils.hibernate.HibernateUtil.<clinit>(HibernateUtil.java:44)
Caused by: org.hibernate.MappingException: Foreign key (FKDF4FDF95484A979C:APPLICATION_STATEMENT_ADDRESS [UNIQUE_PARTY_ADDRESS_ID])) must have same number of columns as the referenced primary key (PARTY_ADDRESS [PARTY_ID,ADDRESS_ID])
at org.hibernate.mapping.ForeignKey.alignColumns(ForeignKey.java:86)
at org.hibernate.mapping.ForeignKey.setReferencedTable(ForeignKey.java:51)
at org.hibernate.cfg.Configuration.secondPassCompileForeignKeys(Configuration.java:940)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:888)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1036)
at com.vsoftcorp.utils.hibernate.HibernateUtil.<clinit>(HibernateUtil.java:40)
Exception in thread "main"


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.