-->
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.  [ 1 post ] 
Author Message
 Post subject: JoinTable mapping with referenced SecondaryTable
PostPosted: Thu Apr 16, 2009 11:50 am 
Newbie

Joined: Thu Apr 16, 2009 11:33 am
Posts: 1
Hi, I am trying to do a ManyToMany join from one Entity to another on a property 'SSI_ID'. The Consultant has 'SSI_ID' mapped to its primary table, so the SQL works fine, but 'SSI_ID' is on a SecondaryTable for AccountMinor. JoinTable to tries to map 'SSI_ID' to the PrimaryTable of AccountMinor and throws an Exception.

Essentially, what I require is a 'referencedTable' attribute on JoinColumn to go with the 'referencedColumnName' or for the JoinTable mapping to be smart enough to see that the referenced object has SSI_ID mapped to a SecondaryTable. However, since these are both unavailable, does anyone know of a work-around for this situation?

EDIT - What's strange is, the query being run isnt really the join query, just a find(AccountMinor) with some criteria. However, if I remove the JoinTable mapping, the query runs fine. It is as though having this ManyToMany is causing AccountMinor to lose the SSI_ID mapping override.

Hibernate version:
3

Mapping documents:
Relationship mapping:
Code:
@ManyToMany
@JoinTable(name="ITEM_REL",
   joinColumns=@JoinColumn(name="SSI_ID2", referencedColumnName="SSI_ID"),
   inverseJoinColumns=@JoinColumn(name="SSI_ID1", referencedColumnName="SSI_ID")
)
@FilterJoinTable(name="ITEM_REL_TYPE_ID", condition="ITEM_REL_TYPE_ID = 30")
private List<AccountMinor> accountMinors = new ArrayList<AccountMinor>();


AccountMinor SSI_ID:
Code:
@Table(name="ACCOUNT_GPS")
@SecondaryTables({
   @SecondaryTable(name="CORRECTED_ACCOUNTS"),
   @SecondaryTable( name="ACCOUNT",
         uniqueConstraints=@UniqueConstraint(columnNames="SSI_ID"))
      }
   )
@AttributeOverride(name="ssiId", column=@Column(table="ACCOUNT", name="SSI_ID"))


Full stack trace of any exception that occurs:
- SQL Error: 904, SQLState: 42000
- ORA-00904: "THIS_"."SSI_ID": invalid identifier

- Method execution failed:
org.springframework.dao.InvalidDataAccessResourceUsageException: could not execute query; nested exception is org.hibernate.exception.SQLGrammarException: could not execute query
at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:630)
at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:424)
at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
at org.springframework.orm.hibernate3.HibernateTemplate.findByCriteria(HibernateTemplate.java:1055)
at org.springframework.orm.hibernate3.HibernateTemplate.findByCriteria(HibernateTemplate.java:1048)
at com.loomissayles.actuate.dao.AccountDAO.findAccountsByRunType(AccountDAO.java:86)
at com.loomissayles.actuate.service.AccountServiceImpl.findAccountsByRunType(AccountServiceImpl.java:57)
at com.loomissayles.actuate.service.BatchServiceImpl.getAccounts(BatchServiceImpl.java:146)
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:597)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at $Proxy38.getAccounts(Unknown Source)
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:597)
at org.directwebremoting.impl.ExecuteAjaxFilter.doFilter(ExecuteAjaxFilter.java:34)
at org.directwebremoting.impl.DefaultRemoter$1.doFilter(DefaultRemoter.java:428)
at org.directwebremoting.impl.DefaultRemoter.execute(DefaultRemoter.java:431)
at org.directwebremoting.impl.DefaultRemoter.execute(DefaultRemoter.java:283)
at org.directwebremoting.servlet.PlainCallHandler.handle(PlainCallHandler.java:52)
at org.directwebremoting.servlet.UrlProcessor.handle(UrlProcessor.java:101)
at org.directwebremoting.servlet.DwrServlet.doPost(DwrServlet.java:146)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)
Caused by: org.hibernate.exception.SQLGrammarException: could not execute query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:2208)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2102)
at org.hibernate.loader.Loader.list(Loader.java:2097)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:96)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1573)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
at org.springframework.orm.hibernate3.HibernateTemplate$36.doInHibernate(HibernateTemplate.java:1065)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:419)
... 52 more
Caused by: java.sql.SQLSyntaxErrorException: ORA-00904: "THIS_"."SSI_ID": invalid identifier

at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:91)
at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:133)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:206)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:455)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:413)
at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:1034)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:194)
at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:791)
at oracle.jdbc.driver.T4CPreparedStatement.executeMaybeDescribe(T4CPreparedStatement.java:866)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1186)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3387)
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3431)
at oracle.jdbc.driver.OraclePreparedStatementWrapper.executeQuery(OraclePreparedStatementWrapper.java:1491)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:184)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1785)
at org.hibernate.loader.Loader.doQuery(Loader.java:674)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.doList(Loader.java:2205)
... 59 more

Name and version of the database you are using:
Oracle 10g

The generated SQL (show_sql=true):
select this_.ACID as ACID74_2_, this_.ASSET_CLASS as ASSET2_74_2_, this_.ASSISTANT_ID as ASSISTANT10_74_2_, this_.ASST_OFFICE as ASST3_74_2_, this_.ACCOUNT_MAJOR as ACCOUNT4_74_2_, this_.MANAGER_ID as MANAGER11_74_2_, this_.PM_OFFICE as PM5_74_2_, this_.ACCOUNT_MINOR as ACCOUNT6_74_2_, this_.ACCOUNT_NAME as ACCOUNT7_74_2_, this_.CIT_SHARE_CLASS as CIT8_74_2_, this_.RECON_GROUP as RECON9_74_2_, this_.SSI_ID as SSI1_75_2_, this_1_.ACID as ACID72_2_, employee2_.PERSONNELID as PERSONNE1_78_0_, employee2_.FIRSTNAME as FIRSTNAME78_0_, employee2_.NAMEINIT as NAMEINIT78_0_, employee2_.LASTNAME as LASTNAME78_0_, employee3_.PERSONNELID as PERSONNE1_78_1_, employee3_.FIRSTNAME as FIRSTNAME78_1_, employee3_.NAMEINIT as NAMEINIT78_1_, employee3_.LASTNAME as LASTNAME78_1_
from ACCOUNT_GPS this_
left outer join CORRECTED_ACCOUNTS this_1_ on this_.ACID=this_1_.ACID
left outer join ACCOUNT this_2_ on this_.ACID=this_2_.ACID left outer join LSEMPGPS_STG2 employee2_ on this_.ASSISTANT_ID=employee2_.PERSONNELID
left outer join LSEMPGPS_STG2 employee3_ on this_.MANAGER_ID=employee3_.PERSONNELID
where this_.ACID in (select distinct this_.ACID as y0_ from act_rpt_mgr.MINOR_REPORT_RUN_REL this_ where this_.RUN_TYPE_ID=?)


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

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.