-->
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: idbags and generator assigned
PostPosted: Thu Dec 01, 2005 11:27 pm 
Newbie

Joined: Thu Nov 17, 2005 11:07 pm
Posts: 2
Hey guys,

I have an association table which has a surrogate key (a primary key per se) and am trying to use IDBAG to insert the data in the association table.


TABLE: BUDGETTOBUDGETCATEGORY

BUDGETTOBUDGETCATEGORYID (PK)
BUDGETID (FK)
BUDGETCATEGORYID (FK)
DATECREATED
DATEMODIFIED



This table maintains a many-to-many relationship between Budget and BudgetCategory tables.

I don't want to create a class for the above association table and am trying to insert into this table. On top of it we generate our own primary keys. My question is if i set the generator class to be "assigned" for the IDBAG how can i assign the actual value to the column in the code, i am totally stumped here.

This is how the mapping looks like


<hibernate-mapping package="test.dao">
<class name="BudgetCategory" table="BUDGETCATEGORY">
<id name="budgetCategoryId" column="BUDGETCATEGORYID" type="string">
<generator class="assigned"/>
</id>
<property name="name" column="NAME" type="string"/>
<property name="displayName" column="DISPLAYNAME" type="string"/>
<property name="type" column="TYPE" type="string"/>
<property name="dateCreated" column="DATECREATED" type="timestamp"/>
<property name="dateModified" column="DATEMODIFIED" type="timestamp"/>


<set name="tips" inverse="true" cascade="all-delete-orphan">
<key column="BUDGETCATEGORYID"/>
<one-to-many class="test.dao.BudgetTip"/>
</set>


<idbag name="budgets" table="BUDGETTOBUDGETCATEGORY">
<collection-id column="BUDGETTOBUDGETCATEGORYID" type="string">
<generator class="assigned"/>
</collection-id>
<key column="BUDGETCATEGORYID"/>
<many-to-many column="BUDGETID"
class="test.dao.Budget"/>
</idbag>
</class>
</hibernate-mapping>



Here's the code snippet that i am trying to execute and have been stumped on how to add our application's primary key to the collection-id column


//Code Snippet

public BudgetCategory save(Object persistentObject) throws DataException {
if (persistentObject == null) {
throw new DataException("Cannot save a null BudgetCategory object");
}

BudgetCategory category = (BudgetCategory)persistentObject;
category.setBudgetCategoryId(IdUtils.randomStr(ID_DEFAULT_LENGTH));

//while saving a new BudgetCategory instance make sure that the category is
//added to every single Budget instance.

//TODO:: Add the surrgate key id to the collection-id column using IdUtils

category.setBudgets(getHibernateTemplate().loadAll(Budget.class));

return (BudgetCategory)saveOrUpdate(category);
}


Any help here would be appreciated. We are using Hibernate 3.0 with Spring.

thanks
- k


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 02, 2005 7:42 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
No, but you can use a custom IdentifierGenerator


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 02, 2005 10:38 pm 
Newbie

Joined: Thu Nov 17, 2005 11:07 pm
Posts: 2
Steve,

thank you that helped.

- K


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.