-->
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: createSQLQuery trouble
PostPosted: Thu Oct 02, 2003 3:47 pm 
Beginner
Beginner

Joined: Tue Aug 26, 2003 9:50 am
Posts: 34
Location: Weiden Opf. / Germany
Hi there!

I'm trying to execute this (i use the arrays because the query i'm actually trying to execute is a lot longer and i cut out most of it, trying to get it to work):

List list = hibernateSession.createSQLQuery("select {currentTechnician.*} from tbTechnician as {currentTechnician}"
, new String[] {"currentTechnician"}
, new Class[] {Technician.class}).list();

and get the following execption:

net.sf.hibernate.JDBCException: SQLException occurred: The column prefix 'currentTechnician_1_' does not match with a table name or alias name used in the query.
com.jnetdirect.jsql.v: The column prefix 'currentTechnician_1_' does not match with a table name or alias name used in the query.
at com.jnetdirect.jsql.v.a(Unknown Source)
at com.jnetdirect.jsql.av.a(Unknown Source)
at com.jnetdirect.jsql.af.e(Unknown Source)
at com.jnetdirect.jsql.af.new(Unknown Source)
at com.jnetdirect.jsql.af.do(Unknown Source)
at com.jnetdirect.jsql.ap.executeQuery(Unknown Source)
at com.mchange.v2.c3p0.impl.C3P0PreparedStatement.executeQuery(C3P0PreparedStatement.java:188)
at com.mchange.v2.c3p0.impl.C3P0PooledConnection$2.executeQuery(C3P0PooledConnection.java:473)
at net.sf.hibernate.impl.BatcherImpl.getResultSet(BatcherImpl.java:81)
at net.sf.hibernate.loader.Loader.getResultSet(Loader.java:629)
at net.sf.hibernate.loader.Loader.doResultSet(Loader.java:171)
at net.sf.hibernate.loader.Loader.doFind(Loader.java:113)
at net.sf.hibernate.loader.Loader.find(Loader.java:736)
at net.sf.hibernate.loader.SQLLoader.list(SQLLoader.java:69)
at net.sf.hibernate.impl.SessionImpl.findBySQL(SessionImpl.java:3612)
at net.sf.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:47)
at de.sag.qsee.taskscheduler.business.AppointmentManager.getFreeTechnicianAppointments(AppointmentManager.java:455)


i used the sql server profiler and found out the hibernate creates the following sql statement, which is obviously wrong:

select currentTechnician.technicianActorID as technicianActorID0_
, currentTechnician.technicianNo as technici2_3_0_
, currentTechnician.shortMark as shortMark3_0_
, currentTechnician.mobilePhone as mobilePh4_3_0_
, currentTechnician.birthday as birthday3_0_
, currentTechnician.collectionAccount as collecti6_3_0_
, currentTechnician.carNumber as carNumber3_0_
, currentTechnician_1_.status as status1_0_
, currentTechnician_1_.lastName as lastName1_0_
, currentTechnician_1_.firstName as firstName1_0_
, currentTechnician_1_.userName as userName1_0_
, currentTechnician_1_.loginName as loginName1_0_
, currentTechnician_1_.password as password1_0_
, currentTechnician_1_.numberFailedLogins as numberFa8_1_0_
, currentTechnician_1_.languageID as languageID1_0_
, currentTechnician_1_.countryID as countryID1_0_
, currentTechnician_1_.tbRoleID as tbRoleID1_0_
from tbTechnician as currentTechnician


i guess it's because Technician inherits from User which is stored in a different table in the db. The columns referenced with currentTechnician_1_ are the ones from the user.


the mapping is as follows:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="de.sag.qsee.masterdata.data.Actor" table="tbActor">
<!-- PK -->
<id name="actorID" column="actorID" type="int" unsaved-value="0">
<generator class="identity"/>
</id>
<!-- subclasses -->
<!-- User class -->
<joined-subclass name="de.sag.qsee.masterdata.userdata.data.User" table="tbUser">
<key column="userActorID"/>
<property name="status" column="status" type="int"/>
<property name="lastName" column="lastName" type="string"/>
<property name="firstName" column="firstName" type="string"/>
<property name="userName" column="userName" type="string"/>
<property name="loginName" column="loginName" type="string"/>
<property name="password" column="password" type="string"/>
<property name="numberFailedLogins" column="numberFailedLogins" type="int"/>
<many-to-one name="language" column="languageID" not-null="true"/>
<many-to-one name="country" column="countryID" not-null="true"/>
<many-to-one name="currentRole" column="tbRoleID" not-null="false"/>
<bag name="roles" table="tbUser2Role" lazy="true">
<key column="userActorID"/>
<many-to-many class="de.sag.qsee.masterdata.userdata.data.Role" column="tbRoleID"/>
</bag>
<!-- subclasses -->
<!-- Technician class -->
<joined-subclass name="de.sag.qsee.masterdata.userdata.data.Technician" table="tbTechnician">
<key column="technicianActorID"/>
<!-- local attributes -->
<property name="technicianNo" column="technicianNo" type="string"/>
<property name="shortMark" column="shortMark" type="string"/>
<property name="mobilePhone" column="mobilePhone" type="string"/>
<property name="birthday" column="birthday" type="date"/>
<property name="collectionAccount" column="collectionAccount" type="string"/>
<property name="carNumber" column="carNumber" type="string"/>
<!-- one to many -->
<bag name="repairTypes" table="tbTechnicianQualification" lazy="true">
<key column="technicianActorID"/>
<many-to-many class="de.sag.qsee.masterdata.oemdata.data.RepairType" column="tbRepairTypeID"/>
</bag>
<bag name="addresses" table="tbAddress" inverse="true" lazy="true" cascade="all">
<key column="actorID"/>
<one-to-many class="de.sag.qsee.masterdata.data.Address"/>
</bag>
<bag name="workingDays" table="tbTechnicianWorkingDays" inverse="true" lazy="true">
<key column="technicianActorID"/>
<one-to-many class="de.sag.qsee.masterdata.userdata.data.TechnicianWorkingDay"/>
</bag>
<bag name="appointments" table="tbTechnicianAppointmentSlots" inverse="true" lazy="true">
<key column="technicianActorID"/>
<one-to-many class="de.sag.qsee.taskscheduler.data.TechnicianAppointmentSlot"/>
</bag>
</joined-subclass>
</joined-subclass>
</class>
</hibernate-mapping>


For everything else the mapping works fine, we're using it excessivly. Just the createSQLQuery won't work.

kind regards,

Torsten Liebscher


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 02, 2003 4:11 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Max, what are we doing about joined-subclass support?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 04, 2003 11:38 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
As mentioned in the docs, when using createSQLQuery it is the responsibility of the user to provide ALL properties for an object - including possible superclasses and subclasses....note: subclasses properties is only needed if hibernate discovers that your result contain a subclass.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 04, 2003 11:39 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
...and if i understand correctly - the user just need to make the join by them selves....createSQLQueries' are for "hardcore" people who like to write SQL ;)

_________________
Max
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.  [ 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.