Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:
Hibernate 3.0.5
I just migrated to hibernate3 and one of my HQL query does not work anymore. To give some background on what I think is the root problem, originLocation is a property of type any. Here is what the query looked like before with hibernate2:
SELECT soGroup.originLocation
FROM ServiceOrderGroupDTO AS soGroup
inner join soGroup.originLocation ori
WHERE soGroup.originLocation.id IS NOT NULL
Order by request.creationDate DESC
Now with hibernate3 I get an exception (i've put it in the proper section). So I tried a simplified version that looks like this:
SELECT soGroup.originLocation
FROM ServiceOrderGroupDTO AS soGroup
But with this query, I get back ServiceOrderGrouDTOs and not ServiceOrderLocationDTOs, most probably because the join is not there.
Mapping documents:
I'm including the principal mapping document, if any other document is needed, I can provide. I just don't want this post to be bigger then it needs.
Code:
<class name="ServiceOrderGroupDTO" table="Service_Order_Group" lazy="false">
<cache usage="read-write"/>
<id name="id">
<generator class="native"/>
</id>
<property name="storyDescription" column="description" not-null="false" length="256"/>
<property name="origin" column="origin" not-null="false" length="50"/>
<property name="destination" column="destination" not-null="false" length="50"/>
<property name="serviceDescription" column="service_description" not-null="false" length="1500"/>
<property name="reporterName" column="reporter_name" not-null="false" length="50"/>
<property name="reporterPhone" column="reporter_phone" not-null="false" length="50"/>
<property name="guest" column="guest" not-null="false" length="256"/>
<property name="bookingTypeId" column="booking_type_id" not-null="false"/>
<property name="serviceOrderNumber" column="service_order_number" not-null="true"/>
<any name="originLocation" meta-type="int" id-type="int" cascade="none">
<meta-value class="com.invidex.videolinx.common.persistence.dto.area.CityDTO" value="10202"/>
<meta-value class="com.invidex.videolinx.common.persistence.dto.area.ProvinceDTO" value="10203"/>
<meta-value class="com.invidex.videolinx.common.persistence.dto.area.CountryDTO" value="10204"/>
<meta-value class="com.invidex.videolinx.common.persistence.dto.area.RegionDTO" value="10205"/>
<meta-value class="com.invidex.videolinx.common.persistence.dto.facility.TerrestrialFacilityDTO" value="10700"/>
<meta-value class="com.invidex.videolinx.common.persistence.dto.facility.SatelliteDTO" value="10800"/>
<column name="origin_entity_id"/>
<column name="origin_instance_id"/>
</any>
<any name="destinationLocation" meta-type="int" id-type="int" cascade="none">
<meta-value class="com.invidex.videolinx.common.persistence.dto.area.CityDTO" value="10202"/>
<meta-value class="com.invidex.videolinx.common.persistence.dto.area.ProvinceDTO" value="10203"/>
<meta-value class="com.invidex.videolinx.common.persistence.dto.area.CountryDTO" value="10204"/>
<meta-value class="com.invidex.videolinx.common.persistence.dto.area.RegionDTO" value="10205"/>
<meta-value class="com.invidex.videolinx.common.persistence.dto.facility.TerrestrialFacilityDTO" value="10700"/>
<meta-value class="com.invidex.videolinx.common.persistence.dto.facility.SatelliteDTO" value="10800"/>
<column name="destination_entity_id"/>
<column name="destination_instance_id"/>
</any>
<many-to-one name="reporter" column="reporter_id" not-null="false" cascade="none"/>
<many-to-one name="currency" column="currency_id" not-null="false" cascade="none"/>
</class>
Code between sessionFactory.openSession() and session.close():Code:
SessionFactory sessionFactory = (SessionFactory) context.lookup("java:/hibernate/SessionFactory");
String query = (String) dynaActionForm.get("query");
final Session session = sessionFactory.openSession();
List results = session.createQuery(query).list();
session.close();
Full stack trace of any exception that occurs:Code:
java.lang.NullPointerException
at org.hibernate.hql.ast.HqlSqlWalker.createFromJoinElement(HqlSqlWalker.java:264)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.joinElement(HqlSqlBaseWalker.java:3022)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:2841)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:2719)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:513)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:371)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:201)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:151)
at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:189)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:130)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:83)
at org.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:427)
at org.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:884)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:834)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
at com.invidex.videolinx.server.query.QueryAction.execute(QueryAction.java:40)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:615)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:688)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:427)
at org.mortbay.jetty.servlet.WebApplicationHandler.dispatch(WebApplicationHandler.java:496)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:569)
at org.mortbay.http.HttpContext.handle(HttpContext.java:1482)
at org.mortbay.jetty.servlet.WebApplicationContext.handle(WebApplicationContext.java:624)
at org.mortbay.http.HttpContext.handle(HttpContext.java:1434)
at org.mortbay.http.HttpServer.service(HttpServer.java:896)
at org.jboss.jetty.Jetty.service(Jetty.java:454)
at org.mortbay.http.HttpConnection.service(HttpConnection.java:814)
at org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:981)
at org.mortbay.http.HttpConnection.handle(HttpConnection.java:831)
at org.mortbay.http.SocketListener.handleConnection(SocketListener.java:244)
at org.mortbay.util.ThreadedServer.handle(ThreadedServer.java:366)
at org.mortbay.util.ThreadPool$PoolThread.run(ThreadPool.java:534)
Name and version of the database you are using:Microsoft SQL Server 2000 - 8.00.534 (Intel X86)
The generated SQL (show_sql=true):Im not including any SQL because the query crashes before producing any. Assuming the right query is the one that worked with hibernate2.
Debug level Hibernate log excerpt:Again, it's the debug ouput of the ry that crashes.
Code:
2005-09-01 19:54:16,808 DEBUG [org.hibernate.impl.SessionFactoryObjectFactory] JNDI lookup: hibernate/SessionFactory
2005-09-01 19:54:16,808 DEBUG [org.hibernate.impl.SessionFactoryObjectFactory] lookup: uid=2c90811c06133e4b0106133e5d060000
2005-09-01 19:54:16,808 DEBUG [org.hibernate.impl.SessionImpl] opened session at timestamp: 4610475855085568
2005-09-01 19:54:16,808 DEBUG [org.hibernate.hql.ast.QueryTranslatorImpl] parse() - HQL: SELECT soGroup.originLocation
FROM com.invidex.videolinx.common.persistence.dto.request.service.ServiceOrderGroupDTO AS soGroup
inner join soGroup.originLocation ori
WHERE soGroup.originLocation.id IS NOT NULL
Order by request.creationDate DESC
2005-09-01 19:54:16,808 DEBUG [org.hibernate.hql.ast.AST] --- HQL AST ---
\-[QUERY] 'query'
+-[SELECT_FROM] 'SELECT_FROM'
| +-[FROM] 'FROM'
| | +-[RANGE] 'RANGE'
| | | +-[DOT] '.'
| | | | +-[DOT] '.'
| | | | | +-[DOT] '.'
| | | | | | +-[DOT] '.'
| | | | | | | +-[DOT] '.'
| | | | | | | | +-[DOT] '.'
| | | | | | | | | +-[DOT] '.'
| | | | | | | | | | +-[DOT] '.'
| | | | | | | | | | | +-[IDENT] 'com'
| | | | | | | | | | | \-[IDENT] 'invidex'
| | | | | | | | | | \-[IDENT] 'videolinx'
| | | | | | | | | \-[IDENT] 'common'
| | | | | | | | \-[IDENT] 'persistence'
| | | | | | | \-[IDENT] 'dto'
| | | | | | \-[IDENT] 'request'
| | | | | \-[IDENT] 'service'
| | | | \-[IDENT] 'ServiceOrderGroupDTO'
| | | \-[ALIAS] 'soGroup'
| | \-[JOIN] 'join'
| | +-[INNER] 'inner'
| | +-[DOT] '.'
| | | +-[IDENT] 'soGroup'
| | | \-[IDENT] 'originLocation'
| | \-[ALIAS] 'ori'
| \-[SELECT] 'SELECT'
| \-[DOT] '.'
| +-[IDENT] 'soGroup'
| \-[IDENT] 'originLocation'
+-[WHERE] 'WHERE'
| \-[IS_NOT_NULL] 'is not null'
| \-[DOT] '.'
| +-[DOT] '.'
| | +-[IDENT] 'soGroup'
| | \-[IDENT] 'originLocation'
| \-[IDENT] 'id'
\-[ORDER] 'Order'
+-[DOT] '.'
| +-[IDENT] 'request'
| \-[IDENT] 'creationDate'
\-[DESCENDING] 'DESC'
2005-09-01 19:54:16,808 DEBUG [org.hibernate.hql.ast.ErrorCounter] throwQueryException() : no errors
2005-09-01 19:54:16,808 DEBUG [org.hibernate.hql.antlr.HqlSqlBaseWalker] query() << begin, level = 1
2005-09-01 19:54:16,808 DEBUG [org.hibernate.hql.ast.FromElement] FromClause{level=1} : com.invidex.videolinx.common.persistence.dto.request.service.ServiceOrderGroupDTO (soGroup) -> serviceord0_
2005-09-01 19:54:16,808 DEBUG [org.hibernate.hql.ast.FromReferenceNode] Resolved : soGroup -> serviceord0_.id
2005-09-01 19:54:16,824 DEBUG [org.hibernate.hql.ast.DotNode] getDataType() : originLocation -> org.hibernate.type.AnyType@b99d08
2005-09-01 19:54:16,824 DEBUG [org.hibernate.hql.ast.FromReferenceNode] Resolved : soGroup.originLocation -> (serviceord0_.origin_entity_id, serviceord0_.origin_instance_id)
2005-09-01 19:54:16,871 WARN [org.apache.struts.action.RequestProcessor] Unhandled Exception thrown: class java.lang.NullPointerException
2005-09-01 19:54:16,871 DEBUG [org.mortbay.jetty.servlet.ServletHandler] EXCEPTION
javax.servlet.ServletException
at org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:545)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:486)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:615)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:688)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:427)
at org.mortbay.jetty.servlet.WebApplicationHandler.dispatch(WebApplicationHandler.java:496)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:569)
at org.mortbay.http.HttpContext.handle(HttpContext.java:1482)
at org.mortbay.jetty.servlet.WebApplicationContext.handle(WebApplicationContext.java:624)
at org.mortbay.http.HttpContext.handle(HttpContext.java:1434)
at org.mortbay.http.HttpServer.service(HttpServer.java:896)
at org.jboss.jetty.Jetty.service(Jetty.java:454)
at org.mortbay.http.HttpConnection.service(HttpConnection.java:814)
at org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:981)
at org.mortbay.http.HttpConnection.handle(HttpConnection.java:831)
at org.mortbay.http.SocketListener.handleConnection(SocketListener.java:244)
at org.mortbay.util.ThreadedServer.handle(ThreadedServer.java:366)
at org.mortbay.util.ThreadPool$PoolThread.run(ThreadPool.java:534)
2005-09-01 19:54:16,871 WARN [/query3] /query3/runQuery.do:
java.lang.NullPointerException
at org.hibernate.hql.ast.HqlSqlWalker.createFromJoinElement(HqlSqlWalker.java:264)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.joinElement(HqlSqlBaseWalker.java:3022)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:2841)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:2719)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:513)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:371)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:201)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:151)
at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:189)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:130)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:83)
at org.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:427)
at org.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:884)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:834)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
at com.invidex.videolinx.server.query.QueryAction.execute(QueryAction.java:40)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:615)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:688)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:427)
at org.mortbay.jetty.servlet.WebApplicationHandler.dispatch(WebApplicationHandler.java:496)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:569)
at org.mortbay.http.HttpContext.handle(HttpContext.java:1482)
at org.mortbay.jetty.servlet.WebApplicationContext.handle(WebApplicationContext.java:624)
at org.mortbay.http.HttpContext.handle(HttpContext.java:1434)
at org.mortbay.http.HttpServer.service(HttpServer.java:896)
at org.jboss.jetty.Jetty.service(Jetty.java:454)
at org.mortbay.http.HttpConnection.service(HttpConnection.java:814)
at org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:981)
at org.mortbay.http.HttpConnection.handle(HttpConnection.java:831)
at org.mortbay.http.SocketListener.handleConnection(SocketListener.java:244)
at org.mortbay.util.ThreadedServer.handle(ThreadedServer.java:366)
at org.mortbay.util.ThreadPool$PoolThread.run(ThreadPool.java:534)