-->
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.  [ 7 posts ] 
Author Message
 Post subject: Query question
PostPosted: Fri Apr 30, 2004 6:20 pm 
Newbie

Joined: Wed Apr 28, 2004 5:22 pm
Posts: 11
Location: United States
I am trying to perform the following query:

query = session.createQuery("from Screen1HPBean screen where screen.termid = 'ABC');

//One object is found
Screen1HPBean screen = (Screen1HPBean)query.list().get(0);

//Now I can get information from ScreenqHPBean with no problem,
//but when I try to get - Set plans; it only returns one object of type //PlanBean when it should have returned 23
Set plans = screen.getPlans();
Iterator iter = plans.iterator();
while(iter.hasNext()){
LogService.log(LogService.DEBUG, "PLAN BEAN: " + ((PlanBean)iter.nex\t()).getMealPlan());
}

session.connection().commit();
session.close();
DbService.releaseConnection(con);

//the database contains 23 entries but only one is being returned.

Here is my database mapping file:

Anyhelp? Suggestions?

-------------------------------

--<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping schema="web001" package="edu.udel.dining">

<class name="edu.udel.dining.beans.Screen1HPBean" table="dining_screenbean">
<id name="id">
<column name="id" unique="true" not-null="true" sql-type="char"
length="32" />
<generator class="uuid.hex"/>
</id>
<property name="termid" type="string">
<column name="termid" length="3" not-null="true" />
</property>
<set name="plans" lazy="true">
<key column="id" />
<one-to-many class="edu.udel.dining.beans.PlanBean" />
</set>
</class>

<class name="edu.udel.dining.beans.PlanBean" table="dining_planbean">
<id name="id" column="id">
<generator class="uuid.hex"/>
</id>
<property name="mealPlan" type="string"/>
<property name="blackBoard" type="string"/>
<property name="numberOfMeals" type="string"/>
<property name="semesterAmount" type="string"/>
<property name="pointsAmount" type="string"/>
<property name="traditionalOption" type="int"/>
<property name="nonTraditionalOption" type="int"/>
<property name="allowCancellations" type="int"/>
</class>

</hibernate-mapping>
-----------------------------

Thanks in advance,
Luis


Top
 Profile  
 
 Post subject: Check your mapping
PostPosted: Fri Apr 30, 2004 7:52 pm 
Newbie

Joined: Mon Mar 01, 2004 9:49 pm
Posts: 13
I guess, you got one-to-many mapping of Screen1HPBean wrong: key column should be the column which is foreign key to dining_planbean.id not the dining_screenbean.id


Top
 Profile  
 
 Post subject: Re: Check your mapping
PostPosted: Sat May 01, 2004 2:26 pm 
Newbie

Joined: Wed Apr 28, 2004 5:22 pm
Posts: 11
Location: United States
Hi, thanks for your reply. I am not sure I understand you though. See, this is how my database looks like:

Table dining_screenbean:
ID = 1234
TERMID = 04S

Table dining_planbeann
ID = 1234
MEALPLAN = 1
BLACKBOARD = A
NUMBEROFMEALS = 12

ID = 1234
MEALPLAN = 2
BLACKBOARD = B
NUMBEROFMEALS = 13

ID = 1234
MEALPLAN = 3
BLACKBOARD = 4
NUMBEROFMEALS = 14

and so on. So, for what I see the row ID on dining_planben is foreign _key to row ID on dining_screenbean. What do you say? Perhaps you could be more specific in what you are saying so I can give it a try?

Thanks again,
Luis


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 01, 2004 2:48 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
you're mapping files are wrong, if you look at data, at unicity, the result is ok.
you have defined the unicity of dining_planbeann on id.
Your example show 3 records but they all have id = 1234, --> so for hibernate, they are all the same, hibernate is going to stop at the first.

As i can see, for dining_planbeann, the unicity is a composite-id with ID AND MEALPLAN, so just map your object correctly and it will work.


Anthony


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 01, 2004 9:21 pm 
Newbie

Joined: Wed Apr 28, 2004 5:22 pm
Posts: 11
Location: United States
could you give me an example of how to use the composite-id?

I am getting lots of errors such as, repeating column mealPlan, add insert=false, update=false. When I add the insert and update attributes, I get errors saying that I should register them..... At this point I am very lost. I was trying to follow the example from the docs (Parent and chield, but it does not seen to work....

Any help? Thanks in advance!

Luis


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 02, 2004 4:37 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
Code:
<class name="edu.udel.dining.beans.PlanBean" table="dining_planbean">
<composite-id>
        <key-property name="mealPlan" column="mealPlan"/>
        <key-many-to-one name="screen1HPBean" class="Screen1HPBean" column="id"/>
</composite-id>
<property name="blackBoard" type="string"/>
<property name="numberOfMeals" type="string"/>
<property name="semesterAmount" type="string"/>
<property name="pointsAmount" type="string"/>
<property name="traditionalOption" type="int"/>
<property name="nonTraditionalOption" type="int"/>
<property name="allowCancellations" type="int"/>
</class>


or
Code:
<class name="edu.udel.dining.beans.PlanBean" table="dining_planbean">
<composite-id>
        <key-property name="mealPlan" column="mealPlan"/>
        <key-property name="idMealPlan" column="id"/>
</composite-id>
<property name="blackBoard" type="string"/>
<property name="numberOfMeals" type="string"/>
<property name="semesterAmount" type="string"/>
<property name="pointsAmount" type="string"/>
<property name="traditionalOption" type="int"/>
<property name="nonTraditionalOption" type="int"/>
<property name="allowCancellations" type="int"/>
</class>

if you don't need the association to be bidirectionnal.

Also implements Serializable and define equals/hashcode
http://www.hibernate.org/hib_docs/refer ... lshashcode


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 02, 2004 11:19 am 
Newbie

Joined: Wed Apr 28, 2004 5:22 pm
Posts: 11
Location: United States
Nice..... now it works well.... Thanks a bunch,
Luis


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