So an Alert has many Contacts and many Locations. But, Contacts and Location can be assigned to many different Alerts.
My issue is that I am trying to use the VO on the delegate/jsp side. So, when I get a new Alert, It seems to add the contact relationship. But it seems random. Sometimes it works, other times it adds different ones instead.
Then, when I want to select different ones, effectively deleting the old references and adding a new one, this is random as well. There does not seem to be a pattern as to how it updates the values.
Can someone please look at the below relevant code and help me to get this relationship to behave?
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 );
_________________________________________________________________
MSN 8 helps eliminate e-mail viruses. Get 2 months FREE*. http://join.msn.com/?page=features/virus
------------------------------------------------------- This SF.net email is sponsored by: eBay Get office equipment for less on eBay! http://adfarm.mediaplex.com/ad/ck/711-11697-6916-5 _______________________________________________ xdoclet-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/xdoclet-user
