I'm using hibernate3 in combination with spring.
I have the following problem: I have a many-to-many relationship between product and publisher;
Product.hbm.xml:
Code:
<class name="com.sonydadc.claudio.product.beans.BasicProduct" table="CLAUDIO_PRODUCT" mutable="true" lazy="true">
<id name="id" column="PRODUCT_ID" type="string"/id>
<!--properties-->
<set name="publishers" table="CLAUDIO_PRODUCT_PUBLISHER" lazy="true" inverse="true" cascade="all">
<key column="PRODUCT_ID" />
<one-to-many class="com.sonydadc.claudio.product.beans.ProductPublisher"/>
</set>
</class>
ProductPublisher.hbm.xml:
Code:
<class name="com.sonydadc.claudio.product.beans.ProductPublisher" table="CLAUDIO_PRODUCT_PUBLISHER">
<composite-id>
<key-many-to-one name="product" class="com.sonydadc.claudio.product.beans.BasicProduct" column="PRODUCT_ID" />
<key-many-to-one name="publisher" class="com.sonydadc.claudio.product.beans.Publisher" column="PUBLISHER_ID" />
</composite-id>
</class>
Publisher.hbm.xml:
Code:
<class name="com.sonydadc.claudio.product.beans.Publisher" table="CLAUDIO_PUBLISHER" lazy="false">
<id name="id" column="PUBLISHER_ID" type="string"/>
<!--properties-->
<set name="products" table="CLAUDIO_PRODUCT_PUBLISHER" lazy="true" inverse="true" cascade="all">
<key column="PUBLISHER_ID"/>
<one-to-many class="com.sonydadc.claudio.product.beans.ProductPublisher"/>
</set>
</class>
All I want is to retrieve all ProductPublisher-Objects (by a given productId) in a DAO-Method:
Code:
public List getProductPublishersByPublisherId(String id) {
String query = "from ProductPublisher";
return this.getHibernateTemplate().find(query);
}
When executing the find-Method all I get is the following exception:
Code:
[ERROR] [action] - Servlet.service() for servlet action threw exception <java.lang.ClassCastException: com.sonydadc.claudio.product.beans.ProductPublisher>java.lang.ClassCastException: com.sonydadc.claudio.product.beans.ProductPublisher
at org.hibernate.loader.Loader.getKeyFromResultSet(Loader.java:650)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:277)
at org.hibernate.loader.Loader.doQuery(Loader.java:384)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:203)
at org.hibernate.loader.Loader.doList(Loader.java:1499)
at org.hibernate.loader.Loader.list(Loader.java:1482)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:365)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:268)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:782)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
at org.springframework.orm.hibernate3.HibernateTemplate$29.doInHibernate(HibernateTemplate.java:751)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:312)
at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:742)
at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:734)
at com.sonydadc.claudio.product.dao.ProductPublisherDAO.getProductPublishersByPublisherId(ProductPublisherDAO.java:37)
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:585)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:288)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:155)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:122)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:57)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:144)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:174)
at $Proxy11.getProductPublishersByPublisherId(Unknown Source)
at com.sonydadc.claudio.struts.publish.actions.RemovePublisherAction.execute(RemovePublisherAction.java:42)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:226)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:397)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:172)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:595)
Has somebody encountered (and solved) a similar problem.
Thx Stephan