I am sure I am not the only person having to use m-m and m-1 relationships with VO's am I?
This is quite an urgent task for me as I am not able to continue with this task until it is done.
Please, someone give me 5 minutes.
--- Thanks... Mick Knutson ---
From: "Mick Knutson" <[EMAIL PROTECTED]> Reply-To: [EMAIL PROTECTED] To: [EMAIL PROTECTED] Subject: [Xdoclet-user] updating a m-m value object? Date: Tue, 03 Jun 2003 20:06:04 -0700
I have made some progress, but not enough to have my application work.
I now have Contacts in my DB. And I have 3 different Alert's already there as well.
When there are no mapped relashionships in my DB, all 3 Alerts show zero Contacts Selected.
But, in various combinations, it seems that a given Contact can only be mapped to 1 Alert at a time. This is far from what I need as I need TRUE M-M mapping.
Can anyone please tell me why this is happening and how I can fix this?
--- Thanks... Mick Knutson ---
OK, This is my second post as nobody responded to me the first time.
I am seriously trying to figure this out but no luck.
I added the code I have below, but my M-M relationship is not updating correctly, or consistantly. It just seems to randomly update the fields it wants, but only 1 Alert at a time. So modifying multiple alerts does not actually take.
Can someone please help me?
Struts Action add: ================== public ActionForward add( ActionMapping mapping , ActionForm form , HttpServletRequest request , HttpServletResponse response ) throws Exception { try { if( log.isInfoEnabled() ) { log.info( "Process a alert add(...)" ); log.info( "alertForm::add(): " + form.toString() ); }
IAlertServices asd = this.getAlertService();
UserLightDto userlightDto = getUserContainer( request ).getUserLightDto();
AlertDto alertDto = new AlertDto(); BeanUtils.copyProperties( alertDto, form );
if( log.isInfoEnabled() ) { log.info( "alertUpdate.dto: " + alertDto.toString() ); }
// First we need to create the ContactDto objects from our String[]
String[] alertContacts = (String[])( (DynaActionForm) form ).get( Constants.ALERT_CONTACTS_KEY );
if( alertDto.getAlertId().equals( "" ) ) { // Must be a new alert then....add it log.info( "Must be a new alert then....Add it" );
// We first have to create the alert. Then, only after creation, can we add the contacts.
alertDto = asd.alertCreate( alertDto );
log.info( "String[] alertContacts length: " + alertContacts.length );
alertDto = setAlertContactsFromForm( alertDto, alertContacts );
alertDto = asd.alertUpdate( alertDto );
return ( mapping.findForward( Constants.SUCCESS_FWD ) );
}
log.info( "Must be an existing alert then....update it" ); alertDto.clearContacts(); alertDto = asd.alertUpdate( alertDto ); alertDto = setAlertContactsFromForm( alertDto, alertContacts ); alertDto = asd.alertUpdate( alertDto );
// Forward control to the specified success URI return ( mapping.findForward( Constants.SUCCESS_FWD ) ); } catch( Exception e ) { log.error( "Exception adding alert; " + e.getMessage(), e ); throw e; } }
private String[] setAlertContactsToForm( AlertDto alertDto ) { // ContactDto[] alertContacts = alertDto.getContacts(); String[] contacts = new String[alertContacts.length];
for( int i=0; i < alertContacts.length; i++ ) { log.info( "alertContacts[i]: " + alertContacts[i].toString() ); contacts[i] = alertContacts[i].getContactId(); } return contacts; }
private AlertDto setAlertContactsFromForm( AlertDto alertDto, String[] contacts )
{
alertDto.clearContacts();
for( int i=0; i < contacts.length; i++ ) { ContactDto contact = new ContactDto(); log.info( "contacts[i]: " + contacts[i] ); contact.setContactId( contacts[i] ); alertDto.addContact( contact ); } return alertDto; }
AlertManager: ============== public AlertDto alertUpdate( AlertDto alertData ) throws EJBException { try { AlertLocalHome alertLocalHome = AlertUtil.getLocalHome();
if( log.isInfoEnabled() )
{
log.info( "Update alert Data with this: " + alertData.toString() );
}
AlertLocal alert = null; Long alertSequence = null;
try
{
alert = alertLocalHome.findByPrimaryKey( alertData.getAlertId() );
}
catch(Exception e)
{
if( log.isInfoEnabled() )
{
log.info( "No alert found. So create a new alert row and populate it with this data." );
}
// create a profile then...
alertData.setAlertId( AlertUtil.generateGUID( alertData ) );
alert = alertLocalHome.create( alertData );
return alert.getAlertDto();
}
log.info( "Update alertDto data: " + alertData.toString() ); alert.setAlertDto( alertData );
AlertDto dto = alert.getAlertDto();
if (log.isInfoEnabled()) { log.info( "alertUpdate.dto: " + dto.toString() ); }
return dto; } catch(Exception e) { log.error( "Error performing Alert update.", e); throw new EJBException( e.getMessage() ); } }
Alert Entity: ============= package com.baselogic.yoursos.alert;
import java.util.Collection; import java.util.Date;
//import com.baselogic.yoursos.contact.ContactLocal; import com.baselogic.yoursos.contact.ContactDto;
/**
* The Entity bean represents a Alert Entity
*
* @author Mick Knutson
* @version $Revision: 1.1 $
*
* @ejb.bean
* name="Alert"
* display-name="Alert for YourSos"
* cmp-version="2.x"
* type="CMP"
* view-type="local"
* local-jndi-name="local/com.baselogic.yoursos.alert.AlertLocal"
* primkey-field="alertId"
* schema="Alert"
*
* @ejb.pk
* class="java.lang.String"
*
* @ejb.value-object
* match="*"
* name="Alert"
*
* @ejb.finder signature="java.util.Collection findAllByUserId( java.lang.Long pUserId )"
* query="SELECT OBJECT(c) FROM Alert AS c WHERE c.userId = ?1"
* @jboss.query signature="java.util.Collection findAllByUserId( java.lang.Long pUserId )"
* query="SELECT OBJECT(c) FROM Alert AS c WHERE c.userId = ?1"
*
* @ejb.util
* generate="physical"
*
* @ejb.transaction
* type="Required"
*
* @ejb.transaction-type
* type="Container"
*
* @ejb.permission
* unchecked="true"
*
* @jboss.table-name
* table-name="alert"
*
* @jboss.create-table
* create="false"
*
* @jboss.remove-table
* remove="false"
*
**/
public abstract class AlertBean implements javax.ejb.EntityBean
{
private javax.ejb.EntityContext myEntityCtx;
// -------------------------------------------------------------------------
// Properties (Getters/Setters)
// -------------------------------------------------------------------------
/** * Retrieve the Alert's sequenceName for use as a primaryKey. * * @ejb.pk-field * @ejb.persistent-field * @ejb.interface-method * @jboss.column-name name="alert_id" **/ public abstract java.lang.String getAlertId();
/**
* No interface method for setAlertId(..). See page 130 of the EJB 2.0 specification:
* "Once the primary key for an entity bean has been set, the Bean Provider must
* not attempt to change it by use of set accessor methods on the primary key
* cmp-fields. The Bean provider should therefore not expose the set accessor
* methods for the primary key cmp-fields in the component interface of the
* entity bean.". A work around would be to remove and then an re-create the bean.
*/
public abstract void setAlertId( java.lang.String pAlertId );
/** * Manage the Allergies's userId FK. * * @ejb.persistent-field * @ejb.interface-method * @jboss:column-name name="user_id_fk" **/ public abstract Long getUserId(); public abstract void setUserId( Long pUserId );
/** * Manage the Alert's subject. * * @ejb.persistent-field * @ejb.interface-method * @jboss.column-name name="subject" * **/ public abstract String getSubject(); public abstract void setSubject( String pSubject );
/** * Manage the Alert's StartDate * * @ejb.persistent-field * @ejb.interface-method * @jboss.column-name name="starting_date" * **/ public abstract java.util.Date getStartDate(); public abstract void setStartDate( java.util.Date pStartDate );
/** * Manage the Alert's Reoccurring * * @ejb.persistent-field * @ejb.interface-method * @jboss.column-name name="reoccurring" **/ public abstract String getReoccurring(); public abstract void setReoccurring( String pReoccurring );
/** * Manage the Alert's GracePeriodDays * * @ejb.persistent-field * @ejb.interface-method * @jboss.column-name name="grace_period_days" * **/ public abstract String getGracePeriodDays(); public abstract void setGracePeriodDays( String pGracePeriodDays );
/** * Manage the Alert's GracePeriodHours * * @ejb.persistent-field * @ejb.interface-method * @jboss.column-name name="grace_period_hours" * **/ public abstract String getGracePeriodHours(); public abstract void setGracePeriodHours( String pGracePeriodHours );
/** * Manage the Alert's EndingDate * * @ejb.persistent-field * @ejb.interface-method * @jboss.column-name name="ending_date" * **/ public abstract java.util.Date getEndingDate(); public abstract void setEndingDate( java.util.Date pEndingDate );
/** * Manage the Alert's StartingLocation * * @ejb.persistent-field * @ejb.interface-method * @jboss.column-name name="starting_location" * **/ public abstract String getStartingLocation(); public abstract void setStartingLocation( String pStartingLocation );
/** * Manage the Alert's EndingLocation * * @ejb.persistent-field * @ejb.interface-method * @jboss.column-name name="ending_location" * **/ public abstract String getEndingLocation(); public abstract void setEndingLocation( String pEndingLocation );
/** * Manage the Alert's Status * * @ejb.persistent-field * @ejb.interface-method * @jboss.column-name name="status" * **/ public abstract String getStatus(); public abstract void setStatus( String pStatus );
/** * Manage the Alert's SafeConfirm * * @ejb.persistent-field * @ejb.interface-method * @jboss.column-name name="safe_confirm" * **/ public abstract String getSafeConfirm(); public abstract void setSafeConfirm( String pSafeConfirm );
/** * Manage the Alert's Details * * @ejb.persistent-field * @ejb.interface-method * @jboss.column-name name="details" * **/ public abstract String getDetails(); public abstract void setDetails( String pDetails );
/** * Manage the Alert's NoteToContactees * * @ejb.persistent-field * @ejb.interface-method * @jboss.column-name name="note_to_contactees" * **/ public abstract String getNoteToContactees(); public abstract void setNoteToContactees( String pNoteToContactees );
/** * Manage the Alert's DTO/Form object * * @ejb.interface-method * @ejb.transaction * type="Supports" **/ public abstract AlertDto getAlertDto();
/** * Manage the Alert's DTO/Form object * * @ejb.interface-method * @ejb.transaction * type="Supports" **/ public abstract void setAlertDto( AlertDto pAlertDto );
/** * Get all Contact's for this alert. * * @ejb.interface-method * * @ejb.relation * name="Alert-Contact" * role-name="alerts-have-many-contacts" * target-ejb="Contact" * target-role-name="contact-belongs_to-many-alerts" * target-multiple="yes" * * @ejb.relation-table * table-name="alert_contacts_rel" * create-table="false" * remove-table="false" * * @jboss.relation * related-pk-field="contactId" * fk-column="contact_id" * fk-constraint="false" * * @jboss.relation-mapping * style="relation-table" * * @ejb.value-object * aggregate="com.baselogic.yoursos.contact.ContactDto" * aggregate-name="Contact" * match="normal" * members="com.baselogic.yoursos.contact.ContactLocal" * members-name="Contact" * type="Collection" * relation="external" * */ public abstract Collection getContacts(); public abstract void setContacts();
/** * Get all Location's for this alert. * * @ejb.interface-method * * @ejb.relation * name="Alert-Location" * role-name="alerts-have-many-locations" * target-ejb="Location" * target-role-name="locations-belong_to-many-alerts" * target-multiple="yes" * * @ejb.relation-table * table-name="alert_location_rel" * create-table="false" * remove-table="false" * * @jboss.relation * related-pk-field="locationId" * fk-column="location_id" * fk-constraint="false" * * @jboss.relation-mapping * style="relation-table" * * @ejb.value-object * aggregate="com.baselogic.yoursos.location.LocationDto" * aggregate-name="Location" * match="normal" * members="com.baselogic.yoursos.location.LocationLocal" * members-name="Location" * type="Collection" * relation="external" * */ public abstract Collection getLocations(); public abstract void setLocations();
// -------------------------------------------------------------------------
// Framework Callbacks
// -------------------------------------------------------------------------
/**
* Create a TestEntity based on the supplied TestEntity Value Object.
*
* @param pAlertDto The name used to create the Alert.
*
* @throws javax.ejb.EJBException If no new unique ID could be retrieved this will
* rollback the transaction because there is no
* hope to try again
* @throws javax.ejb.CreateException Because we have to do so (EJB spec.)
*
* @ejb.interface-method view-type="local"
* @ejb.create-method view-type="local"
**/
public java.lang.String ejbCreate( AlertDto pAlertDto )
throws javax.ejb.EJBException, javax.ejb.CreateException
{
setAlertId( pAlertDto.getAlertId() );
setAlertDto( pAlertDto );
return null; }
/** * String Value of this Alert Entity * * @ejb.interface-method * **/ public String toString() { try { return( getAlertDto().toString() ); } catch(Exception e){return "";} }
// -------------------------------------------------------------------------
// EJB Callbacks
// -------------------------------------------------------------------------
public void ejbPostCreate( AlertDto pAlertDto )
{/* Do nothing yet */}
public void setEntityContext( javax.ejb.EntityContext lContext ) { myEntityCtx = lContext; }
public void unsetEntityContext() { myEntityCtx = null; }
public void ejbActivate() {}
public void ejbPassivate() {}
public void ejbLoad() {}
public void ejbStore() {}
public void ejbRemove() throws javax.ejb.RemoveException {}
} //The End...
Contact Entity: ================== /** * Get the User for this Contact * * @ejb.interface-method * * @ejb.relation * name="Alert-Contact" * role-name="contact-belongs_to-many-alerts" * target-ejb="Alert" * target-role-name="alerts-have-many-contacts" * target-multiple="yes" * * @ejb.relation-table * table-name="alert_contacts_rel" * create-table="false" * remove-table="false" * * @jboss.relation * related-pk-field="alertId" * fk-column="alert_id" * fk-constraint="false" * * @jboss.relation-mapping * style="relation-table" **/ public abstract AlertLocal getAlert(); public abstract void setAlert( AlertLocal pAlert );
_________________________________________________________________
Help STOP SPAM with the new MSN 8 and get 2 months FREE* http://join.msn.com/?page=features/junkmail
------------------------------------------------------- This SF.net email is sponsored by: Etnus, makers of TotalView, The best thread debugger on the planet. Designed with thread debugging features you've never dreamed of, try TotalView 6 free at www.etnus.com. _______________________________________________ xdoclet-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/xdoclet-user
_________________________________________________________________
Tired of spam? Get advanced junk mail protection with MSN 8. http://join.msn.com/?page=features/junkmail
------------------------------------------------------- This SF.net email is sponsored by: Etnus, makers of TotalView, The best thread debugger on the planet. Designed with thread debugging features you've never dreamed of, try TotalView 6 free at www.etnus.com. _______________________________________________ xdoclet-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/xdoclet-user
