-->
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.  [ 9 posts ] 
Author Message
 Post subject: Help to complete my one-to-many association
PostPosted: Tue Aug 16, 2005 4:07 am 
Beginner
Beginner

Joined: Tue Aug 16, 2005 3:58 am
Posts: 40
Location: Singapore
Hi Friends,
I have been struggling to get through one-to-many association for my simple case of associating User with Qualification(s).

I have overridden hashCode and equals methods and my mapping looks as below.

<hibernate-mapping package="dto.user">
<class name="User" table="user">
<id
column="userid"
name="userid"
type="string"
>
<generator class="assigned" />
</id>

. . . . . . .

<set name="qualifications"
cascade="all-delete-orphan"
>
<key column="userid" />
<one-to-many class="Qualification" />
</set>

<many-to-one name="address" class="Address"
column="addressid"
cascade="all"
/>
</class> </hibernate-mapping>


My Qualification.hbm.xml is:

<hibernate-mapping package="dto.user">
<class name="Qualification" table="qualification">
<id
column="qualificationid"
name="qualificationid"
type="integer"
>
<generator class="native" />
</id>
. . . . .

<many-to-one
class="User"
name="user"
not-null="true"
>
<column name="userid" />
</many-to-one>
</class>
</hibernate-mapping>

I have declared a Set in my User object with both getter and setter methods.

I want to have User -> Qualifications association (one-to-many) so that I would be able to get all Qualifications of a particular user.

Please throw some light on this energy sapping problem.

Thanks and Regards,
Aru K


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 16, 2005 8:23 am 
Expert
Expert

Joined: Sat Oct 25, 2003 8:49 am
Posts: 490
Location: Vrhnika, Slovenia
And what's the problem?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 16, 2005 12:22 pm 
Newbie

Joined: Wed Dec 08, 2004 12:28 pm
Posts: 8
I think that you forgot a very impotant thing:

the description of your problem


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 16, 2005 8:42 pm 
Beginner
Beginner

Joined: Tue Aug 16, 2005 3:58 am
Posts: 40
Location: Singapore
Im very sorry for not stating my problem. Sorry again friends!!!!

Problem
=======
I couldnt have my sessionFactory created using these hbm files. I get no exception when I use the following code, and I get no Factory too. ie,

try{
Configuration cfg=new Configuration();
System.out.println("About to build session factory....");
factory=cfg.configure().buildSessionFactory(); //// this line is not executed or even throws exception as would normally if something went wrong

System.out.println("Session Factory is :"+factory);
if(factory!=null)
{
getServletContext().setAttribute("FACTORY",factory);
System.out.println("Session factory is kept in application context (NEW STYLE-WORKING WELL)");
}
}catch(Exception e)
{
System.out.println("EXCEPTION while trying to store in application context :"+e);
}


In this code, I get no exception as well as dont get Session factory too. My program doesnt throw even an exception. Once it printed 'About to build session factory.. it ignores the rest.

But if I remove the <set > tag from User.hbm.xml file, it creates sessionFactory well.

Please help.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 17, 2005 3:13 am 
Expert
Expert

Joined: Sat Oct 25, 2003 8:49 am
Posts: 490
Location: Vrhnika, Slovenia
There is no way you get null as factory after this code. It should definitely 'say' (throw) something.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 17, 2005 3:17 am 
Beginner
Beginner

Joined: Tue Aug 16, 2005 3:58 am
Posts: 40
Location: Singapore
Thanks for your comment.

But it is 100% sure that it doesnt throw any exception.

I actually use this code in a servlet's (which gets initialized when appln starts up) init() method.

I even dont get null. Its really frustrating... Plz help.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 17, 2005 3:21 am 
Expert
Expert

Joined: Sat Oct 25, 2003 8:49 am
Posts: 490
Location: Vrhnika, Slovenia
So if you don't get null, what do you get then??


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 17, 2005 3:27 am 
Beginner
Beginner

Joined: Tue Aug 16, 2005 3:58 am
Posts: 40
Location: Singapore
As I have said previously, execution gets break and ignores the code starting from

factory=cfg.configure().buildSessionFactory(); //// this line is not executed or even throws exception as would normally if something went wrong


That is, system doesnt execute or does something when executing this line without causing an exception. Rest of lines are simply ignored.

To make sure that it really parses my hbm files, I did remove <set> tag from User.hbm.xml file. Then it went on to create factory and saving it in appln. context for my use.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 17, 2005 3:36 am 
Expert
Expert

Joined: Sat Oct 25, 2003 8:49 am
Posts: 490
Location: Vrhnika, Slovenia
Try catching Throwable.


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