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: joined-subclass ERROR: relation "xy" does not exis
PostPosted: Wed Feb 01, 2006 11:27 am 
Expert
Expert

Joined: Tue Nov 23, 2004 7:00 pm
Posts: 570
Location: mostly Frankfurt Germany
Mapping a class hierarchy with joined-subclass does not allow the following query. The same query works as expected when I use subclass mapping or subclass in combination with join.
Is there another expression possible to circumvent this problem?
Is this a bug or missing feature?

Regards Sebastian

Code:
session.createQuery(
            "from Internetshop i where   i.paymentMethods.class = CreditCardPayment)")
            .list();

Hibernate version:3.1 and 3.1.2
Database: PostgreSql 8.1
Mapping documents:
Code:
<hibernate-mapping package="de.laliluna.example8">
  <class name="PaymentMethod" table="tpayment">
    <id name="id">
      <!--  postgreSQL -->
      <generator class="sequence">
        <param name="sequence">tpayment_id_seq</param>

      </generator>
    </id>
    <property name="name" type="string"></property>
    <joined-subclass name="CreditCardPayment" table="tcreditcardpayment">
      <key column="payment_id"></key>
      <property name="creditCardNumber" type="string" column="creditcardnumber"></property>
    </joined-subclass>
    <joined-subclass name="CashPayment" table="tcashpayment">
      <key column="payment_id"></key>
      <property name="bankAccount" type="string" column="bankaccount"></property>
    </joined-subclass>
  </class>
</hibernate-mapping>
<hibernate-mapping package="de.laliluna.example8">
  <class name="Internetshop" table="tinternetshop">
    <id name="id">
    <!-- PostgreSQL -->
      <generator class="sequence">
        <param name="sequence">tinternetshop_id_seq</param>
      </generator>
    </id>
    <property name="name" type="string"></property>
    <set name="paymentMethods" table="shop_paymentmethod">
      <key column="shop_id"></key>
      <many-to-many class="PaymentMethod">
        <column name="payment_id"></column>
      </many-to-many>
    </set>
  </class>
</hibernate-mapping>



Full stack trace of any exception that occurs:
Code:
Caused by: org.postgresql.util.PSQLException: ERROR: relation "paymentmet2_1_" does not exist
   at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:1512)
   at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1297)
   at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:188)
   at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:430)
   at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:346)
   at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:250)
   at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:139)
   at org.hibernate.loader.Loader.getResultSet(Loader.java:1669)
   at org.hibernate.loader.Loader.doQuery(Loader.java:662)
   at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
   at org.hibernate.loader.Loader.doList(Loader.java:2145)


The generated SQL (show_sql=true):
Code:
select internetsh0_.id as id41_, internetsh0_.name as name41_ from tinternetshop internetsh0_, shop_paymentmethod paymentmet1_, tpayment paymentmet2_ where internetsh0_.id=paymentmet1_.shop_id and paymentmet1_.payment_id=paymentmet2_.id and case when paymentmet2_1_.payment_id is not null then 1 when paymentmet2_2_.payment_id is not null then 2 when paymentmet2_.id is not null then 0 end=1

_________________
Best Regards
Sebastian
---
Training for Hibernate and Java Persistence
Tutorials for Hibernate, Spring, EJB, JSF...
eBook: Hibernate 3 - DeveloperGuide
Paper book: Hibernate 3 - Das Praxisbuch
http://www.laliluna.de


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 01, 2006 3:40 pm 
Expert
Expert

Joined: Tue Nov 23, 2004 7:00 pm
Posts: 570
Location: mostly Frankfurt Germany
I tried using a left join
Code:
select i from Internetshop i left join i.paymentMethods p where p.class = CreditCardPayment

This does not work with joined-subclass. But the query is far away from beeing efficient. Is this a known behaviour or a stupid mistake from Sebastian.

Code:
select internetsh0_.id as id41_, internetsh0_.name as name41_ from tinternetshop internetsh0_ left outer join shop_paymentmethod paymentmet1_ on internetsh0_.id=paymentmet1_.shop_id left outer join tpayment paymentmet2_ on paymentmet1_.payment_id=paymentmet2_.id where case when paymentmet2_1_.payment_id is not null then 1 when paymentmet2_2_.payment_id is not null then 2 when paymentmet2_.id is not null then 0 end=1


but works with
subclass combined with join table.
Code:
select musicfan0_.id as id43_0_, musicgroup2_.id as id45_1_, musicfan0_.name as name43_0_, musicgroup2_.name as name45_1_,
musicgroup2_1_.cryingGroupies as cryingGr2_46_1_, musicgroup2_2_.destroyedGuitars as destroye2_47_1_, musicgroup2_.discriminator as discrimi2_45_1_
from
tmusicfan musicfan0_
left outer join musicfan_musicgroup musicgroup1_ on musicfan0_.id=musicgroup1_.musicfan_id
left outer join tmusicgroup musicgroup2_ on musicgroup1_.musicgroup_id=musicgroup2_.id
left outer join tboygroup musicgroup2_1_ on musicgroup2_.id=musicgroup2_1_.musicgroup_id
left outer join thardrock musicgroup2_2_ on musicgroup2_.id=musicgroup2_2_.musicgroup_id,
musicfan_musicgroup musicgroup3_, tmusicgroup musicgroup4_ where musicfan0_.id=musicgroup3_.musicfan_id
and musicgroup3_.musicgroup_id=musicgroup4_.id and musicgroup4_.discriminator='hardrock' and musicgroup2_2_.destroyedGuitars>150

_________________
Best Regards
Sebastian
---
Training for Hibernate and Java Persistence
Tutorials for Hibernate, Spring, EJB, JSF...
eBook: Hibernate 3 - DeveloperGuide
Paper book: Hibernate 3 - Das Praxisbuch
http://www.laliluna.de


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 01, 2006 4:53 pm 
Expert
Expert

Joined: Tue Nov 23, 2004 7:00 pm
Posts: 570
Location: mostly Frankfurt Germany
here is at least a workaround that I found, but still I think that this is at least not a nice behaviour of Hibernate.

Regards Sebastian


Code:
select i from Internetshop i where i.paymentMethods.id in (select p.id from CreditCardPayment  p where p.creditCardNumber like '1%')

_________________
Best Regards
Sebastian
---
Training for Hibernate and Java Persistence
Tutorials for Hibernate, Spring, EJB, JSF...
eBook: Hibernate 3 - DeveloperGuide
Paper book: Hibernate 3 - Das Praxisbuch
http://www.laliluna.de


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.