-->
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.  [ 3 posts ] 
Author Message
 Post subject: Help, Set is correctly persisted, but not loaded.
PostPosted: Tue Oct 12, 2004 5:31 pm 
Newbie

Joined: Tue Oct 12, 2004 5:04 pm
Posts: 5
Hibernate 2.1.6
JDK 1.4.2_05 / J2SDK 5
MySQL 4.1
Tomcat 5

Hi,

I've got 2 POJO's and their respective mapping files generated thru XDoclet. (see code below).

In short the relation between the POJO's is that a shoppinglist has one or more shoppinglistitems and a shoppinglistitem only belongs to one shoppinglist. The items are stored in a set in the list.
The list is also associated with a user, one user can have more than one list, a list belongs to one user. The same goes for shop and list. One shop per list, more than one list per shop.

When I create a new List and add a User, Shop and several items, open a session, start a transaction, save the list and commit the transaction and close the session, I see in my MySQL database all relevant tables updated as expected.
When I now open a session, load the list with the UUID generated previously and close the session, I see that the list POJO has the correct User and Shop associated with it, but the set of items is empty.

I'm stuck at this point and have no idea on what I'm doing wrong, so every help is appreciated.

Thanx in advance.
Iwan

=--=-=-=-=-=-=-=- Shoppinglist.java =--=-=-=-=-=-=-=-
/**
* @hibernate.class table="Shoppinglist"
*
* AbstractPersisitenObject has an id, which is a string, and also defines
* equals, compareTo and hashCode
*/
class Shoppinglist extends AbstractPersistentObject
{
/**
* @hibernate.id generator-class="uuid.string"
*/
public String getId()
{
return super.getId();
}

private Set items;
private User user;
private Shop shop;

/** Creates a new instance of Shoppinglist */
public Shoppinglist()
{
}

/**
* @hibernate.set lazy="false" cascade="all-delete-orphan" inverse="true" outer-join="false"
* @hibernate.collection-one-to-many class="com.softech.shopping.model.ShoppinglistItem"
* @hibernate.collection-key column="shoppinglist"
*/
public Set getItems()
{
return items;
}

public void setItems(Set items)
{
this.items = items;
}

public void addItem(ShoppinglistItem item)
{
items.add(item);
}

public void removeItem(ShoppinglistItem item)
{
items.remove(item);
}

/**
* @hibernate.many-to-one
*/
public User getUser()
{
return user;
}

public void setUser(User user)
{
this.user = user;
}

/**
* @hibernate.many-to-one
*/
public Shop getShop()
{
return shop;
}

public void setShop(Shop shop)
{
this.shop = shop;
}
}
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-
=--=-=-=-=-=-=-=- ShoppinglistItem.java =--=-=-=-=-=-=-=-
/**
* @hibernate.class table="ShoppinglistItem"
*/
class ShoppinglistItem extends AbstractPersistentObject
{
/**
* @hibernate.id generator-class="uuid.string"
*/
public String getId()
{
return super.getId();
}

private Shop shop;
private Article article;
private double amount;
private Shoppinglist shoppinglist;

/** Creates a new instance of ShoppingListItem */
public ShoppinglistItem()
{
}

/**
* @hibernate.many-to-one
*/
public Shop getShop()
{
return shop;
}

public void setShop(Shop shop)
{
this.shop = shop;
}

/**
* @hibernate.many-to-one
*/
public Article getArticle()
{
return article;
}

public void setArticle(Article article)
{
this.article = article;
}

/**
* @hibernate.property
*/
public double getAmount()
{
return amount;
}

public void setAmount(double amount)
{
this.amount = amount;
}

/**
* @hibernate.many-to-one
*/
public Shoppinglist getShoppinglist()
{
return shoppinglist;
}

public void setShoppinglist(Shoppinglist list)
{
this.shoppinglist = list;
}
}
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-
=--=-=-=-=-=-=-=- Shoppinglist.hbm.xml -=-=-=-=-=-=-=-=-=-=-=
<?xml version="1.0"?>

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

<hibernate-mapping>
<class
name="com.softech.shopping.model.Shoppinglist"
table="Shoppinglist"
dynamic-update="false"
dynamic-insert="false"
>

<id
name="id"
column="id"
type="java.lang.String"
>
<generator class="uuid.string">
</generator>
</id>

<set
name="items"
lazy="false"
inverse="true"
cascade="all-delete-orphan"
sort="unsorted"
>

<key
column="shoppinglist"
/>

<one-to-many
class="com.softech.shopping.model.ShoppinglistItem"
/>
</set>

<many-to-one
name="user"
class="com.softech.shopping.model.User"
cascade="none"
outer-join="auto"
update="true"
insert="true"
column="user"
/>

<many-to-one
name="shop"
class="com.softech.shopping.model.Shop"
cascade="none"
outer-join="auto"
update="true"
insert="true"
column="shop"
/>

<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-Shoppinglist.xml
containing the additional properties and place it in your merge dir.
-->

</class>

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

=--=-=-=-=-=-=-=- ShoppinglistItem.hbm.xml =-=-=-=-=-=-=-=-=-
<?xml version="1.0"?>

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

<hibernate-mapping>
<class
name="com.softech.shopping.model.ShoppinglistItem"
table="ShoppinglistItem"
dynamic-update="false"
dynamic-insert="false"
>

<id
name="id"
column="id"
type="java.lang.String"
>
<generator class="uuid.string">
</generator>
</id>

<many-to-one
name="shop"
class="com.softech.shopping.model.Shop"
cascade="none"
outer-join="auto"
update="true"
insert="true"
column="shop"
/>

<many-to-one
name="article"
class="com.softech.shopping.model.Article"
cascade="none"
outer-join="auto"
update="true"
insert="true"
column="article"
/>

<property
name="amount"
type="double"
update="true"
insert="true"
column="amount"
/>

<many-to-one
name="shoppinglist"
class="com.softech.shopping.model.Shoppinglist"
cascade="none"
outer-join="auto"
update="true"
insert="true"
column="shoppinglist"
/>

<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-ShoppinglistItem.xml
containing the additional properties and place it in your merge dir.
-->

</class>

</hibernate-mapping>


Top
 Profile  
 
 Post subject: In Addition:Help, Set is correctly persisted, but not loaded
PostPosted: Tue Oct 12, 2004 5:32 pm 
Newbie

Joined: Tue Oct 12, 2004 5:04 pm
Posts: 5
I'm running everything in a Tomcat 5.0 environment. Sorry for the omission.

Iwan


Top
 Profile  
 
 Post subject: Help, Set is correctly persisted, but not loaded
PostPosted: Wed Oct 13, 2004 5:26 pm 
Newbie

Joined: Tue Oct 12, 2004 5:04 pm
Posts: 5
Fixed it by not using the uuid.string key-generator but the uuid.hex instead.

Iwan


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