-->
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.  [ 4 posts ] 
Author Message
 Post subject: Inner join on composite-id gives error
PostPosted: Fri Mar 16, 2007 10:49 am 
Newbie

Joined: Fri Mar 16, 2007 10:35 am
Posts: 4
Hi all,

i am trying to generate an SQL query that inner joins with another table on a part of a composite id. Somehow Hibernate does generate the where clause with the right prefix, but the actual inner join is not made. I searched google and the forum for this, however i couldnt find anything that could help me solve the problem.

Hibernate version: 3
Oracle 10g (10.2)

i hope someone can help me :)

thanks :)


my code for generating the SQL:

Code:
public List listWeekFitters(Integer week, Store store) {
      Criteria fitterList = session.createCriteria(Fitters.class);
      fitterList.createAlias("day", "day");
      fitterList.add(Restrictions.eq("store", store));
      fitterList.add(Restrictions.lt("day.week", week));
      fitterList.addOrder(Order.desc("day")).addOrder(Order.asc("numbersperdivision"));
      return fitterList.list();
   }


my hibernate config:

Fitter.hbm.xml:
Code:
<hibernate-mapping package="model">
    <class name="Fitters" table="Fitters">
       <composite-id>
          <key-property name="hour" column="hour" type="integer" />
          <key-many-to-one name="day" column="day_fk" class="Calendar" />
          <key-many-to-one name="numbersperdivision" column="numbersPerDivision_FK" class="FitterGroups" />
      </composite-id>
       <property name="Amount" column="Amount" type="integer" not-null="true" />
       <many-to-one name="store" column="store_fk" class="Store" />
    </class>
</hibernate-mapping>


Calendar.hbm.xml:
Code:
<hibernate-mapping package="model">
    <class name="Calendar" table="Calendar">
       <id name="day" column="day" type="java.util.Date" >
          <generator class="assigned" />
         </id>
       <property name="week" column="week" type="integer" not-null="true" />
       <property name="year" column="year" type="integer" not-null="true" />
       <property name="period" column="period" type="integer" not-null="true" />
       <property name="quarter" column="quarter" type="integer" not-null="true" />
       <property name="season" column="season" type="integer" not-null="true" />
    </class>
</hibernate-mapping>


the SQL it creates:

Code:
Hibernate: select this_.hour as hour11_0_, this_.day_fk as day2_11_0_, this_.numbersPerDivision_FK as numbersP3_11_0_, this_.Amount as Amount11_0_, this_.store_fk as store5_11_0_ from Fitters this_ where this_.store_fk=? and day1_.week<? order by this_.day_fk desc, this_.numbersPerDivision_FK asc


the SQL it should create (i think):

Code:
Hibernate: select this_.hour as hour11_0_, this_.day_fk as day2_11_0_, this_.numbersPerDivision_FK as numbersP3_11_0_, this_.Amount as Amount11_0_, this_.store_fk as store5_11_0_ from Fitters this_ inner join Calendar day1_ on this_.day_fk = day1_.day where this_.store_fk=? and day1_.week<? order by this_.day_fk desc, this_.numbersPerDivision_FK asc


the error:

Code:
WARN [http-8080-Processor25] (JDBCExceptionReporter.java:71) - SQL Error: 904, SQLState: 42000
ERROR [http-8080-Processor25] (JDBCExceptionReporter.java:72) - ORA-00904: "DAY1_"."WEEK": invalid identifier

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:2148)
   at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)
   at org.hibernate.loader.Loader.list(Loader.java:2024)
   at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:94)
   at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1533)
   at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
   at nl.indicia.hrg.logic.PasserRegistrationManager.listWeekFitters(PasserRegistrationManager.java:45)
   at nl.indicia.hrg.action.PasserRegistrationAction.showweek(PasserRegistrationAction.java:152)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:274)
   at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:194)
   at nl.indicia.framework.action.Action.execute(Action.java:26)
   at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
   at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
   at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
   at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
   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 nl.indicia.framework.hibernate.HibernateFilter.doFilter(HibernateFilter.java:23)
   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:869)
   at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
   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(Unknown Source)
[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 19, 2007 8:37 am 
Newbie

Joined: Fri Mar 16, 2007 10:35 am
Posts: 4
anybody who can help?


Top
 Profile  
 
 Post subject: Can you try this
PostPosted: Mon Mar 19, 2007 9:35 am 
Regular
Regular

Joined: Wed Aug 24, 2005 11:49 am
Posts: 63
Code:
public List listWeekFitters(Integer week, Store store) {
      Criteria fitterList = session.createCriteria(Fitters.class);
      fitterList.add(Restrictions.eq("store", store));
      Criteria dayCriteria = fitterList.createAlias("day", "day");
      dayCriteria.add(Restrictions.lt("week", week));
      fitterList.addOrder(Order.desc("day")).addOrder(Order.asc("numbersperdivision"));
      return fitterList.list();
   }

_________________
Edwin van der Elst
Finalist IT Group


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 19, 2007 9:55 am 
Newbie

Joined: Fri Mar 16, 2007 10:35 am
Posts: 4
Thanks for your reply, unfortunately it did not resolve my problem. With your proposed resolution it gives me the following error:

org.hibernate.QueryException: could not resolve property: week of: nl.indicia.hrg.model.Fitters



After this i tried:

Code:
dayCriteria.add(Restrictions.lt("day.week", week));


which gave me:
Code:
ERROR [http-8080-Processor25] (JDBCExceptionReporter.java:72) - ORA-00904: "DAY1_"."WEEK": invalid identifier


and this:

Code:
Criteria dayCriteria = fitterList.createAlias("day", "d");
dayCriteria.add(Restrictions.lt("d.week", week));

(just in case it didnt like the double used name)

gave me this:

Code:
ERROR [http-8080-Processor25] (JDBCExceptionReporter.java:72) - ORA-00904: "D1_"."WEEK": invalid identifier


I hope someone can help me out :(


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