-->
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.  [ 22 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Help with a composite id and a load query sql
PostPosted: Wed Mar 16, 2005 12:33 am 
Newbie

Joined: Wed Mar 16, 2005 12:20 am
Posts: 9
Read the rules before posting!
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:

3 rc1

Mapping documents:

<hibernate-mapping package="com.tpmex.jessdb">
<class name="Timetable" table="copHorarios" lazy="true">
<composite-id name="id" class="TimetableIden" access="field">
<key-property name="timetableId" type="long"/>
<key-property name="instalationId" type="long"/>
<key-property name="dayOfWeek" type="int"/>
</composite-id>

<property name="initialTime" column="InitialTime" type="calendar"/>
<property name="finalTime" column="FinalTime" type="calendar"/>
<property name="forTrainingUse" column="UsoCapacitacion" type="boolean"/>

<loader query-ref="sqlTimetables"/>
</class>

<class name="TimetableIden" lazy="true">
<id name="timetableId" column="Horario_Id"/>

<property name="instalationId" column="Instalacion_Id" type="long"/>
<property name="dayOfWeek" column="DayOfWeek" type="int"/>
</class>


<sql-query name="sqlTimetables" >
<return alias="h" class="Timetable" lock-mode="read"/>
<return alias="i" class="TimetableIden" lock-mode="read"/>
Select Horario_Id as {i.timetableId}, Instalacion_Id as {i.instalationId}, datepart(dw, getdate()) as {i.dayOfWeek},
case datepart(dw, getdate())
when 1 then convert(datetime, domini)
when 2 then convert(datetime, lunini)
when 3 then convert(datetime, marini)
when 4 then convert(datetime, mierini)
when 5 then convert(datetime, jueini)
when 6 then convert(datetime, vieini)
when 7 then convert(datetime, sabini)
end as {h.initialTime},
case datepart(dw, getdate())
when 1 then convert(datetime, domfin)
when 2 then convert(datetime, lunfin)
when 3 then convert(datetime, marfin)
when 4 then convert(datetime, mierfin)
when 5 then convert(datetime, juefin)
when 6 then convert(datetime, viefin)
when 7 then convert(datetime, sabfin)
end as {h.finalTime},
UsoCapacitacion as {h.forTrainingUse}
From copHorarios
Where Horario_Id = ? and Instalacion_Id = ? and datepart(dw, getdate()) = ?
</sql-query>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():

TimetableIden searchtime = new TimetableIden(3,1,3);
Timetable time = (Timetable) session.get(Timetable.class, searchtime);


Full stack trace of any exception that occurs:

Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not execute query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:59)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:1502)
at org.hibernate.loader.Loader.list(Loader.java:1482)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:103)
at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1333)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:146)
at org.hibernate.persister.entity.NamedQueryLoader.load(NamedQueryLoader.java:55)
at org.hibernate.persister.entity.BasicEntityPersister.load(BasicEntityPersister.java:2453)
at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:387)
at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:368)
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:166)
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:140)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:249)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:123)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:561)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:556)
at com.tpmex.jessdb.TestHibernate.<init>(TestHibernate.java:61)
at com.tpmex.jessdb.TestHibernate.main(TestHibernate.java:108)
Caused by: java.sql.SQLException: Invalid column name timetabl1_0_.
at net.sourceforge.jtds.jdbc.JtdsResultSet.findColumn(JtdsResultSet.java:885)
at net.sourceforge.jtds.jdbc.JtdsResultSet.getLong(JtdsResultSet.java:893)
at org.hibernate.type.LongType.get(LongType.java:26)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:77)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:68)
at org.hibernate.type.AbstractType.hydrate(AbstractType.java:80)
at org.hibernate.type.ComponentType.hydrate(ComponentType.java:422)
at org.hibernate.type.ComponentType.nullSafeGet(ComponentType.java:182)
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)
... 16 more


Name and version of the database you are using:

MS SQLServer 2000 using jTDS JDBC Driver

The generated SQL (show_sql=true):

Select Horario_Id as Horario1_1_, Instalacion_Id as Instalac2_3_1_, datepart(dw, getdate()) as DayOfWeek3_1_,
case datepart(dw, getdate())
when 1 then convert(datetime, domini)
when 2 then convert(datetime, lunini)
when 3 then convert(datetime, marini)
when 4 then convert(datetime, mierini)
when 5 then convert(datetime, jueini)
when 6 then convert(datetime, vieini)
when 7 then convert(datetime, sabini)
end as InitialT4_2_0_,
case datepart(dw, getdate())
when 1 then convert(datetime, domfin)
when 2 then convert(datetime, lunfin)
when 3 then convert(datetime, marfin)
when 4 then convert(datetime, mierfin)
when 5 then convert(datetime, juefin)
when 6 then convert(datetime, viefin)
when 7 then convert(datetime, sabfin)
end as FinalTime2_0_,
UsoCapacitacion as UsoCapac6_2_0_
From copHorarios
Where Horario_Id = ? and Instalacion_Id = ? and datepart(dw, getdate()) = ?


Debug level Hibernate log excerpt:


<log4j:event logger="org.hibernate.impl.SessionFactoryObjectFactory" timestamp="1110944989523" level="DEBUG" thread="main">
<log4j:message><![CDATA[initializing class SessionFactoryObjectFactory]]></log4j:message>
</log4j:event>

<log4j:event logger="org.hibernate.impl.SessionFactoryObjectFactory" timestamp="1110944989525" level="DEBUG" thread="main">
<log4j:message><![CDATA[registered: ff80808102a97b3f0102a97b41500000 (unnamed)]]></log4j:message>
</log4j:event>

<log4j:event logger="org.hibernate.impl.SessionFactoryObjectFactory" timestamp="1110944989525" level="INFO" thread="main">
<log4j:message><![CDATA[Not binding factory to JNDI, no JNDI name configured]]></log4j:message>
</log4j:event>

<log4j:event logger="org.hibernate.impl.SessionFactoryImpl" timestamp="1110944989525" level="DEBUG" thread="main">
<log4j:message><![CDATA[instantiated session factory]]></log4j:message>
</log4j:event>

<log4j:event logger="org.hibernate.impl.SessionFactoryImpl" timestamp="1110944989525" level="INFO" thread="main">
<log4j:message><![CDATA[Checking 0 named queries]]></log4j:message>
</log4j:event>

<log4j:event logger="org.hibernate.impl.SessionImpl" timestamp="1110944989556" level="DEBUG" thread="main">
<log4j:message><![CDATA[opened session]]></log4j:message>
</log4j:event>

<log4j:event logger="org.hibernate.event.def.DefaultLoadEventListener" timestamp="1110944989563" level="DEBUG" thread="main">
<log4j:message><![CDATA[loading entity: [com.tpmex.jessdb.Timetable#component[timetableId,instalationId,dayOfWeek]{timetableId=3, dayOfWeek=3, instalationId=1}]]]></log4j:message>
</log4j:event>

<log4j:event logger="org.hibernate.event.def.DefaultLoadEventListener" timestamp="1110944989563" level="DEBUG" thread="main">
<log4j:message><![CDATA[attempting to resolve: [com.tpmex.jessdb.Timetable#component[timetableId,instalationId,dayOfWeek]{timetableId=3, dayOfWeek=3, instalationId=1}]]]></log4j:message>
</log4j:event>

<log4j:event logger="org.hibernate.event.def.DefaultLoadEventListener" timestamp="1110944989563" level="DEBUG" thread="main">
<log4j:message><![CDATA[object not resolved in any cache: [com.tpmex.jessdb.Timetable#component[timetableId,instalationId,dayOfWeek]{timetableId=3, dayOfWeek=3, instalationId=1}]]]></log4j:message>
</log4j:event>

<log4j:event logger="org.hibernate.persister.entity.BasicEntityPersister" timestamp="1110944989564" level="DEBUG" thread="main">
<log4j:message><![CDATA[Materializing entity: [com.tpmex.jessdb.Timetable#component[timetableId,instalationId,dayOfWeek]{timetableId=3, dayOfWeek=3, instalationId=1}]]]></log4j:message>
</log4j:event>

<log4j:event logger="org.hibernate.persister.entity.NamedQueryLoader" timestamp="1110944989564" level="DEBUG" thread="main">
<log4j:message><![CDATA[loading entity: com.tpmex.jessdb.Timetable using named query: sqlTimetables]]></log4j:message>
</log4j:event>

<log4j:event logger="org.hibernate.impl.SessionImpl" timestamp="1110944989574" level="DEBUG" thread="main">
<log4j:message><![CDATA[setting flush mode to: NEVER]]></log4j:message>
</log4j:event>

<log4j:event logger="org.hibernate.impl.SessionImpl" timestamp="1110944989581" level="DEBUG" thread="main">
<log4j:message><![CDATA[SQL query:


Select Horario_Id as Horario1_1_, Instalacion_Id as Instalac2_3_1_, datepart(dw, getdate()) as DayOfWeek3_1_,
case datepart(dw, getdate())
when 1 then convert(datetime, domini)
when 2 then convert(datetime, lunini)
when 3 then convert(datetime, marini)
when 4 then convert(datetime, mierini)
when 5 then convert(datetime, jueini)
when 6 then convert(datetime, vieini)
when 7 then convert(datetime, sabini)
end as InitialT4_2_0_,
case datepart(dw, getdate())
when 1 then convert(datetime, domfin)
when 2 then convert(datetime, lunfin)
when 3 then convert(datetime, marfin)
when 4 then convert(datetime, mierfin)
when 5 then convert(datetime, juefin)
when 6 then convert(datetime, viefin)
when 7 then convert(datetime, sabfin)
end as FinalTime2_0_,
UsoCapacitacion as UsoCapac6_2_0_
From copHorarios
Where Horario_Id = ? and Instalacion_Id = ? and datepart(dw, getdate()) = ?
]]></log4j:message>
</log4j:event>

<log4j:event logger="org.hibernate.jdbc.AbstractBatcher" timestamp="1110944989584" level="DEBUG" thread="main">
<log4j:message><![CDATA[about to open PreparedStatement (open PreparedStatements: 0, globally: 0)]]></log4j:message>
</log4j:event>

<log4j:event logger="org.hibernate.jdbc.AbstractBatcher" timestamp="1110944989584" level="DEBUG" thread="main">
<log4j:message><![CDATA[opening JDBC connection]]></log4j:message>
</log4j:event>

<log4j:event logger="org.hibernate.connection.DriverManagerConnectionProvider" timestamp="1110944989584" level="DEBUG" thread="main">
<log4j:message><![CDATA[total checked-out connections: 0]]></log4j:message>
</log4j:event>

<log4j:event logger="org.hibernate.connection.DriverManagerConnectionProvider" timestamp="1110944989587" level="DEBUG" thread="main">
<log4j:message><![CDATA[using pooled JDBC connection, pool size: 0]]></log4j:message>
</log4j:event>

<log4j:event logger="org.hibernate.SQL" timestamp="1110944989587" level="DEBUG" thread="main">
<log4j:message><![CDATA[


Select Horario_Id as Horario1_1_, Instalacion_Id as Instalac2_3_1_, datepart(dw, getdate()) as DayOfWeek3_1_,
case datepart(dw, getdate())
when 1 then convert(datetime, domini)
when 2 then convert(datetime, lunini)
when 3 then convert(datetime, marini)
when 4 then convert(datetime, mierini)
when 5 then convert(datetime, jueini)
when 6 then convert(datetime, vieini)
when 7 then convert(datetime, sabini)
end as InitialT4_2_0_,
case datepart(dw, getdate())
when 1 then convert(datetime, domfin)
when 2 then convert(datetime, lunfin)
when 3 then convert(datetime, marfin)
when 4 then convert(datetime, mierfin)
when 5 then convert(datetime, juefin)
when 6 then convert(datetime, viefin)
when 7 then convert(datetime, sabfin)
end as FinalTime2_0_,
UsoCapacitacion as UsoCapac6_2_0_
From copHorarios
Where Horario_Id = ? and Instalacion_Id = ? and datepart(dw, getdate()) = ?
]]></log4j:message>
</log4j:event>

<log4j:event logger="org.hibernate.jdbc.AbstractBatcher" timestamp="1110944989601" level="DEBUG" thread="main">
<log4j:message><![CDATA[preparing statement]]></log4j:message>
</log4j:event>

<log4j:event logger="org.hibernate.type.LongType" timestamp="1110944989608" level="DEBUG" thread="main">
<log4j:message><![CDATA[binding '3' to parameter: 1]]></log4j:message>
</log4j:event>

<log4j:event logger="org.hibernate.type.LongType" timestamp="1110944989608" level="DEBUG" thread="main">
<log4j:message><![CDATA[binding '1' to parameter: 2]]></log4j:message>
</log4j:event>

<log4j:event logger="org.hibernate.type.IntegerType" timestamp="1110944989608" level="DEBUG" thread="main">
<log4j:message><![CDATA[binding '3' to parameter: 3]]></log4j:message>
</log4j:event>

<log4j:event logger="org.hibernate.jdbc.AbstractBatcher" timestamp="1110944989626" level="DEBUG" thread="main">
<log4j:message><![CDATA[about to open ResultSet (open ResultSets: 0, globally: 0)]]></log4j:message>
</log4j:event>

<log4j:event logger="org.hibernate.loader.Loader" timestamp="1110944989626" level="DEBUG" thread="main">
<log4j:message><![CDATA[processing result set]]></log4j:message>
</log4j:event>

<log4j:event logger="org.hibernate.loader.Loader" timestamp="1110944989627" level="DEBUG" thread="main">
<log4j:message><![CDATA[result set row: 0]]></log4j:message>
</log4j:event>

<log4j:event logger="org.hibernate.jdbc.AbstractBatcher" timestamp="1110944989627" level="DEBUG" thread="main">
<log4j:message><![CDATA[about to close ResultSet (open ResultSets: 1, globally: 1)]]></log4j:message>
</log4j:event>

<log4j:event logger="org.hibernate.jdbc.AbstractBatcher" timestamp="1110944989627" level="DEBUG" thread="main">
<log4j:message><![CDATA[about to close PreparedStatement (open PreparedStatements: 1, globally: 1)]]></log4j:message>
</log4j:event>

<log4j:event logger="org.hibernate.jdbc.AbstractBatcher" timestamp="1110944989627" level="DEBUG" thread="main">
<log4j:message><![CDATA[closing statement]]></log4j:message>
</log4j:event>

<log4j:event logger="org.hibernate.util.JDBCExceptionReporter" timestamp="1110944989630" level="DEBUG" thread="main">
<log4j:message><![CDATA[could not execute query [


Select Horario_Id as Horario1_1_, Instalacion_Id as Instalac2_3_1_, datepart(dw, getdate()) as DayOfWeek3_1_,
case datepart(dw, getdate())
when 1 then convert(datetime, domini)
when 2 then convert(datetime, lunini)
when 3 then convert(datetime, marini)
when 4 then convert(datetime, mierini)
when 5 then convert(datetime, jueini)
when 6 then convert(datetime, vieini)
when 7 then convert(datetime, sabini)
end as InitialT4_2_0_,
case datepart(dw, getdate())
when 1 then convert(datetime, domfin)
when 2 then convert(datetime, lunfin)
when 3 then convert(datetime, marfin)
when 4 then convert(datetime, mierfin)
when 5 then convert(datetime, juefin)
when 6 then convert(datetime, viefin)
when 7 then convert(datetime, sabfin)
end as FinalTime2_0_,
UsoCapacitacion as UsoCapac6_2_0_
From copHorarios
Where Horario_Id = ? and Instalacion_Id = ? and datepart(dw, getdate()) = ?
]]]></log4j:message>
<log4j:throwable><![CDATA[java.sql.SQLException: Invalid column name timetabl1_0_.
at net.sourceforge.jtds.jdbc.JtdsResultSet.findColumn(JtdsResultSet.java:885)
at net.sourceforge.jtds.jdbc.JtdsResultSet.getLong(JtdsResultSet.java:893)
at org.hibernate.type.LongType.get(LongType.java:26)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:77)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:68)
at org.hibernate.type.AbstractType.hydrate(AbstractType.java:80)
at org.hibernate.type.ComponentType.hydrate(ComponentType.java:422)
at org.hibernate.type.ComponentType.nullSafeGet(ComponentType.java:182)
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.custom.CustomLoader.list(CustomLoader.java:103)
at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1333)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:146)
at org.hibernate.persister.entity.NamedQueryLoader.load(NamedQueryLoader.java:55)
at org.hibernate.persister.entity.BasicEntityPersister.load(BasicEntityPersister.java:2453)
at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:387)
at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:368)
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:166)
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:140)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:249)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:123)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:561)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:556)
at com.tpmex.jessdb.TestHibernate.<init>(TestHibernate.java:61)
at com.tpmex.jessdb.TestHibernate.main(TestHibernate.java:108)
]]></log4j:throwable>
</log4j:event>

<log4j:event logger="org.hibernate.util.JDBCExceptionReporter" timestamp="1110944989633" level="WARN" thread="main">
<log4j:message><![CDATA[SQL Error: 0, SQLState: 07009]]></log4j:message>
</log4j:event>

<log4j:event logger="org.hibernate.util.JDBCExceptionReporter" timestamp="1110944989633" level="ERROR" thread="main">
<log4j:message><![CDATA[Invalid column name timetabl1_0_.]]></log4j:message>
</log4j:event>

<log4j:event logger="org.hibernate.impl.SessionImpl" timestamp="1110944989636" level="DEBUG" thread="main">
<log4j:message><![CDATA[setting flush mode to: AUTO]]></log4j:message>
</log4j:event>

<log4j:event logger="org.hibernate.event.def.DefaultLoadEventListener" timestamp="1110944989636" level="INFO" thread="main">
<log4j:message><![CDATA[Error performing load command]]></log4j:message>
<log4j:throwable><![CDATA[org.hibernate.exception.SQLGrammarException: could not execute query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:59)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:1502)
at org.hibernate.loader.Loader.list(Loader.java:1482)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:103)
at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1333)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:146)
at org.hibernate.persister.entity.NamedQueryLoader.load(NamedQueryLoader.java:55)
at org.hibernate.persister.entity.BasicEntityPersister.load(BasicEntityPersister.java:2453)
at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:387)
at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:368)
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:166)
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:140)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:249)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:123)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:561)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:556)
at com.tpmex.jessdb.TestHibernate.<init>(TestHibernate.java:61)
at com.tpmex.jessdb.TestHibernate.main(TestHibernate.java:108)
Caused by: java.sql.SQLException: Invalid column name timetabl1_0_.
at net.sourceforge.jtds.jdbc.JtdsResultSet.findColumn(JtdsResultSet.java:885)
at net.sourceforge.jtds.jdbc.JtdsResultSet.getLong(JtdsResultSet.java:893)
at org.hibernate.type.LongType.get(LongType.java:26)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:77)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:68)
at org.hibernate.type.AbstractType.hydrate(AbstractType.java:80)
at org.hibernate.type.ComponentType.hydrate(ComponentType.java:422)
at org.hibernate.type.ComponentType.nullSafeGet(ComponentType.java:182)
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)
... 16 more
]]></log4j:throwable>
</log4j:event>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 16, 2005 12:36 pm 
Pro
Pro

Joined: Tue Aug 26, 2003 1:24 pm
Posts: 213
Location: Richardson, TX
The column timetabl1_0_ (the invalid one) does not show up in the generated SQL statement. Are you sure that's the right SQL for the query you've defined?


Top
 Profile  
 
 Post subject: SQL Aliases are changed by hibernate
PostPosted: Wed Mar 16, 2005 12:53 pm 
Newbie

Joined: Wed Mar 16, 2005 12:20 am
Posts: 9
My named query is:
Select Horario_Id as {i.timetableId}, Instalacion_Id as {i.instalationId}, datepart(dw, getdate()) as {i.dayOfWeek},
case datepart(dw, getdate())
when 1 then convert(datetime, domini)
when 2 then convert(datetime, lunini)
when 3 then convert(datetime, marini)
when 4 then convert(datetime, mierini)
when 5 then convert(datetime, jueini)
when 6 then convert(datetime, vieini)
when 7 then convert(datetime, sabini)
end as {h.initialTime},
case datepart(dw, getdate())
when 1 then convert(datetime, domfin)
when 2 then convert(datetime, lunfin)
when 3 then convert(datetime, marfin)
when 4 then convert(datetime, mierfin)
when 5 then convert(datetime, juefin)
when 6 then convert(datetime, viefin)
when 7 then convert(datetime, sabfin)
end as {h.finalTime},
UsoCapacitacion as {h.forTrainingUse}
From copHorarios
Where Horario_Id = ? and Instalacion_Id = ? and datepart(dw, getdate()) = ?


but hibernate changes my aliases to the following:

Select Horario_Id as Horario1_1_, Instalacion_Id as Instalac2_3_1_, datepart(dw, getdate()) as DayOfWeek3_1_,
case datepart(dw, getdate())
when 1 then convert(datetime, domini)
when 2 then convert(datetime, lunini)
when 3 then convert(datetime, marini)
when 4 then convert(datetime, mierini)
when 5 then convert(datetime, jueini)
when 6 then convert(datetime, vieini)
when 7 then convert(datetime, sabini)
end as InitialT4_2_0_,
case datepart(dw, getdate())
when 1 then convert(datetime, domfin)
when 2 then convert(datetime, lunfin)
when 3 then convert(datetime, marfin)
when 4 then convert(datetime, mierfin)
when 5 then convert(datetime, juefin)
when 6 then convert(datetime, viefin)
when 7 then convert(datetime, sabfin)
end as FinalTime2_0_,
UsoCapacitacion as UsoCapac6_2_0_
From copHorarios
Where Horario_Id = ? and Instalacion_Id = ? and datepart(dw, getdate()) = ?


greg_barton wrote:
The column timetabl1_0_ (the invalid one) does not show up in the generated SQL statement. Are you sure that's the right SQL for the query you've defined?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 16, 2005 1:12 pm 
Pro
Pro

Joined: Tue Aug 26, 2003 1:24 pm
Posts: 213
Location: Richardson, TX
In the last stack trace you posted, there is this line:

Quote:
Caused by: java.sql.SQLException: Invalid column name timetabl1_0_.

The last SQL statement you posted could not produce this exception because it does not contain that column. The question is, where is the SQL statement that does contain that column?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 16, 2005 2:59 pm 
Newbie

Joined: Wed Mar 16, 2005 12:20 am
Posts: 9
check it out my initial request. There is my sql-query element in the mapping file and there is logging file. You will see that the aliases defined on sql-query element doesn't appears with the same name in the logging file.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 16, 2005 4:53 pm 
Pro
Pro

Joined: Tue Aug 26, 2003 1:24 pm
Posts: 213
Location: Richardson, TX
OK, I think I see now. You shouldn't include the <composite-id> type in the mapping file. Also, you should name the columns in your <composite-id> tag. Try this:

Code:

<class name="Timetable" table="copHorarios" lazy="true">
  <composite-id name="id" class="TimetableIden" access="field">
    <key-property name="timetableId" column="Horario_Id" type="long"/>
    <key-property name="instalationId" column="Instalacion_Id" type="long"/>
    <key-property name="dayOfWeek" column="DayOfWeek" type="int"/>
  </composite-id>

  <property name="initialTime" column="InitialTime" type="calendar"/>
  <property name="finalTime" column="FinalTime" type="calendar"/>
  <property name="forTrainingUse" column="UsoCapacitacion" type="boolean"/>

  <loader query-ref="sqlTimetables"/>
</class>


Leave out the <class> mapping for TimetableIden.

Hibernate isn't renaming the column. You're just not naming it in the mapping. :)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 16, 2005 5:43 pm 
Newbie

Joined: Wed Mar 16, 2005 12:20 am
Posts: 9
I tried these mapping file too and throws an error with message "column not found for property [timetableId]". Then I debug into some Hibernate class and found that only found the following properties of my class mapping: id, initialTime, finalTime and forTrainingUse and NOT found the properties inner composite-id (timetableId, instalationId and dayOfWeek). why? is this a bug?

<class name="Timetable" table="copHorarios" lazy="true">
<composite-id name="id" class="TimetableIden" access="field">
<key-property name="timetableId" column="Horario_Id" type="long"/> //red color: not founded by hibernate
<key-property name="instalationId" column="Instalacion_Id" type="long"/>
<key-property name="dayOfWeek" column="DayOfWeek" type="int"/>

</composite-id>

<property name="initialTime" column="InitialTime" type="calendar"/>
<property name="finalTime" column="FinalTime" type="calendar"/>
<property name="forTrainingUse" column="UsoCapacitacion" type="boolean"/>

<loader query-ref="sqlTimetables"/>
</class>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 16, 2005 5:55 pm 
Pro
Pro

Joined: Tue Aug 26, 2003 1:24 pm
Posts: 213
Location: Richardson, TX
Are those fields in the "copHorarios" table?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 16, 2005 6:12 pm 
Newbie

Joined: Wed Mar 16, 2005 12:20 am
Posts: 9
The fields: Horario_Id and Instalacion_Id are in the 'copHorarios' but 'DayOfWeek' is calculated in the sql-query element (see below).

<sql-query name="sqlTimetables" >
<return alias="h" class="Timetable" lock-mode="read"/>
<return alias="i" class="TimetableIden" lock-mode="read"/>
Select Horario_Id as {i.timetableId}, Instalacion_Id as {i.instalationId}, datepart(dw, getdate()) as {i.
dayOfWeek},
case datepart(dw, getdate())
when 1 then convert(datetime, domini)
when 2 then convert(datetime, lunini)
when 3 then convert(datetime, marini)
when 4 then convert(datetime, mierini)
when 5 then convert(datetime, jueini)
when 6 then convert(datetime, vieini)
when 7 then convert(datetime, sabini)
end as {h.initialTime},
case datepart(dw, getdate())
when 1 then convert(datetime, domfin)
when 2 then convert(datetime, lunfin)
when 3 then convert(datetime, marfin)
when 4 then convert(datetime, mierfin)
when 5 then convert(datetime, juefin)
when 6 then convert(datetime, viefin)
when 7 then convert(datetime, sabfin)
end as {h.finalTime},
UsoCapacitacion as {h.forTrainingUse}
From copHorarios
Where Horario_Id = ? and Instalacion_Id = ? and datepart(dw, getdate()) = ?
</sql-query>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 16, 2005 6:39 pm 
Pro
Pro

Joined: Tue Aug 26, 2003 1:24 pm
Posts: 213
Location: Richardson, TX
I don't think you understand. You can't map any property to a table if there is no column that holds the data. Are you saying there is no "DayOfWeek" column in the "copHorarios" table? What is the primary key of the "copHorarios" table?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 16, 2005 7:09 pm 
Newbie

Joined: Wed Mar 16, 2005 12:20 am
Posts: 9
the primary key is: horario_id and instalacion_id. I already changed in the morning.

And yes: DayOfWeek is not in the table "copHorarios" but I am specifying the load sql query, maybe need to specify "update=false" and "insert=false".

Are you saying that every property must exist in table 'copHorarios' with a sql loader or without it?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 17, 2005 1:12 am 
Pro
Pro

Joined: Tue Aug 26, 2003 1:24 pm
Posts: 213
Location: Richardson, TX
Yes, every property you declare as persistent (by placing it in a hibernate mapping of the class, for instance) does need to have at least one field to store it's data in the underlying table. That's the entire point of declaring a persistence layer.

Of course, your POJOS can have properties that are not persistent, but then you can't declare them in a mapping, nor can you query on them. You can create arbitrary objects from the results of HQL queries using "select new()," though.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 17, 2005 6:33 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
not true greg ,)

persistent attributes can be fully calculated or as we call it in hibernate a formula.

what jsalazar is doing is basically to implment his own formula via sql loader which should work. - and yes, you need to play with insert/update true/false to make it only used in selects.

The reason he gets a column not found is because hibernate is trying to find a column and that column is for some reason missing in the sql he has.

your last message saying "column not found for property" i cant locate - can you post the log/stacktrace ? (this time without all the xml bloat which makes it unreadable for humans ,)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 17, 2005 6:35 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
not true greg ,)

persistent attributes can be fully calculated or as we call it in hibernate a formula.

what jsalazar is doing is basically to implment his own formula via sql loader which should work. - and yes, you need to play with insert/update true/false to make it only used in selects.

The reason he gets a column not found is because hibernate is trying to find a column and that column is for some reason missing in the sql he has.

your last message saying "column not found for property" i cant locate - can you post the log/stacktrace ? (this time without all the xml bloat which makes it unreadable for humans ,)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 17, 2005 10:42 am 
Pro
Pro

Joined: Tue Aug 26, 2003 1:24 pm
Posts: 213
Location: Richardson, TX
Oops. My bad. Catching up on the new Hibernate3 features. So, a clarification: can you query against formula values? I've read that you can't: http://forum.hibernate.org/viewtopic.php?t=940040 And you mean it's possible to create a formula that's not based on any table data? (i.e. it can use any arbitrary SQL)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 22 posts ]  Go to page 1, 2  Next

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.