-->
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.  [ 1 post ] 
Author Message
 Post subject: Executing Native SQL
PostPosted: Wed Sep 29, 2004 2:24 pm 
Newbie

Joined: Tue Sep 21, 2004 6:06 am
Posts: 1
Location: London
Hibernate version: 2.1.3 and 2.1.6

Name and version of the database: Oracle 9i

The issue:


I have seen a few more complex scenarios than the issue i am facing, but i could not find the posting of a solution in the instance of invalid column name SQLExceptions occuring when trying to retrieve a list of organisations filtering upon the columns I wish to see.


The following SQL returns me all the desired organisations:

String sql = "select {org.*} from organisation org where org.og_id = 7834";

List organisations = this.getHibernateSession()
.createSQLQuery(sql, "org", OrganisationDO.class).list();


However - when i try a similar query but name the individual columns i wish to recieve as follows:

String sql = "select og.og_name {org.name} from organisation og where og.og_id = 7834";

List organisations = this.getHibernateSession()
.createSQLQuery(sql, "org", OrganisationDO.class).list();

I get an SQLException with the message Invalid column name

The SQL which gets generated is as follows:
select og.og_name OG_NAME0_ from organisation og where og.og_id = 7834

On closer inspection i cannot understand why the OG_NAME0_ column is getting generated where the property within the OrganisationDO class is simply name. None-the-less the sql statement executes fine within an SQL editor window and i cannot see how I have misnamed a column.
I get the same issue in boh hibernate 2.1.3 and 2.1.6.


Any assitance greatly appreciated.


Mapping documents:

<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
<class
name="com.bupa.infrastructure.providerlocator.appservice.dataobject.OrganisationDO"
table="ORGANISATION"
dynamic-update="false"
dynamic-insert="false"
mutable="false"
>

<id
name="id"
column="OG_ID"
type="int"
>
<generator class="increment">
</generator>
</id>

<set
name="openingHours"
lazy="true"
inverse="false"
cascade="none"
sort="unsorted"
>

<key
column="OH_ID"
>
</key>

<one-to-many
class="com.bupa.infrastructure.providerlocator.appservice.dataobject.OpeningHoursDO"
/>
</set>

<set
name="activities"
table="ORGANISATIONAL_ACTIVITY_CK"
lazy="true"
inverse="false"
cascade="none"
sort="unsorted"
>

<key
column="OG_ID"
>
</key>

<many-to-many
class="com.bupa.infrastructure.providerlocator.appservice.dataobject.ActivityDO"
column="AC_ID"
outer-join="auto"
/>

</set>

<property
name="contactEmail"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="OG_CONTACT_EMAIL"
/>

<property
name="description"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="OG_DESCRIPTION"
/>

<property
name="directions"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="OG_DIRECTIONS"
/>

<property
name="fax"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="OG_FAX"
/>

<property
name="furtherInformation"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="OG_FURTHER_INFO"
/>

<property
name="grade"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="OG_GRADE"
/>

<set
name="infos"
lazy="true"
inverse="false"
cascade="none"
sort="unsorted"
>

<key
column="OI_ID"
>
</key>

<one-to-many
class="com.bupa.infrastructure.providerlocator.appservice.dataobject.InfoDO"
/>
</set>

<many-to-one
name="locationDO"
class="com.bupa.infrastructure.providerlocator.appservice.dataobject.LocationDO"
cascade="none"
outer-join="auto"
update="true"
insert="true"
access="property"
column="LC_ID"
/>

<property
name="logoURL"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="OG_LOGO_URL"
/>

<property
name="name"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="OG_NAME"
/>

<property
name="url"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="OG_URL"
/>

<many-to-one
name="organisationTypeDO"
class="com.bupa.infrastructure.providerlocator.appservice.dataobject.OrganisationTypeDO"
cascade="none"
outer-join="false"
update="false"
insert="false"
access="property"
column="OT_TYPE_ID"
/>

<property
name="photoUrl"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="OG_PHOTO_URL"
/>

<property
name="telephone"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="OG_TELEPHONE"
/>

<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-OrganisationDO.xml
containing the additional properties and place it in your merge dir.
-->

</class>

</hibernate-mapping>


Full stack trace of any exception that occurs:


The generated SQL (show_sql=true):


[/u]

_________________
CK


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.