-->
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.  [ 8 posts ] 
Author Message
 Post subject: Query mapped to wrong table with one table per subclass
PostPosted: Thu Mar 11, 2004 11:21 am 
Newbie

Joined: Thu Nov 13, 2003 12:03 pm
Posts: 18
Location: France
Using hibernate 2.0.3

I have a mapping with a one table per sublass strategy.

Code:
<hibernate-mapping>
    <class
        name="com.fnac.customer.mailfollowup.bean.AbstractMailParam"
        table="COMMON_MAIL_PARAM"
        dynamic-update="false"
        dynamic-insert="false"
    >

        <id
            name="id"
            column="COMMON_MAIL_PARAM_ID"
            type="java.lang.Long"
            unsaved-value="null"
        >
            <generator class="sequence">
                <param name="sequence">SEQ_DEFAULT</param>
            </generator>
        </id>

        <version
            name="versionNumber"
            type="int"
            column="VERSION_NUMBER"
        />

 
        <many-to-one
            name="thePartner"
            class="com.fnac.customer.mailfollowup.bean.admin.Partner"
            cascade="none"
            outer-join="auto"
            update="true"
            insert="true"
            column="PARTNER_ID"
        />

        <joined-subclass
            name="com.fnac.customer.mailfollowup.bean.MailParam"
            table="MAIL_PARAM"
            dynamic-update="false"
            dynamic-insert="false"
        >
        <key
            column="COMMON_MAIL_PARAM_ID"
        />

        <many-to-one
            name="mailProcess"
            class="com.fnac.customer.mailfollowup.bean.MailProcess"
            cascade="none"
            outer-join="auto"
            update="true"
            insert="true"
            column="PROCESS_ID"
        />

        </joined-subclass>

    </class>
    <class
        name="com.fnac.customer.mailfollowup.bean.AbstractProcess"
        table="PROCESS"
        dynamic-update="false"
        dynamic-insert="false"
        discriminator-value="null"
    >

        <id
            name="id"
            column="PROCESS_ID"
            type="java.lang.Long"
            unsaved-value="null"
        >
            <generator class="sequence">
                <param name="sequence">SEQ_PROCESS</param>
            </generator>
        </id>

        <discriminator
            column="PROCESS_TYPE"
            type="java.lang.Integer"
        />

        <version
            name="versionNumber"
            type="int"
            column="VERSION_NUMBER"
        />


        </subclass>
        <subclass
            name="com.fnac.customer.mailfollowup.bean.MailProcess"
            dynamic-update="false"
            dynamic-insert="false"
            discriminator-value="1"
        >

        <many-to-one
            name="mailParam"
            class="com.fnac.customer.mailfollowup.bean.MailParam"
            cascade="none"
            outer-join="auto"
            update="true"
            insert="true"
            column="PARAM_ID"
        />

        </subclass>

    </class>
    <class
        name="com.fnac.customer.mailfollowup.bean.admin.Partner"
        table="PARTNER"
        dynamic-update="false"
        dynamic-insert="false"
    >

        <id
            name="id"
            column="PARTNER_ID"
            type="java.lang.Long"
            unsaved-value="null"
        >
            <generator class="sequence">
                <param name="sequence">SEQ_DEFAULT</param>
            </generator>
        </id>

        <version
            name="versionNumber"
            type="int"
            column="VERSION_NUMBER"
        />
        <property
            name="name"
            type="java.lang.String"
            update="true"
            insert="true"
            column="NAME"
        />

    </class>
</hibernate-mapping>



Then I do a simple query trying:
Code:
session.find( "select process.mailParam.thePartner.name"
                + " from MailProcess as process ");


Then hibernate tries to get thePartner property from the subclass and not the parent class. As a consequence I get an SQL Exception.
How come it doesn't get the property from the parent class ?
Is ther any workaround for that ?
Thanks.

Code:
java.sql.SQLException: ORA-00904: "MAILPARA1__1"."PARTNER_ID" : identificateur non valide

   at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:180)
   at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:208)
   at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:543)
   at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1451)
   at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteDescribe(TTC7Protocol.java:651)
   at oracle.jdbc.driver.OracleStatement.doExecuteQuery(OracleStatement.java:2117)
   at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2331)
   at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:422)
   at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:366)
   at net.sf.hibernate.impl.BatcherImpl.getResultSet(BatcherImpl.java:71)
   at net.sf.hibernate.loader.Loader.getResultSet(Loader.java:551)
   at net.sf.hibernate.loader.Loader.doFind(Loader.java:140)
   at net.sf.hibernate.loader.Loader.find(Loader.java:620)
   at net.sf.hibernate.hql.QueryTranslator.find(QueryTranslator.java:928)
   at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1343)
   ... 29 more



Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 11, 2004 11:35 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
in hibernate.hbm.xml, use show-sql = true, then trace the generated SQL, there might be an error in one of the column name


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 11, 2004 11:39 am 
Newbie

Joined: Thu Nov 13, 2003 12:03 pm
Posts: 18
Location: France
I did, but it's true that I didn't post it. Here it is ;-)
Code:
Hibernate: select partner2_.NAME as x0_0_ from PROCESS mailproc0_, MAIL_PARAM mailpara1_, PARTNER partner2_ where mailproc0_.PROCESS_TYPE=1 and mailproc0_.PARAM_ID=mailpara1_.COMMON_MAIL_PARAM_ID and mailpara1__1.PARTNER_ID=partner2_.PARTNER_ID



As you can see, it doesn't select the parent class table where is the partner property.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 11, 2004 12:25 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
Are you sure you're in a limitation?
see

http://www.hibernate.org/hib_docs/refer ... ritance-s2


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 11, 2004 12:43 pm 
Newbie

Joined: Thu Nov 13, 2003 12:03 pm
Posts: 18
Location: France
I am using the table per sublass strategy.
I don't see any limitations in the doc for this strategy.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 11, 2004 12:53 pm 
Newbie

Joined: Thu Nov 13, 2003 12:03 pm
Posts: 18
Location: France
A workaround is to hardcode the join
Code:
session.find(select abstractParam.thePartner.name from Mailprocess as process, AbstractParam as abstractParam where process.mailParam.id = abstractParam.id)

I feel although that this join shoud be done by hibernate.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 11, 2004 1:09 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
i think we're going to have a detailled explanation by the hibernate team

there must be a reason why it's working like this


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 12, 2004 6:34 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Hum sounds like Hibernate forgot COMMON_MAIL_PARAM mailpara1__1 in the from clause. I'll ckeck that deeper

_________________
Emmanuel


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