-->
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: Bad SQL gen'd with InheritanceType.JOINED and OneToMany
PostPosted: Fri Aug 18, 2006 2:39 am 
Beginner
Beginner

Joined: Thu Nov 20, 2003 1:30 pm
Posts: 27
Pretty sure this is a bug...I have a class Report which extends Product with InheritanceType.JOINED and Product has a OneToMany of categories. Any time I try to query based on the categories I get the following exception.

Thanks

Query query = session().createQuery(
"SELECT p.report FROM "
+ ReportPurchase.class.getName() + " p "
+ "WHERE p.report.categories IN (:categories) ");
query.setParameterList("categories", categories);

public class ReportPurchase
@NotNull
@ManyToOne
private Report report;

@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@Searchable
public class Report extends Product

public class Product
@OneToMany
@Cascade( { CascadeType.ALL, CascadeType.DELETE_ORPHAN })
Set<Category> categories = new HashSet<Category>();

Hibernate version: 3.2.0 CR2

Full stack trace of any exception that occurs:
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:2147)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2028)
at org.hibernate.loader.Loader.list(Loader.java:2023)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:393)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at com.researchjunction.service.hibernate.HibernateReportService.findBestSellingReports(HibernateReportService.java:214)
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:334)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:181)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:148)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:100)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:209)
at $Proxy45.findBestSellingReports(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:585)
at wicket.proxy.LazyInitProxyFactory$JdkHandler.invoke(LazyInitProxyFactory.java:377)
at wicket.proxy.$Proxy50.findBestSellingReports(Unknown Source)
at com.researchjunction.panel.BestSellingReportsPanel.<init>(BestSellingReportsPanel.java:26)
at com.researchjunction.page.guest.ReportPage.init(ReportPage.java:137)
at com.researchjunction.page.guest.ReportPage.<init>(ReportPage.java:72)
at com.researchjunction.page.administrator.ReviewReports$1.onClick(ReviewReports.java:76)
at common.wicket.component.LinkPropertyColumn$LinkPanel$1.onClick(LinkPropertyColumn.java:53)
at wicket.markup.html.link.Link.onLinkClicked(Link.java:254)
... 34 more
Caused by: java.sql.SQLException: No value specified for parameter 1
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:910)
at com.mysql.jdbc.PreparedStatement.fillSendPacket(PreparedStatement.java:1530)
at com.mysql.jdbc.PreparedStatement.fillSendPacket(PreparedStatement.java:1478)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1199)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeQuery(NewProxyPreparedStatement.java:76)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1668)
at org.hibernate.loader.Loader.doQuery(Loader.java:662)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.doList(Loader.java:2144)
... 65 more

Name and version of the database you are using: mysql 5.1

The generated SQL (show_sql=true):
Hibernate: select report1_.id as id37_, report1_.title as title37_, report1_.description as descript4_37_, report1_.manufacturer_id as manufac18_37_, report1_.visitors as visitors37_, report1_.createdDate as createdD6_37_, report1_.updatedDate as updatedD7_37_, report1_.reportDraft_id as reportD19_37_, report1_.subTitle as subTitle37_, report1_.excerpt as excerpt37_, report1_.pages as pages37_, report1_.author as author37_, report1_.tableOfContents as tableOf12_37_, report1_.publishedDate as publish13_37_, report1_.rating as rating37_, report1_.companiesMentioned as compani15_37_, report1_.executiveSummaryPdf as executi16_37_, report1_.pdf as pdf37_, report1_.category_id as category20_37_, report1_.alternateCategory_id as alterna21_37_ from reportPurchases reportpurc0_ inner join products report1_ on reportpurc0_.report_id=report1_.id, products_categories categories3_, categories category4_ where report1_.id=categories3_.products_id and categories3_.categories_id=category4_.id and (. in (?))


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 18, 2006 4:18 am 
Expert
Expert

Joined: Thu Sep 22, 2005 10:29 am
Posts: 285
Location: Almassera/Valencia/Spain/EU/Earth/Solar system/Milky Way/Local Group/Virgo Supercluster
Is p.report.categories a Set?

If it is a Set then you can't ask for: Set IN List


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 18, 2006 4:20 am 
Expert
Expert

Joined: Thu Sep 22, 2005 10:29 am
Posts: 285
Location: Almassera/Valencia/Spain/EU/Earth/Solar system/Milky Way/Local Group/Virgo Supercluster
Maybe you're asking for:

Code:
SELECT
   r
FROM
   ReportPurchase p
   inner join p.report r
   inner join r.categories c
WHERE
   c IN (:categories)


Please, don't forget to rate.


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.