-->
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.  [ 2 posts ] 
Author Message
 Post subject: Hibernate Mapping Question Two entities one class
PostPosted: Sat Sep 20, 2008 4:36 pm 
Newbie

Joined: Sat Sep 20, 2008 4:21 pm
Posts: 2
I have two entities. One is a customer and other is order. Customer can have n number of orders(one to many). I have two java classes: customer and order. Customer has a list of orders.

The database implementation has one table. I have tested a sample out but for the same customer I get x number of customer objects and each have n number of objects. Is there a way of getting only one customer class back?


Hibernate mapping file for customer class:

<?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 default-cascade="none" default-access="property"
auto-import="false">
<class name="customer" table="customer" dynamic-insert="true" select-before-update="false">
<id name="customerid" column="customerid" />


<bag name="order" inverse="false">
<key column="customerid" not-null="false" />
<one-to-many class="order" />
</bag>



</class>


</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 22, 2008 6:37 am 
Regular
Regular

Joined: Wed Jun 20, 2007 1:53 am
Posts: 75
Hi,

How did you load the customer object?

there are two ways ,
1. Using Hibernate API's (session)
2. HQL query

I think you might have used HQL query (with join) to load the customer object.

So just try to load customer object using hibernate API, so it wont load customer object for each of his/her order.


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