-->
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.  [ 2 posts ] 
Author Message
 Post subject: Add attritude to many to many join
PostPosted: Wed Nov 03, 2004 9:12 pm 
Beginner
Beginner

Joined: Thu Sep 23, 2004 6:03 am
Posts: 27
Hibernate version: 2.1.1

Mapping documents: Xdoclet

Name and version of the database you are using: MySQL 4.1

The generated SQL (show_sql=true):

create table condition_type_value (
id BIGINT NOT NULL AUTO_INCREMENT,
has_text BIT,
is_defaulted_value BIT,
value VARCHAR(255),
fk_condition_type_value_id BIGINT,
primary key (id)
);

create table table_join_rights_condition_type_value (
fk_condition_type_value_id BIGINT not null,
fk_condition_type_value BIGINT not null,
fk_rights_id BIGINT not null,
fk_rights BIGINT not null
);

create table rights (
id BIGINT NOT NULL AUTO_INCREMENT,
comments VARCHAR(255),
rights_id BIGINT,
fk_rights_type_id BIGINT,
fk_condition_type_id BIGINT,
primary key (id)
);



I was hoping that someone might be able to point me in a certain direction with regard to what I am trying to do. As you can see for the generated SQL I have a many to many relationship between rights and conditionTypeValues, what I would also like to be able to do is add another attribute to table_join_rights_condition_type_value to capture comments. How is this done? I am using Xdoclet to generate the hibernate mappings, any input would be more appreicated.

CONDITION TYPE VALUE CLASS
--------------------
/**
* @return Returns the rights.
* @hibernate.bag
* table="table_join_rights_condition_type_value"
* cascade="all"
* inverse="true"
* @hibernate.collection-key
* column="fk_condition_type_value_id"
* @hibernate.collection-many-to-many
* class="au.edu.tlf.lips.model.Rights"
* column="fk_condition_type_value"
*/
public List getRights() {
return rights;
}

/**
* @param rights The rights to set.
*/
public void setRights(List rights) {
this.rights = rights;
}


RIGHTS CLASS
-----------------------------------------
/**
* @return Returns the conditionTypeValue.
* @hibernate.bag
* table="table_join_rights_condition_type_value"
* cascade="all"
* inverse="true"
* @hibernate.collection-key
* column="fk_rights_id"
* @hibernate.collection-many-to-many
* class="au.edu.tlf.lips.model.ConditionTypeValue"
* column="fk_rights"
*/
public List getConditionTypeValue() {
return conditionTypeValue;
}

/**
* @param conditionTypeValue The conditionTypeValue to set.
*/
public void setConditionTypeValue(List conditionTypeValue) {
this.conditionTypeValue = conditionTypeValue;
}


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 04, 2004 1:03 am 
Beginner
Beginner

Joined: Thu Sep 23, 2004 6:03 am
Posts: 27
After reading a little more I believe that I need to only implement a unidirectional many-to-many assoication (i.e.) remove Xdoclet in ConditionTypeValue class but when I'm trying to then add the assoicated the table is not being populated. Is this code correct for what I'm trying to do. Any help would be great.

Thanks

public ModelAndView onSubmit(HttpServletRequest request,
HttpServletResponse response, Object command, BindException errors)
throws Exception {
if (log.isDebugEnabled()) {
log.debug("entering 'onSubmit' method...");
}

//define the licence
Licence licence = (Licence) command;

//set up list to contain all rights
List rights = new LinkedList();

//a single instance of a right
Rights right = null;

//success screen
String success = getSuccessView();

//get the parent rights type
String rightsTypeId = request.getParameter("rightsTypeId");
RightsType rightsType = rightsTypeMgr.getRightsType(Long.valueOf(rightsTypeId));

//get conditions that applied to that rightsType
List conditionTypes = conditionTypeMgr.getAllCondtionTypesForRightsType(rightsType);
Iterator keys = conditionTypes.iterator();

//for each condition set actual right information
while(keys.hasNext()){
ConditionType conditionType = (ConditionType)keys.next();

//populate right object
right = new Rights();
right.setLicence(licence);
right.setRightsType(rightsType);
right.setConditionType(conditionType);

List conditionTypeValuesToAddToRights = new LinkedList();
List conditionTypeValuesToAddToConditions = new LinkedList();

String[] requestIds = request.getParameterValues(conditionType.getId().toString());

for(int i=0; i<requestIds.length; i++) {
ConditionTypeValue conditionTypeValue = conditionTypeValueMgr.getConditionTypeValue(Long.valueOf(requestIds[i]));
conditionTypeValuesToAddToRights.add(conditionTypeValue);
}
right.setConditionTypeValue(conditionTypeValuesToAddToRights);

rightsMgr.saveRights(right);

rights.add(right);
}

rightsMgr.removeRights(licence);

licence.setRights(rights);

licenceMgr.saveLicence(licence);


String message = getMessageSourceAccessor().getMessage(
"rights.updated",
new Object[] { licence.getLicenceDescriptor() });

saveMessage(request, message);

success = "viewLicence.html?id=" + licence.getId();

return new ModelAndView(new RedirectView(success));
}


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