Hello Marco, Monday, June 23, 2003, 9:32:04 PM, Marco Tedone wrote:
MT> BINGOO! Actually in the AddressBean.ejbCreate() method none of the MT> AddressBean fields was set. Thank you Alex, I want to pay you a dinner! Status: Open Resolution: Accepted alex MT> Marco MT> ----- Original Message ----- MT> From: "Alexey Loubyansky" <[EMAIL PROTECTED]> MT> To: "Marco Tedone" <[EMAIL PROTECTED]> MT> Sent: Monday, June 23, 2003 8:03 AM MT> Subject: Re: [JBoss-user] Jboss 3.2.1 Problems with table's relationship >> Are you sure AddressBean.ejbCreate(AddressData aData) initializes all >> fields properly? >> >> alex >> >> Monday, June 23, 2003, 12:41:38 AM, Marco Tedone wrote: >> >> MT> Hi, it's me again. I created the table's relationship as shown by MT> Jboss >> MT> logging messages (don't consider the Numerator Table which is not MT> related to >> MT> the problem). >> >> MT> 22:25:03,828 INFO [People] Created table 'People' successfully. >> MT> 22:25:03,828 INFO [Numerator] Table 'Numerator' already exists >> MT> 22:25:03,906 INFO [Address] Created table 'Address' successfully. >> MT> 22:25:03,937 INFO [Address] Added foreign key constraint to table MT> 'People' >> >> MT> After deployment I find in my database the People and Address tables. MT> People >> MT> has an index (addressId) which is the pk of Address table. Here MT> follows the >> MT> code of my entity bean: >> >> MT> <!-- BEGIN of CODE --> >> >> MT> package org.jemos.core.framework.ejbs.entities; >> MT> import java.util.Date; >> MT> import javax.ejb.CreateException; >> MT> import javax.ejb.EJBException; >> MT> import javax.ejb.EntityBean; >> MT> import javax.naming.InitialContext; >> MT> import javax.naming.NamingException; >> MT> import org.apache.log4j.Category; >> MT> import org.jemos.core.framework.ejbs.BaseEntityBean; >> MT> import org.jemos.core.framework.ejbs.interfaces.AddressData; >> MT> import org.jemos.core.framework.ejbs.interfaces.AddressLocal; >> MT> import org.jemos.core.framework.ejbs.interfaces.AddressLocalHome; >> MT> import org.jemos.core.framework.ejbs.interfaces.PeopleData; >> MT> import org.jemos.core.framework.ejbs.interfaces.PeopleKey; >> >> >> MT> /** >> MT> * >> MT> * @ejb.bean >> MT> * type="CMP" >> MT> * name="People" >> MT> * reentrant="true" >> MT> * local-jndi-name="ejb/jemos/core/PeopleEJB" >> MT> * view-type="local" >> MT> * transaction-type="Container" >> MT> * cmp-version="2.x" >> MT> * @ejb.transaction >> MT> * type="Required" >> MT> * >> MT> * @ejb.ejb-ref >> MT> * ejb-name="Address" >> MT> * view-type="local" >> MT> * ref-name="Address" >> MT> * >> MT> * >> MT> * @jboss.persistence >> MT> * pk-constraint="true" >> MT> * table-name="people" >> MT> * >> MT> * @ejb.value-object >> MT> * name="PeopleValue" >> MT> * match="*" >> MT> * >> MT> */ >> MT> public abstract class PeopleBean >> MT> extends BaseEntityBean implements EntityBean { >> MT> //The logger instance >> MT> private transient final Category log = >> MT> Category.getInstance(getClass().getName()); >> MT> /** >> MT> * @ejb.create-method >> MT> * @param pData >> MT> * @return >> MT> * @throws CreateException >> MT> */ >> MT> public PeopleKey ejbCreate(PeopleData pData, AddressData aData) >> MT> throws CreateException { >> MT> log.info("Now in ejbCreate: Setting People data"); >> MT> setEmail(pData.getEmail()); >> MT> setPassword(pData.getPassword()); >> MT> setFirstName(pData.getFirstName()); >> MT> setLastName(pData.getLastName()); >> MT> setCreationDate(new java.util.Date()); >> MT> return null; >> MT> } >> MT> public void ejbPostCreate(PeopleData pData, AddressData aData) >> MT> throws CreateException { >> MT> AddressLocal address = createAddress(aData); >> MT> setHomeAddress(address); >> MT> } >> MT> //Business methods >> MT> /** >> MT> * @ejb.interface-method >> MT> */ >> MT> public AddressLocal createAddress(AddressData aData) >> MT> throws EJBException >> MT> { >> MT> AddressLocal addr = this.getHomeAddress( ); >> MT> log.info("from setAddress. AddressData:" + aData); >> MT> try >> MT> { >> MT> if (addr == null) >> MT> { >> MT> log.info("Creating a new reference to AddressEJB"); >> MT> // Customer doesn't have an address yet. Create a new one. >> MT> InitialContext cntx = new InitialContext( ); >> MT> AddressLocalHome addrHome = >> MT> (AddressLocalHome)cntx.lookup("ejb/jemos/core/AddressEJB"); >> MT> log.info("Before creating: addressId value= " + aData.getAddressId()); >> MT> addr = addrHome.create(aData); >> MT> log.info("Address created."); >> MT> } >> MT> else >> MT> { >> MT> // Customer already has an address. Change its fields >> MT> log.info("Customer already has an address. Change its fields"); >> MT> addr.setAddress1(aData.getAddress1()); >> MT> addr.setAddress2(aData.getAddress2()); >> MT> addr.setAddress3(aData.getAddress3()); >> MT> addr.setZip(aData.getZip()); >> MT> addr.setCity(aData.getCity()); >> MT> addr.setCountry(aData.getCountry()); >> MT> } >> MT> } >> MT> catch (NamingException ne) >> MT> { >> MT> throw new EJBException(ne); >> MT> } catch (CreateException e) { >> MT> e.printStackTrace(); >> MT> } >> MT> finally{ >> MT> return addr; >> MT> } >> MT> } >> MT> /** >> MT> * @ejb.interface-method >> MT> * @return >> MT> */ >> MT> public AddressData getAddress() >> MT> { >> MT> AddressLocal addrLocal = this.getHomeAddress(); >> MT> if (addrLocal == null) return null; >> MT> int addressId = addrLocal.getAddressId(); >> MT> String address1 = addrLocal.getAddress1(); >> MT> String address2 = addrLocal.getAddress2(); >> MT> String address3 = addrLocal.getAddress3(); >> MT> String zip = addrLocal.getZip(); >> MT> String city = addrLocal.getCity(); >> MT> String country = addrLocal.getCountry(); >> MT> Date date = addrLocal.getCreationDate(); >> MT> AddressData addrValue = new AddressData(addressId, >> MT> address1, >> MT> address2, >> MT> address3, >> MT> zip, >> MT> city, >> MT> country, >> MT> date); >> MT> return addrValue; >> MT> } >> MT> //persistent-relationships >> MT> /** >> MT> * @ejb.interface-method >> MT> * view-type="local" >> MT> * @ejb.relation >> MT> * name="People-Address" >> MT> * role-name="1-People-1-Address" >> MT> * multiple="no" >> MT> * target-role-name="1-Address-1-People" >> MT> * target-multiple="no" >> MT> * target-ejb="Address" >> MT> * >> MT> * @jboss.relation >> MT> * fk-constraint="true" >> MT> * related-pk-field="addressId" >> MT> * fk-column="addressId" >> MT> */ >> MT> public abstract AddressLocal getHomeAddress(); >> MT> /** >> MT> * @ejb.interface-method >> MT> * @param address >> MT> */ >> MT> public abstract void setHomeAddress(AddressLocal address); >> MT> //abstract-accessor methods >> MT> /** >> MT> * @ejb.interface-method >> MT> * @ejb.persistent-field >> MT> * @ejb.pk-field >> MT> * @jboss.persistence >> MT> * not-null="true" >> MT> * @jboss.cmp-field >> MT> * field-name="email" >> MT> * column-name="email" >> MT> */ >> MT> public abstract String getEmail(); >> MT> /** >> MT> * @ejb.interface-method >> MT> * @param email >> MT> */ >> MT> public abstract void setEmail(String email); >> MT> /** >> MT> * @ejb.interface-method >> MT> * @ejb.persistent-field >> MT> * @ejb.pk-field >> MT> * @jboss.persistence >> MT> * not-null="true" >> MT> * @jboss.cmp-field >> MT> * field-name="password" >> MT> * column-name="password" >> MT> */ >> MT> public abstract String getPassword(); >> MT> /** >> MT> * @ejb.interface-method >> MT> * @param password >> MT> */ >> MT> public abstract void setPassword(String password); >> MT> /** >> MT> * @ejb.persistent-field >> MT> * @ejb.interface-method >> MT> * @jboss.cmp-field >> MT> * field-name="firstName" >> MT> * column-name="firstName" >> MT> */ >> MT> public abstract String getFirstName(); >> MT> /** >> MT> * @ejb.interface-method >> MT> * @param firstName >> MT> */ >> MT> public abstract void setFirstName(String firstName); >> MT> /** >> MT> * @ejb.interface-method >> MT> * @ejb.persistent-field >> MT> * @jboss.cmp-field >> MT> * field-name="lastName" >> MT> * column-name="lastName" >> MT> */ >> MT> public abstract String getLastName(); >> MT> /** >> MT> * @ejb.interface-method >> MT> * @param lastName >> MT> */ >> MT> public abstract void setLastName(String lastName); >> MT> //cmr-fields >> >> >> MT> } >> >> MT> <!-- END of CODE --> >> >> MT> My client creates a reference to the local home interface of the MT> People bean >> MT> and then creates a People entity: so far so good. As you can see in MT> the >> MT> ejbPostCreate, then the bean calls the createAddress method which MT> creates an >> MT> Address entity and returns a reference to the Address local interface. MT> In >> MT> the ejbPostCreate, then, I call the persitence-relationships accessors >> MT> (setHomeAddress) but here I obtain the wrong result. While a People MT> entity >> MT> is written with the data I entered, an Address entity is written with MT> the >> MT> following values (this has been taken by Jboss console, but the record MT> on >> MT> the database appears exactly as this): >> >> MT> [PeopleDbManagerSession] AddressData: {addressId=0 address1=null >> MT> address2=null address3=null zip=null city=null country=null >> MT> creationDate=null >> >> MT> These are the values immediately before the home.create(..) method of MT> the >> MT> Address local bean: >> >> MT> <!-- BEGIN of DATA --> >> MT> 22:27:42,234 INFO [PeopleCMP$Proxy] from setAddress. >> MT> AddressData:{addressId=1 address1=43, Millais Road address2=Leyton >> MT> address3=Essex zip=E11 4HB ci >> MT> ty=London country=UK creationDate=Sun Jun 22 22:27:41 BST 2003} >> MT> 22:27:42,234 INFO [PeopleCMP$Proxy] Creating a new reference to MT> AddressEJB >> MT> 22:27:42,234 INFO [PeopleCMP$Proxy] Before creating: addressId value= MT> 1 >> MT> <!-- END of DATA --> >> >> MT> As you can see, the AddressData object contains the values which I MT> entered >> MT> on my client, but the record on the database is written to null MT> values. >> >> MT> I thought that maybe it could be the database (i'm using MySQL MT> 4.0.12-nt) so >> MT> I changed to SQLServer but the results are the same! >> >> MT> Please help me, I think I've looked everywhere, and now I don't know MT> where >> MT> to look further. >> >> MT> Many thanks, >> >> MT> Marco ------------------------------------------------------- This SF.Net email is sponsored by: INetU Attention Web Developers & Consultants: Become An INetU Hosting Partner. Refer Dedicated Servers. We Manage Them. You Get 10% Monthly Commission! INetU Dedicated Managed Hosting http://www.inetu.net/partner/index.php _______________________________________________ JBoss-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-user