gavin wrote:
Please submit code to reproduce this (as a very simple easy to run main() method) to JIRA.
Ok.
gavin wrote:
What happens if you use this query instead:
Code:
select partyRelationship from Party party
join party.relatedPartiesFrom partyRelationship
where party.partyId = ?
and partyRelationship.relatedParty = ?
and partyRelationship.relationshipType = ?
Same thing (?!):
could not resolve property: id of: it.esselunga.ecommerce.data.model.PartyRelationship [select partyRelationship from it.esselunga.ecommerce.data.model.Party party join party.relatedPartiesFrom partyRelationship where party.partyId = ? and partyRelationship.relatedParty = ? and partyRelationship.relationshipType = ? ]
gavin wrote:
Actually, what happens with just
this query:
Code:
select partyRelationship from Party party
join party.relatedPartiesFrom partyRelationship
Same thing again (!!!):
could not resolve property: id of: it.esselunga.ecommerce.data.model.PartyRelationship [select partyRelationship from it.esselunga.ecommerce.data.model.Party party join party.relatedPartiesFrom partyRelationship ]
gavin wrote:
Lastly, are you calling the query with find(), or iterate()?
I a Query.uniqueResult.
The exact code is:
1) calling the method from a junit test
Code:
assertTrue( partyService.isRelatedTo( partyContainer.customer, partyContainer.person[ 0 ],
partyContainer.partyRelationshipType[ 0 ] ) );
2) the method is implemented by a Spring bean with transactions and session managed by TransactionInterceptor
Code:
public boolean isRelatedTo( Person partyRelatedFrom, Person partyRelatedTo, PartyRelationshipType relType ) {
PartyRelationship retrieved =
( PartyRelationship )DataAccessUtils.uniqueResult( "select partyRelationship " +
"from Party party " +
"join party.relatedPartiesFrom partyRelationship " +
"where party.partyId = ? " +
"and partyRelationship.relatedParty = ? " +
"and partyRelationship.relationshipType = ? ",
new Object[] { partyRelatedFrom, partyRelatedTo,
relType },
new Type[] { Hibernate.OBJECT, Hibernate.OBJECT,
Hibernate.OBJECT},
sessionFactory );
return retrieved != null;
}
Finally, the DataAccessUtils.uniqueResult is a helper method whose code is:
Code:
public static Object uniqueResult( String queryString, Object[] paramValues, Type[] paramTypes,
SessionFactory sessionFactory ) {
Session session = SessionFactoryUtils.getSession( sessionFactory, false );
try {
// @todo check this is loaded from a cache
Query query = session.createQuery( queryString );
for ( int i = 0 ; i < paramValues.length ; i++ ) {
Object paramValue = paramValues[ i ];
Type paramType = paramTypes[ i ];
query.setParameter( i, paramValue, paramType );
}
Object object = query.uniqueResult();
return object;
}
catch ( HibernateException e ) {
throw SessionFactoryUtils.convertHibernateAccessException( e );
}
}
Thanks, now I'll try to reproduce with a simple example the problem and file it to JIRA.
N.B: I have another problem which may be related to this but maybe has nothing to do and it's only my fault (I'm afraid the mapping with the double from - to and to-from relationship may be responsible of this). Since I'm trying to implement a "isRelatedTo" method which returns true if two parties are lied by a relationship of a given type, I am looking for a workaround. So I tried with the following code:
Code:
Session session = SessionFactoryUtils.getSession( sessionFactory, false );
try {
Party partyRelatedFrom = ( Party )session.load( Party.class, partyIdRelatedFrom );
Set relatedPartiesFrom = partyRelatedFrom.getRelatedPartiesFrom();
for ( Iterator iterator = relatedPartiesFrom.iterator() ; iterator.hasNext() ; ) {
PartyRelationship partyRelationship = ( PartyRelationship )iterator.next();
Party relatedParty = partyRelationship.getRelatedParty();
if ( relatedParty != null && relatedParty.getPartyId().equals( partyIdRelatedTo ) ) {
if ( remove ) iterator.remove();
return true;
}
}
return false;
}
catch ( HibernateException e ) {
throw SessionFactoryUtils.convertHibernateAccessException( e );
}
And this gives the following trace:
16:47:28,425 DEBUG TransactionInterceptor:146 - Getting transaction for method 'isRelatedTo' in class [it.esselunga.ecommerce.services.party.PartyService]
16:47:28,446 DEBUG HibernateTransactionManager:163 - Using transaction object [org.springframework.orm.hibernate.HibernateTransactionObject@1cb048e]
16:47:28,456 DEBUG HibernateTransactionManager:214 - Creating new transaction
16:47:28,466 DEBUG SessionFactoryUtils:156 - Opening Hibernate session
16:47:28,476 DEBUG HibernateTransactionManager:271 - Opened new session [net.sf.hibernate.impl.SessionImpl@1983ad7] for Hibernate transaction
16:47:28,496 DEBUG HibernateTransactionManager:280 - Beginning Hibernate transaction on session [net.sf.hibernate.impl.SessionImpl@1983ad7]
16:47:28,516 DEBUG TransactionSynchronizationManager:129 - Bound value [org.springframework.orm.hibernate.SessionHolder@13f348b] for key [net.sf.hibernate.impl.SessionFactoryImpl@c7833c] to thread [main]
16:47:28,536 DEBUG TransactionSynchronizationManager:129 - Bound value [org.springframework.jdbc.datasource.ConnectionHolder@92997e] for key [org.apache.commons.dbcp.BasicDataSource@ac4d3b] to thread [main]
16:47:28,546 DEBUG TransactionSynchronizationManager:175 - Initializing transaction synchronization
16:47:28,576 DEBUG TransactionSynchronizationManager:111 - Retrieved value [org.springframework.orm.hibernate.SessionHolder@13f348b] for key [net.sf.hibernate.impl.SessionFactoryImpl@c7833c] bound to thread [main]
16:47:28,596 DEBUG HibernateInterceptor:89 - Found thread-bound session for Hibernate interceptor
16:47:34,034 DEBUG SpringHibernatePartyService:52 - trying to retrieve relationship of type 94 between parties 50(from) and 49(to)
16:47:34,044 DEBUG TransactionSynchronizationManager:111 - Retrieved value [org.springframework.orm.hibernate.SessionHolder@13f348b] for key [net.sf.hibernate.impl.SessionFactoryImpl@c7833c] bound to thread [main]
Hibernate: select party0_.PARTY_ID as PARTY_ID2_, case when party0__2_.PARTY_ID is not null then 1 when party0__1_.PARTY_ID is not null then 2 when party0__3_.PARTY_ID is not null then 3 when party0_.PARTY_ID is not null then 0 end as clazz_2_, party0_.PARTY_TYPE as PARTY_TYPE8_2_, party0__1_.TITLE as TITLE10_2_, party0__1_.SURNAME as SURNAME10_2_, party0__1_.FORENAME as FORENAME10_2_, party0__1_.EMAIL as EMAIL10_2_, party0__1_.HOME_TEL as HOME_TEL10_2_, party0__1_.WORK_TEL as WORK_TEL10_2_, party0__1_.MOBILE_TEL as MOBILE_TEL10_2_, party0__1_.DATE_OF_BIRTH as DATE_OF_9_10_2_, party0__1_.SEX as SEX10_2_, party0__1_.DETAILS_PRIVATE as DETAILS11_10_2_, party0__1_.CREATION_DATE as CREATIO12_10_2_, party0__1_.PROFESSION_ID as PROFESS13_10_2_, party0__1_.EDUCATION_LEVEL_ID as EDUCATI14_10_2_, party0__2_.FIDELITY_CARD_TYPE as FIDELITY2_11_2_, party0__2_.FIDELITY_CARD_NUMBER as FIDELITY3_11_2_, party0__2_.IS_NEW_CARD_NUMBER as IS_NEW_C4_11_2_, party0__2_.HOW_MANY_RELATIVES as HOW_MANY5_11_2_, party0__2_.SEND_INFO as SEND_INFO11_2_, party0__3_.GROUP_NAME as GROUP_NAME12_2_, party0__3_.DESCRIPTION as DESCRIPT3_12_2_, profession1_.ENUM_ID as ENUM_ID0_, profession1_.ENUM_CODE as ENUM_CODE0_, profession1_.SEQUENCE as SEQUENCE0_, profession1_.DESCRIPTION as DESCRIPT5_0_, educationl2_.ENUM_ID as ENUM_ID1_, educationl2_.ENUM_CODE as ENUM_CODE1_, educationl2_.SEQUENCE as SEQUENCE1_, educationl2_.DESCRIPTION as DESCRIPT5_1_ from PARTY party0_ left outer join PERSON party0__1_ on party0_.PARTY_ID=party0__1_.PARTY_ID left outer join CUSTOMER party0__2_ on party0_.PARTY_ID=party0__2_.PARTY_ID left outer join PARTY_GROUP party0__3_ on party0_.PARTY_ID=party0__3_.PARTY_ID left outer join ENUMERATION profession1_ on party0__1_.PROFESSION_ID=profession1_.ENUM_ID left outer join ENUMERATION educationl2_ on party0__1_.EDUCATION_LEVEL_ID=educationl2_.ENUM_ID where party0_.PARTY_ID=?
Hibernate: select relatedpar0_.FROM_DATE as FROM_DATE__, relatedpar0_.THRU_DATE as THRU_DATE__, relatedpar0_.DESCRIPTION as DESCRIPT4___, relatedpar0_.RELATIONSHIP_TYPE_ID as RELATION5___, relatedpar0_.PARTY_ID_FROM as PARTY_ID6___, relatedpar0_.PARTY_ID_TO as PARTY_ID1___, partyrelat1_.ENUM_ID as ENUM_ID0_, partyrelat1_.ENUM_TYPE as ENUM_TYPE0_, partyrelat1_.ENUM_CODE as ENUM_CODE0_, partyrelat1_.SEQUENCE as SEQUENCE0_, partyrelat1_.DESCRIPTION as DESCRIPT5_0_ from PARTY_RELATIONSHIP relatedpar0_ left outer join ENUMERATION partyrelat1_ on relatedpar0_.RELATIONSHIP_TYPE_ID=partyrelat1_.ENUM_ID where relatedpar0_.PARTY_ID_TO=?
16:47:34,354 DEBUG HibernateInterceptor:109 - Not closing pre-bound Hibernate session after interceptor
16:47:34,364 DEBUG TransactionInterceptor:186 - Invoking commit for transaction on method 'isRelatedTo' in class [it.esselunga.ecommerce.services.party.PartyService]
16:47:34,374 DEBUG HibernateTransactionManager:415 - Triggering beforeCommit synchronization
16:47:34,374 DEBUG HibernateTransactionManager:430 - Triggering beforeCompletion synchronization
16:47:34,384 INFO HibernateTransactionManager:313 - Initiating transaction commit
16:47:34,384 DEBUG HibernateTransactionManager:382 - Committing Hibernate transaction on session [net.sf.hibernate.impl.SessionImpl@1983ad7]
Hibernate: delete from PARTY_RELATIONSHIP where PARTY_ID_TO=? and FROM_DATE=? and THRU_DATE=? and DESCRIPTION=? and RELATIONSHIP_TYPE_ID=? and PARTY_ID_FROM=?
Hibernate: insert into PARTY_RELATIONSHIP (PARTY_ID_TO, FROM_DATE, THRU_DATE, DESCRIPTION, RELATIONSHIP_TYPE_ID, PARTY_ID_FROM) values (?, ?, ?, ?, ?, ?)
16:47:34,614 WARN JDBCExceptionReporter:38 - SQL Error: 335544349, SQLState: HY000
16:47:34,624 ERROR JDBCExceptionReporter:46 - GDS Exception. 335544349. attempt to store duplicate value (visible to active transactions) in unique index "PK_PARTY_RELATIONSHIP"
16:47:34,634 ERROR JDBCExceptionReporter:38 - could not insert collection rows: [it.esselunga.ecommerce.data.model.Party.relatedPartiesFrom#50]
org.firebirdsql.jdbc.FBSQLException: GDS Exception. 335544349. attempt to store duplicate value (visible to active transactions) in unique index "PK_PARTY_RELATIONSHIP"
at org.firebirdsql.jdbc.AbstractPreparedStatement.internalExecute(AbstractPreparedStatement.java:445)
at org.firebirdsql.jdbc.AbstractPreparedStatement.executeUpdate(AbstractPreparedStatement.java:147)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:233)
at net.sf.hibernate.impl.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:22)
at net.sf.hibernate.collection.AbstractCollectionPersister.insertRows(AbstractCollectionPersister.java:622)
at net.sf.hibernate.impl.ScheduledCollectionUpdate.execute(ScheduledCollectionUpdate.java:49)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2382)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2338)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2204)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
at org.springframework.orm.hibernate.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:386)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:314)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:189)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:134)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:148)
at $Proxy1.isRelatedTo(Unknown Source)
at it.esselunga.ecommerce.services.party.TestSpringHibernatePartyService.testPersonWithRelativeScenario(TestSpringHibernatePartyService.java:132)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at junit.textui.TestRunner.doRun(TestRunner.java:116)
at com.intellij.rt.execution.junit2.IdeaJUnitAgent.doRun(Unknown Source)
at junit.textui.TestRunner.start(TestRunner.java:172)
at com.intellij.rt.execution.junit.TextTestRunner2.startRunnerWithArgs(Unknown Source)
at com.intellij.rt.execution.junit2.JUnitStarter.prepareStreamsAndStart(Unknown Source)
at com.intellij.rt.execution.junit2.JUnitStarter.main(Unknown Source)
After producing the jira test I'll try to look inside this one.