-->
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.  [ 4 posts ] 
Author Message
 Post subject: Mappings and Inheritance
PostPosted: Wed Aug 11, 2004 3:44 am 
Newbie

Joined: Wed Aug 11, 2004 3:30 am
Posts: 5
Location: Oslo, norway
hibernate 2.1:

In my program I have class Order witch have two collections, payments and products.

The class Product have a subclass Sett, and will have more subclasses in time.

The mapping for the collection of payments works just fine, but the identical mapping of products does not.

The database is updatet correctly, but when retreving an order the products are not loaded, the paymentents are.

I have noticed that the sql generated by Hibernate is wery different in the two cases, when retreving the payments it is like this:
Hibernate: select payments0_.uid as uid__, payments0_.order_uid as order_uid__, payments0_.uid as uid0_, payments0_.amount as amount0_, payments0_.order_uid as order_uid0_ from Payments payments0_ where payments0_.order_uid=?

but when retreving the products it is like this:
Hibernate: select products0_.uid as uid__, products0_.order_uid as order_uid__, products0_.uid as uid2_, products0_.product_type as product_2_2_, products0_.order_date as order_date2_, products0_.prod_date as prod_date2_, products0_.production_state as producti5_2_, products0_.ordre_uid as ordre_uid2_, products0_.nof_stickers as nof_stic7_2_, products0_.nof_iron_on as nof_iron8_2_, products0_.line1 as line12_, products0_.line2 as line22_, products0_.design as design2_, order1_.uid as uid0_, order1_.order_date as order_date0_, order1_.prod_date as prod_date0_, order1_.customer as customer0_, customer2_.uid as uid1_, customer2_.country as country1_, customer2_.name as name1_, customer2_.street as street1_, customer2_.zip as zip1_, customer2_.city as city1_ from PRODUCTS products0_ left outer join ORDERS order1_ on products0_.ordre_uid=order1_.uid left outer join Customers customer2_ on order1_.customer=customer2_.uid where products0_.order_uid=?

Why is the customer involved in this query?

The Query I use to load all orders is like this:
Iterator it=session.find("from Order as order").iterator()


Mapping documents:
##Mapping for Product with subclass Sett##
<?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="no.alfaprint.data.Product" table="PRODUCTS" polymorphism="implicit"
discriminator-value="-1">
<id name="id" column="uid" type="long">
<generator class="increment"/>
</id>
<discriminator column="product_type" type="int"/>
<property name="orderdate" column="order_date" type="java.util.Date"/>
<property name="productiondate" column="prod_date" type="timestamp"/>
<property name="productionstate" column="production_state"/>

<many-to-one name="order" class="no.alfaprint.data.Order"
column="ordre_uid" not-null="true" cascade="all"/>

<subclass name="no.alfaprint.data.askeladden.Sett" discriminator-value="1">
<property name="antKlistre" column="nof_stickers"/>
<property name="antStryke" column="nof_iron_on"/>
<property name="linje1" column="line1"/>
<property name="linje2" column="line2"/>
<property name="motiv" column="design"/>
</subclass>
</class>

</hibernate-mapping>

##Mapping for Payment##
<?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="no.alfaprint.data.Payment" table="Payments">
<id name="id" column="uid" type="long">
<generator class="increment"/>
</id>
<property name="amount"/>
<many-to-one name="order" class="no.alfaprint.data.Order"
column="order_uid" not-null="true" cascade="all"/>
</class>

</hibernate-mapping>

##Mapping for Order, contains payments and products##
<?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="no.alfaprint.data.Order" table="ORDERS">
<id name="id" column="uid" type="long">
<generator class="increment"/>
</id>
<property name="orderdate" type="java.util.Date" column="order_date"/>

<many-to-one name="customer" class="no.alfaprint.data.Customer"/>

<set name="payments" inverse="true" lazy="false" cascade="all" outer-join="true">
<key column="order_uid"/>
<one-to-many class="no.alfaprint.data.Payment"/>
</set>

<set name="products" inverse="true" lazy="false" cascade="all" outer-join="true">
<key column="order_uid"/>
<one-to-many class="no.alfaprint.data.Product"/>
</set>

</class>

</hibernate-mapping>

Please help, this problem has been hanging over me for days...

Simen.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 12, 2004 3:24 pm 
Expert
Expert

Joined: Thu Jan 29, 2004 2:31 am
Posts: 362
Location: Switzerland, Bern
Try

Code:
outer-join="false"


HTH
Ernst
[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 17, 2004 10:40 am 
Newbie

Joined: Wed Aug 11, 2004 3:30 am
Posts: 5
Location: Oslo, norway
Thanks for your reply, tried it but it didnt make any difference...


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 18, 2004 10:06 am 
Newbie

Joined: Wed Aug 11, 2004 3:30 am
Posts: 5
Location: Oslo, norway
Sorry, it was a typo
I spelled order_uid as ordre_uid.


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