-->
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: one-to-many
PostPosted: Thu Sep 13, 2007 4:48 pm 
Beginner
Beginner

Joined: Tue Aug 14, 2007 6:29 pm
Posts: 27
Location: chicago
I am trying to establish one-to-many mapping,

manager.hbm,
<hibernate-mapping>
<class name="Manager" table="manager" schema="public">
<id name="id" type="java.lang.Integer">
<column name="id" />
<generator class="assigned" />
</id>
<property name="managerid" type="java.lang.String">
<column name="managerid" length="10" unique="true" />
</property>
<property name="managersmgrid" type="java.lang.String">
<column name="managersmgrid" length="10" />
</property>
<property name="managerfirstname" type="java.lang.String">
<column name="managerfirstname" length="15" />
</property>
<property name="managerlastname" type="java.lang.String">
<column name="managerlastname" length="25" />
</property>
<property name="emailaddresslist1" type="java.lang.String">
<column name="emailaddresslist1" length="50" />
</property>
<property name="emailaddresslist2" type="java.lang.String">
<column name="emailaddresslist2" length="50" />
</property>
<property name="emailaddresslist3" type="java.lang.String">
<column name="emailaddresslist3" length="50" />
</property>
<set name="salesreps" >
<key>
<column name="managerid" length="10" />
</key>
<one-to-many class="Salesrep" />
</set>
</class>
</hibernate-mapping>

Salesrep.hbm

<hibernate-mapping>
<class name="Salesrep" table="salesrep" schema="public">
<id name="id" type="java.lang.Integer">
<column name="id" />
<generator class="assigned" />
</id>

<many-to-one name="commissionmodel" class="Commissionmodel" fetch="select" not-null="true">
<column name="modelid" length="10" />
</many-to-one>

<many-to-one name="manager" class="Manager" fetch="select" not-null="true">
<column name="managerid" length="10" />
</many-to-one>

<!--
<property name="modelid" type="java.lang.String">
<column name="modelid" length="10" unique="true" />
</property>
<property name="manager" type="java.lang.String">
<column name="managerid" length="10" unique="true" />
</property>
-->
<property name="salesrepid" type="java.lang.String">
<column name="salesrepid" length="10" unique="true" />
</property>
<property name="sapid" type="java.lang.String">
<column name="sapid" length="10" />
</property>
<property name="lastname" type="java.lang.String">
<column name="lastname" length="25" />
</property>
<property name="firstname" type="java.lang.String">
<column name="firstname" length="15" />
</property>
<property name="emailaddress" type="java.lang.String">
<column name="emailaddress" length="50" />
</property>
<property name="managerflag" >
<column name="managerflag" sql-type="boolean" />
</property>
<property name="merchantstore" type="java.lang.String">
<column name="merchantstore" length="1" />
</property>
<property name="createdby" type="java.lang.String">
<column name="createdby" length="10" />
</property>
<property name="createdate" type="java.util.Date">
<column name="createdate" length="29" />
</property>
<property name="changedby" type="java.lang.String">
<column name="changedby" length="10" />
</property>
<property name="changedate" type="java.util.Date">
<column name="changedate" length="29" />
</property>

</class>
</hibernate-mapping>

But I am unable to retrieve Salesrep set from manager object filled, Am i missing anything? Salesrep set is always empty.

Sundar


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 16, 2007 3:13 pm 
Beginner
Beginner

Joined: Tue Aug 16, 2005 3:44 pm
Posts: 33
Hi!

Do you see this both when getting existing managers which already have some salesreps or do you only see this when inserting new manager / salesreps object?

Do you add the salesrep to the Set with something like

Code:
manager.getSalesreps().add(myNewSalesRep)


You might turn on sql debugging to see the generated sql in case that might give you some ideas to what is gosing on here (and what is not going on :)

You might also want to add an inverse attribute to one side of the relationship, see the section "6.3.2. Bidirectional associations" on http://www.hibernate.org/hib_docs/reference/en/html/collections.html


-Kaj :)


Top
 Profile  
 
 Post subject: Is this postgres issue?
PostPosted: Mon Sep 17, 2007 3:19 pm 
Beginner
Beginner

Joined: Tue Aug 14, 2007 6:29 pm
Posts: 27
Location: chicago
I got this error when I tried to load sales rep which are already there for a given manager id.

Btw,

I noticed the following error

org.postgresql.util.PSQLException: Bad value for type int : STOREMODEL
at org.postgresql.jdbc2.AbstractJdbc2ResultSet.toInt(AbstractJdbc2ResultSet.java:2653)
at org.postgresql.jdbc2.AbstractJdbc2ResultSet.getInt(AbstractJdbc2ResultSet.java:1983)
at org.postgresql.jdbc2.AbstractJdbc2ResultSet.getInt(AbstractJdbc2ResultSet.java:2327)

when I tried to load the values associated with sales rep. I tested with postgres jdbc2 and 3 drivers. Is this a bug with postgres?

I tried with following drivers,
postgresql-8.2-504.jdbc2ee.jar
postgresql-8.2-506.jdbc2ee.jar
postgresql-8.2-506.jdbc3.jar

Thanks
Sundar


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 18, 2007 8:28 am 
Beginner
Beginner

Joined: Fri Sep 08, 2006 7:29 am
Posts: 36
Check if you are closing the session before accessing the salesrep list....

Also, I cannot see anything associated with the exception below....

Quote:
org.postgresql.util.PSQLException: Bad value for type int : STOREMODEL


I did not find Store Model in your mapping files...

Shardul


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 18, 2007 10:42 am 
Beginner
Beginner

Joined: Tue Aug 14, 2007 6:29 pm
Posts: 27
Location: chicago
STOREMODEL is the value I have in database for modelid of Commissionmodel.


Here I expected salesrep to load commissionmodel and manager objects.

Should we load the commissionmodel and manager objects explicitely into salesrep object?

I expected salesrep to load those as I mentioned the relationship as many-to-one with those objects.

Sundar


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 18, 2007 1:30 pm 
Beginner
Beginner

Joined: Fri Sep 08, 2006 7:29 am
Posts: 36
Two things....

1. Ensure that the mapping you have created is correct.
2. Ensure that the session is not closing before you call the code to load the lists(assuming u are using Lazy Loading...)

Shardul.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 20, 2007 3:29 pm 
Beginner
Beginner

Joined: Tue Aug 14, 2007 6:29 pm
Posts: 27
Location: chicago
Can anyone validate this flow. Is anything wrong with this approach?


I load on-to-many mapped data from tables and for one of the calculations using these data , I load again one-to-many data again with different set of conditions using hibernate criteria API. When I checked the values returned by second call , i am seeing wrong number of values .

For eg , one of header values it returned the cound of line items as 3 but it actually has only 2 rows.

Any help would be greatly appreciated.

Thanks
Sundar


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.