-->
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.  [ 3 posts ] 
Author Message
 Post subject: property-ref ????????????
PostPosted: Sat Feb 04, 2006 3:04 am 
Regular
Regular

Joined: Tue Dec 14, 2004 5:21 am
Posts: 104
Location: india
My class structure is

person 1----------* address

person has hibernate generated id (ID) as well as a seperate person id(PID) which is unique . i want the persion id (PID) to be included in my address table(not the hibernate generated id which is the primary key of person table) as foreign key (using property-ref attribute) .

but i get error when i give the mapping below .

i'm confused about the kind of DDL hibernate when using property reference


Hibernate version: 3.1.1

Mapping documents:

IN PERSON

<set name="addresses" inverse="true" cascade="all-delete-orphan">
<key column="PID" />
<one-to-many class="test.Address />
</set>

IN ADDRESS

<many-to-one name="person" class="test.Person"
column="PID" property-ref="pid">
</many-to-one>

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

12:23:11,251 ERROR JDBCExceptionReporter:72 - ERROR: insert or update on table "address" violates foreign key constraint "fke367797d1a01a944"
Detail: Key (pid)=(1139035990967) is not present in table "person". ()
12:23:11,253 ERROR AbstractFlushingEventListener:299 - Could not synchronize database state with session ()
org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:69)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:202)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:230)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:296)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1007)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:354)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at org.fincore.persistence.HibernateUtil.commitTransaction(HibernateUtil.java:213)
at test.Test.main(Test.java:52)
Caused by: java.sql.BatchUpdateException: Batch entry 1 <unknown> was aborted. Call getNextException to see the cause.
at org.postgresql.jdbc2.AbstractJdbc2Statement$BatchResultHandler.handleError(AbstractJdbc2Statement.java:2478)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1298)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:347)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeBatch(AbstractJdbc2Statement.java:2540)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:58)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:195)
... 9 more
12:23:11,259 DEBUG HibernateUtil:232 - Tyring to rollback database transaction of this thread. ()
12:23:11,260 DEBUG JDBCTransaction:152 - rollback ()
12:23:11,262 DEBUG JDBCTransaction:163 - rolled back JDBC Connection ()
12:23:11,263 DEBUG HibernateUtil:181 - Closing Session of this thread. ()
Exception in thread "main" org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
at test.HibernateUtil.commitTransaction(HibernateUtil.java:218)
at test.Test.main(Test.java:52)
Caused by: org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:69)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:202)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:230)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:296)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1007)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:354)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at test .HibernateUtil.commitTransaction(HibernateUtil.java:213)
... 1 more
Caused by: java.sql.BatchUpdateException: Batch entry 1 <unknown> was aborted. Call getNextException to see the cause.
at org.postgresql.jdbc2.AbstractJdbc2Statement$BatchResultHandler.handleError(AbstractJdbc2Statement.java:2478)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1298)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:347)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeBatch(AbstractJdbc2Statement.java:2540)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:58)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:195)
... 9 more

Name and version of the database you are using:
postgreSQL 7.4

_________________
sHeRiN
thanks for your ratings ...... :)


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 04, 2006 5:00 am 
Senior
Senior

Joined: Tue Aug 23, 2005 8:52 am
Posts: 181
You need to modify your set also to indicate that the foreign key of the joined table maps to a key other than th eprimary key.
Code:
<set name="addresses" inverse="true" cascade="all-delete-orphan">
<key column="PID"  property-ref="pid"/>
<one-to-many class="test.Address />
</set>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 06, 2006 4:07 am 
Regular
Regular

Joined: Tue Dec 14, 2004 5:21 am
Posts: 104
Location: india
rajasaur wrote:
You need to modify your set also to indicate that the foreign key of the joined table maps to a key other than th eprimary key.
Code:
<set name="addresses" inverse="true" cascade="all-delete-orphan">
<key column="PID"  property-ref="pid"/>
<one-to-many class="test.Address />
</set>


but the mapping is throwing a NullPointerException at EntityEntry's getLoadedvalue() method


.....
....


Caused by: org.hibernate.TransactionException: JTA commit failed:
at org.hibernate.transaction.JTATransaction.commit(JTATransaction.java:153)
at test.HibernateUtil.commitTransaction(HibernateUtil.java:213)
... 33 more
Caused by: org.jboss.tm.JBossRollbackException: Unable to commit, tx=TransactionImpl:XidImpl[FormatId=257, GlobalId=sherin/16, BranchQual=, localId=16] status=STATUS_NO_TRANSACTION; - nested throwable: (java.lang.NullPointerException)
at org.jboss.tm.TransactionImpl.commit(TransactionImpl.java:354)
at org.jboss.tm.TxManager.commit(TxManager.java:224)
at org.jboss.tm.usertx.client.ServerVMClientUserTransaction.commit(ServerVMClientUserTransaction.java:126)
at org.hibernate.transaction.JTATransaction.commit(JTATransaction.java:146)
... 34 more
Caused by: java.lang.NullPointerException
at org.hibernate.engine.EntityEntry.getLoadedValue(EntityEntry.java:177)
at org.hibernate.type.CollectionType.getKeyOfOwner(CollectionType.java:304)
at org.hibernate.engine.Collections.processReachableCollection(Collections.java:156)
at org.hibernate.event.def.FlushVisitor.processCollection(FlushVisitor.java:37)
at org.hibernate.event.def.AbstractVisitor.processValue(AbstractVisitor.java:101)
at org.hibernate.event.def.AbstractVisitor.processValue(AbstractVisitor.java:61)
at org.hibernate.event.def.AbstractVisitor.processEntityPropertyValues(AbstractVisitor.java:55)
at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:115)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:195)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:76)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:905)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:345)
at org.hibernate.transaction.CacheSynchronization.beforeCompletion(CacheSynchronization.java:59)
at org.jboss.tm.TransactionImpl.doBeforeCompletion(TransactionImpl.java:1473)
at org.jboss.tm.TransactionImpl.beforePrepare(TransactionImpl.java:1092)
at org.jboss.tm.TransactionImpl.commit(TransactionImpl.java:306)
... 37 more


i found a bug report similar to this at
http://opensource2.atlassian.com/projects/hibernate/browse/HB-1526

i am using hibernate 3.1.2 and according to the bug report , the error is to be solved in verson 3.1

if anyone got this problem solved , please reply

_________________
sHeRiN
thanks for your ratings ...... :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.