Hibernate version: 3.0.1
Mapping documents:
Template.hbm.xmlCode:
<hibernate-mapping package="model.message">
<class name="Template" table="template" discriminator-value="0">
<id name="id" column="id" type="long" unsaved-value="-1">
<generator class="native">
<param name="sequence">template_seq</param>
</generator>
</id>
<discriminator column="discriminator" type="integer"/>
<version name="version" column="version" type="integer" unsaved-value="negative"/>
<property name="name" column="name" type="string"/>
<subclass name="model.message.email.EmailTemplate" discriminator-value="1">
<set name="attachments" inverse="true" cascade="all-delete-orphan">
<key column="email_template"/><!-- PROBLEM -->
<one-to-many class="message.email.Attachment"/>
</set>
<list name="emailTemplateParts" inverse="true" cascade="all-delete-orphan">
<key column="email_template" not-null="true" update="false"/>
<index column="list_index" type="integer"/>
<one-to-many class="model.message.email.EmailTemplatePart"/>
</list>
<join table="email_template">
<key column="id"/>
<property name="from" column="from_addresses" type="string"/>
<property name="to" column="to_addresses" type="string"/>
<property name="cc" column="cc_addresses" type="string"/>
<property name="bcc" column="bcc_addresses" type="string"/>
<property name="subject" column="subject" type="string"/>
</join>
<subclass name="model.message.email.NewsletterTemplate" discriminator-value="2">
<join table="newsletter_template">
<key column="id"/>
<many-to-one name="newsletter" column="newsletter" class="model.newsletter.Newsletter"/>
</join>
</subclass>
</subclass>
</class>
</hibernate-mapping>
Document.hbm.xmlCode:
<hibernate-mapping package="model.document">
<class name="Document" table="document" discriminator-value="0">
<id name="id" column="id" type="long" unsaved-value="-1">
<generator class="native">
<param name="sequence">document_seq</param>
</generator>
</id>
<discriminator column="discriminator" type="integer"/>
<version name="version" column="version" type="integer" unsaved-value="negative"/>
<many-to-one name="input" column="input" class="model.source.Input" outer-join="false" lazy="true"/>
<property name="ssn" column="ssn" type="string"/>
<property name="name" column="name" type="string" not-null="true"/>
<property name="created" column="created" type="timestamp"/>
<property name="viewed" column="viewed" type="timestamp"/>
<property name="contentType" column="content_type" type="string" not-null="true"/>
<property name="contentLength" column="content_length" type="long"/>
<many-to-one name="content" column="content" class="Content" lazy="true" outer-join="false" cascade="all-delete-orphan"/>
<subclass name="Garnishment" discriminator-value="1">
<join table="garnishment">
<key column="id"/>
<property name="notificationDate" column="notification_date" type="timestamp"/>
<property name="type" column="type" type="integer"/>
</join>
</subclass>
<subclass name="model.message.email.Attachment" discriminator-value="2">
<join table="attachment">
<key column="id"/>
<many-to-one name="emailTemplate" column="email_template" class="model.message.email.EmailTemplate"/><!-- PROBLEM HERE -->
<property name="contentId" column="content_id" type="string"/>
</join>
</subclass>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():Code:
session.lock( emailTemplate, LockMode.NONE );
emailTemplate.getAttachments( ).size( ); // Init the lazy collection
Full stack trace of any exception that occurs:Here is the relevant piece09/26/05 13:22:48: WARN: org.hibernate.util.JDBCExceptionReporter: http-8084-Processor23: SQL Error: 904, SQLState: 42000
09/26/05 13:22:48: ERROR: org.hibernate.util.JDBCExceptionReporter: http-8084-Processor23: ORA-00904: "ATTACHMENT0_"."EMAIL_TEMPLATE": invalid identifier
Name and version of the database you are using: Oracle 9.2.0
The generated SQL (show_sql=true):bold indicates the problemCode:
select
attachment0_.email_template as email12___, -- PROBLEM HERE
attachment0_.id as id__,
attachment0_.id as id0_,
attachment0_.version as version4_0_,
attachment0_.input as input4_0_,
attachment0_.ssn as ssn4_0_,
attachment0_.name as name4_0_,
attachment0_.created as created4_0_,
attachment0_.viewed as viewed4_0_,
attachment0_.content_type as content9_4_0_,
attachment0_.content_length as content10_4_0_,
attachment0_.content as content4_0_,
attachment0_1_.email_template as email2_6_0_,
attachment0_1_.content_id as content3_6_0_
from document attachment0_
inner join attachment attachment0_1_
on attachment0_.id=attachment0_1_.id
where attachment0_.email_template=?
I suspect that the <key> element of the "attachments" <set> in the EmailTemplate mapping assumes that the column belongs to the root table (document) alias. The problem seems to be that the <key> column refers to a column in a joined subclass table (attachment).
Is it possible to join on a column in a subclass join table? If so, what am I doing wrong?
Thanks,
- Jesse