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.  [ 3 posts ] 
Author Message
 Post subject: Is there something wrong with my mapping?
PostPosted: Thu Apr 24, 2008 8:40 am 
Beginner
Beginner

Joined: Sun Nov 18, 2007 10:39 am
Posts: 46
Location: Liverpool, England
In the mapping below you'll notice I'm mapping a column "Service" in the database table to a column "Name" in the class. When I execute the query below though, the "ORDER BY Name" gets passed straight to the SQL, rather than being translated to "ORDER BY Service"

Have I done something wrong somewhere?

Kev

Hibernate version:
1.2.1GA
Mapping documents:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="Domain" assembly="Saturn.DAO">
<class name="Saturn.DAO.Domain.Service, Saturn.DAO" table="Services" >
    <composite-id name="ID" class="Saturn.DAO.Types.DBKey">
      <key-property name="Prefix"/>
      <key-property name="ID"/>
    </composite-id>
    <property name="Name" column="Service" type="String" />
    <property name="IsDepot" column="Depot" type="Boolean" />
    <property name="IsQuay" column="Quay" type="Boolean" />
    <property name="IsAgent" column="Agent" type="Boolean" />
    <property name="IsSizeDependent" column="SizeDependent" type="Boolean" />
    <property name="IsContainerInspection" column="ContainerInspection" type="Boolean" />
    <property name="CantDelete" type="Boolean" />
</class>
</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():
Code:
session.CreateQuery("FROM Service ORDER BY Name").List(Of Domain.Service)()


Name and version of the database you are using:
MS SQL Server 2005
The generated SQL (show_sql=true):
Code:
select service0_.Prefix as Prefix3_, service0_.ID as ID3_, service0_.Service as Service3_, service0_.Depot as Depot3_, service0_.Quay as Quay3_, service0_.Agent as Agent3_, service0_.SizeDependent as SizeDepe7_3_, service0_.ContainerInspection as Containe8_3_, service0_.CantDelete as CantDelete3_
from Services service0_
order by  Name


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 25, 2008 5:02 pm 
Expert
Expert

Joined: Fri Oct 28, 2005 5:38 pm
Posts: 390
Location: Cedarburg, WI
You need to use aliases in your query. Try this:
Code:
FROM Service AS Service
ORDER BY Service.Name


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 28, 2008 5:57 am 
Beginner
Beginner

Joined: Sun Nov 18, 2007 10:39 am
Posts: 46
Location: Liverpool, England
Nels_P_Olsen wrote:
You need to use aliases in your query. Try this:
Code:
FROM Service AS Service
ORDER BY Service.Name


D'Oh. Of course - thanks for the reminder


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