-->
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.  [ 5 posts ] 
Author Message
 Post subject: Newabie: Problems with Mapping a one-to-many association
PostPosted: Tue May 15, 2007 2:25 pm 
Newbie

Joined: Tue May 15, 2007 12:23 pm
Posts: 5
Hi Everybody!

I am a newabie to Hibernate and have my first greater problem with a many-to-one association on the same object :

Following Situation:
I have a abstract superclass "Status", and two subclasses "CustomerStatus" and "ReservationStatus".The abstract superclass inherits a list "SuccStatus" in which status objects are being held, which are the successor stati. That means that one status object has a list of its successor stati as an list object.

The Status Class:

public abstract class Status extends ID implements java.io.Serializable {


// Fields

private String name;
private String typ;
private Set succStatus;
private String iconName;

// Constructors

/** default constructor */
public Status() {
}



// Property accessors

...


public Set getSuccStatus() {
return succStatus;
}

public void setSuccStatus(Set succStatus) {
this.succStatus = succStatus;
}

...
}



the Hibernate Mapping (iki use the Table per ClassHierachie Pattern):

<hibernate-mapping>
<class name="hostelStar.model.Status" table="status" catalog="hostelstar">
<id name="id" type="java.lang.Long">
<column name="ID" />
<generator class="increment" />
</id>
<discriminator column="TYP" type="string"/>

...

<set name="succStatus" table="status_status" lazy="true" cascade="save-update">
<key column="ID" />
<many-to-many class="hostelStar.model.Status" column="SUCC_STATUS_ID"/>
</set>

<subclass name="hostelStar.model.ReservationStatus" discriminator-value="ResStatus">
...
</subclass>
<subclass name="hostelStar.model.CustomerStatus" discriminator-value="CustStatus">
...
</subclass>
</class>
</hibernate-mapping>


In the DB i have i single table which maps the successor relation; its a "mapping table"

ID is the id from the class
SUCC_STATUS_ID is the ID of the Successor Status

ID | SUCC_STATUS_ID

1 2
1 3
2 4

end so on

When i retrieve a status object from the db there are no entries in the list, although der are entries in the DB. I have tried several versions of mapping the set of successor stati but no one has filled the list.

What is wrong on my mapping file!

Thanks a lot for your support!


Top
 Profile  
 
 Post subject: Can nobody help me?
PostPosted: Fri May 18, 2007 3:12 am 
Newbie

Joined: Tue May 15, 2007 12:23 pm
Posts: 5
Please, if anyone has a glue how to solve the problem - post it!

My program is part of my master thesis, so its very important for me.

THX


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 18, 2007 7:41 am 
Senior
Senior

Joined: Thu May 17, 2007 2:31 am
Posts: 194
Location: Sri Lanka
Hi

Can you send more informations. like table structure.

Amila


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 22, 2007 11:19 am 
Newbie

Joined: Tue May 15, 2007 12:23 pm
Posts: 5
Hi Amila!

Thx for your reply, but I have already found the solution.

It's very simple, but I didn't no it before.

The List with the succStatus is only loaded from the DB when you start working with it.

what a problem ;-) ...


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 23, 2007 12:52 am 
Senior
Senior

Joined: Thu May 17, 2007 2:31 am
Posts: 194
Location: Sri Lanka
Hi

<set name="succStatus" table="status_status" lazy="true" cascade="save-update">
<key column="ID" />
<many-to-many class="hostelStar.model.Status" column="SUCC_STATUS_ID"/>
</set>


lazy="true" means all collections will load when the time they actually used.

Amila

(Don't forget to rate if it helps)


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