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]