I have a mapping between a few tables to represent a Configuration and a SettingType value stored in a separate table.
The <join> works fine using standard session lookups using the ID but when I try to use a sql-query to load the object with some custom sql it blows up when it tries to bring in the columns from the <join> relationship into the query doing the SELECT.
Do I have to specify *all* the columns in the query instead of using c.*? I hope not because I have situations with tables that contain a lot of columns which could make this difficult. Is there a way to indicate that the sql-query should ignore the <join> element and load it with a separate query like it does when I load the Configuration object with its ID?
Some of the below has been simplfied/sanitized:
Hibernate version:
3.1
Mapping documents:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.foo.Configuration"
table="configuration">
<id name="id" type="long" column="ID">
<meta attribute="scope-set">protected</meta>
<generator class="sequence">
<param name="sequence">CONFIG_ID_SEQ</param>
</generator>
</id>
<property name="description" type="string" column="DESCRIPTION" />
<property name="name" type="string" column="STRING" />
<many-to-one name="org" cascade="save-update"
class="com.foo.org.Org" column="ORG_ID" />
<join table="configurationSettings" optional="true">
<key column="CONFIGURATION_ID" />
<many-to-one name="settingsOrg" column="ORG_ID"
class="com.foo.org.Org" />
<many-to-one name="configSettingType" column="SETTING_ID"
class="com.foo.ConfigurationSettingsType" />
</join>
<sql-query name="Configuration.findById">
<![CDATA[SELECT {c.*}
FROM configuration {c}
WHERE c.id = :cid]]>
<return alias="c" class="com.foo.Configuration" />
</sql-query>
Full stack trace of any exception that occurs:java.sql.SQLException: ORA-00904: "C_1_"."SETTING_ID": invalid identifier
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:289)
at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:589)
Name and version of the database you are using:Oracle 9i
The generated SQL (show_sql=true):Hibernate: SELECT c.ID as ID39_0_, c.DESCRIPTION as DESCRIPT3_39_0_, c.NAME as NAME39_0_, c_1_.ORG_ID as ORG2_43_0_, c_1_.SETTING_ID as SETTING3_43_0_
FROM configuration c
WHERE c.id = ?
Code: