First of all: thanks for the fast responses!
Ok, this is what I did: I created 2 beans within WSAD, by means of the EJB wizard. This wizard lets you specify fields and appropriate getters and setters. In the case of the Event CMP, I simply added getters and setters for the userId field, which is perfectly possible without getting error messages. After the creation of the 2 beans, I added a relationship within the EJB deployment descriptor. I decided not to make the Event CMP bean navigable, so I don't have any CMR field (e.g. user) within this bean (which is again possible). So, I supposed I could simply set the user id within the ejbCreate method.. Apparently this is not the case, and I don't know why... Anyway: this is the code of both beans and the deployment descriptor for WebSphere. Maybe you can see my mistakes better this way.. Thanks in advance for a (last?) answer...
package entity;
import java.awt.image.LookupOp;
import javax.naming.InitialContext;
/**
* Bean implementation class for Enterprise Bean: Event
*/
public abstract class EventBean implements javax.ejb.EntityBean {
private javax.ejb.EntityContext myEntityCtx;
/**
* setEntityContext
*/
public void setEntityContext(javax.ejb.EntityContext ctx) {
myEntityCtx = ctx;
}
/**
* getEntityContext
*/
public javax.ejb.EntityContext getEntityContext() {
return myEntityCtx;
}
/**
* unsetEntityContext
*/
public void unsetEntityContext() {
myEntityCtx = null;
}
/**
* ejbCreate
*/
public java.lang.String ejbCreate(java.lang.String id)
throws javax.ejb.CreateException {
setId(id);
return null;
}
/**
* ejbPostCreate
*/
public void ejbPostCreate(java.lang.String id)
throws javax.ejb.CreateException {
}
public java.lang.String ejbCreate(common.bean.EventBean event)
throws javax.ejb.CreateException {
System.out.println("New event is being created in the database");
this.setId(event.getId());
System.out.println("ID :: " + event.getId());
//this.setUserId(event.getUserId());
System.out.println("USER_ID :: " + event.getUserId());
this.setSubject(event.getSubject());
System.out.println("SUBJECT :: " + event.getStartTime());
if (event.getLocation() != null)
this.setLocation(event.getLocation());
System.out.println("LOCATION :: " + event.getLocation());
this.setDate(event.getDate());
System.out.println("DATE :: " + event.getDate());
this.setStartTime(event.getStartTime());
System.out.println("START_TIME :: " + event.getStartTime());
this.setEndTime(event.getEndTime());
System.out.println("END_TIME :: " + event.getEndTime());
if (event.getBody() != null)
this.setBody(event.getBody());
System.out.println("BODY :: " + event.getBody());
if (event.getComment() != null)
this.setComment(event.getComment());
System.out.println("COMMENT :: " + event.getComment());
return null;
}
public void ejbPostCreate(common.bean.EventBean event)
throws javax.ejb.CreateException {
}
/**
* ejbActivate
*/
public void ejbActivate() {
}
/**
* ejbLoad
*/
public void ejbLoad() {
}
/**
* ejbPassivate
*/
public void ejbPassivate() {
}
/**
* ejbRemove
*/
public void ejbRemove() throws javax.ejb.RemoveException {
}
/**
* ejbStore
*/
public void ejbStore() {
}
/**
* Get accessor for persistent attribute: id
*/
public abstract java.lang.String getId();
/**
* Set accessor for persistent attribute: id
*/
public abstract void setId(java.lang.String newId);
/**
* Get accessor for persistent attribute: userId
*/
public abstract java.lang.String getUserId();
/**
* Set accessor for persistent attribute: userId
*/
public abstract void setUserId(java.lang.String newUserId);
/**
* Get accessor for persistent attribute: subject
*/
public abstract java.lang.String getSubject();
/**
* Set accessor for persistent attribute: subject
*/
public abstract void setSubject(java.lang.String newSubject);
/**
* Get accessor for persistent attribute: location
*/
public abstract java.lang.String getLocation();
/**
* Set accessor for persistent attribute: location
*/
public abstract void setLocation(java.lang.String newLocation);
/**
* Get accessor for persistent attribute: date
*/
public abstract java.lang.String getDate();
/**
* Set accessor for persistent attribute: date
*/
public abstract void setDate(java.lang.String newDate);
/**
* Get accessor for persistent attribute: startTime
*/
public abstract java.lang.String getStartTime();
/**
* Set accessor for persistent attribute: startTime
*/
public abstract void setStartTime(java.lang.String newStartTime);
/**
* Get accessor for persistent attribute: endTime
*/
public abstract java.lang.String getEndTime();
/**
* Set accessor for persistent attribute: endTime
*/
public abstract void setEndTime(java.lang.String newEndTime);
/**
* Get accessor for persistent attribute: body
*/
public abstract java.lang.String getBody();
/**
* Set accessor for persistent attribute: body
*/
public abstract void setBody(java.lang.String newBody);
/**
* Get accessor for persistent attribute: comment
*/
public abstract java.lang.String getComment();
/**
* Set accessor for persistent attribute: comment
*/
public abstract void setComment(java.lang.String newComment);
}
package entity;
/**
* Bean implementation class for Enterprise Bean: User
*/
public abstract class UserBean implements javax.ejb.EntityBean {
private javax.ejb.EntityContext myEntityCtx;
/**
* setEntityContext
*/
public void setEntityContext(javax.ejb.EntityContext ctx) {
myEntityCtx = ctx;
}
/**
* getEntityContext
*/
public javax.ejb.EntityContext getEntityContext() {
return myEntityCtx;
}
/**
* unsetEntityContext
*/
public void unsetEntityContext() {
myEntityCtx = null;
}
/**
* ejbCreate
*/
public java.lang.String ejbCreate(java.lang.String userId)
throws javax.ejb.CreateException {
setUserId(userId);
return null;
}
/**
* ejbPostCreate
*/
public void ejbPostCreate(java.lang.String userId)
throws javax.ejb.CreateException {
}
/**
* ejbActivate
*/
public void ejbActivate() {
}
/**
* ejbLoad
*/
public void ejbLoad() {
}
/**
* ejbPassivate
*/
public void ejbPassivate() {
}
/**
* ejbRemove
*/
public void ejbRemove() throws javax.ejb.RemoveException {
}
/**
* ejbStore
*/
public void ejbStore() {
}
/**
* Get accessor for persistent attribute: userId
*/
public abstract java.lang.String getUserId();
/**
* Set accessor for persistent attribute: userId
*/
public abstract void setUserId(java.lang.String newUserId);
/**
* Get accessor for persistent attribute: password
*/
public abstract java.lang.String getPassword();
/**
* Set accessor for persistent attribute: password
*/
public abstract void setPassword(java.lang.String newPassword);
/**
* Get accessor for persistent attribute: lastName
*/
public abstract java.lang.String getLastName();
/**
* Set accessor for persistent attribute: lastName
*/
public abstract void setLastName(java.lang.String newLastName);
/**
* Get accessor for persistent attribute: firstName
*/
public abstract java.lang.String getFirstName();
/**
* Set accessor for persistent attribute: firstName
*/
public abstract void setFirstName(java.lang.String newFirstName);
/**
* Get accessor for persistent attribute: gender
*/
public abstract java.lang.String getGender();
/**
* Set accessor for persistent attribute: gender
*/
public abstract void setGender(java.lang.String newGender);
/**
* Get accessor for persistent attribute: birthDate
*/
public abstract java.lang.String getBirthDate();
/**
* Set accessor for persistent attribute: birthDate
*/
public abstract void setBirthDate(java.lang.String newBirthDate);
/**
* Get accessor for persistent attribute: street
*/
public abstract java.lang.String getStreet();
/**
* Set accessor for persistent attribute: street
*/
public abstract void setStreet(java.lang.String newStreet);
/**
* Get accessor for persistent attribute: houseNrNum
*/
public abstract java.lang.Integer getHouseNrNum();
/**
* Set accessor for persistent attribute: houseNrNum
*/
public abstract void setHouseNrNum(java.lang.Integer newHouseNrNum);
/**
* Get accessor for persistent attribute: houseNrAlpha
*/
public abstract java.lang.String getHouseNrAlpha();
/**
* Set accessor for persistent attribute: houseNrAlpha
*/
public abstract void setHouseNrAlpha(java.lang.String newHouseNrAlpha);
/**
* Get accessor for persistent attribute: postalCodeNum
*/
public abstract java.lang.Integer getPostalCodeNum();
/**
* Set accessor for persistent attribute: postalCodeNum
*/
public abstract void setPostalCodeNum(java.lang.Integer newPostalCodeNum);
/**
* Get accessor for persistent attribute: postalCodeAlpha
*/
public abstract java.lang.String getPostalCodeAlpha();
/**
* Set accessor for persistent attribute: postalCodeAlpha
*/
public abstract void setPostalCodeAlpha(
java.lang.String newPostalCodeAlpha);
/**
* Get accessor for persistent attribute: city
*/
public abstract java.lang.String getCity();
/**
* Set accessor for persistent attribute: city
*/
public abstract void setCity(java.lang.String newCity);
/**
* Get accessor for persistent attribute: country
*/
public abstract java.lang.String getCountry();
/**
* Set accessor for persistent attribute: country
*/
public abstract void setCountry(java.lang.String newCountry);
/**
* This method was generated for supporting the relationship role named event.
* It will be deleted/edited when the relationship is deleted/edited.
*/
public abstract java.util.Collection getEvents();
/**
* This method was generated for supporting the relationship role named event.
* It will be deleted/edited when the relationship is deleted/edited.
*/
public abstract void setEvents(java.util.Collection anEvent);
}
<?xml version="1.0" encoding="UTF-8"?>
< !DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "
http://java.sun.com/dtd/ejb-jar_2_0.dtd">
<ejb-jar id="ejb-jar_ID">
<display-name>PersonalPlannerEJB</display-name>
<enterprise-beans>
<session id="CalendarFacade">
<ejb-name>CalendarFacade</ejb-name>
<home>session.CalendarFacadeHome</home>
<remote>session.CalendarFacade</remote>
<local-home>session.CalendarFacadeLocalHome</local-home>
<local>session.CalendarFacadeLocal</local>
<ejb-class>session.CalendarFacadeBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
<ejb-local-ref id="EJBLocalRef_1040332897235">
<description></description>
<ejb-ref-name>ejb/LocalEvent</ejb-ref-name>
<ejb-ref-type>Entity</ejb-ref-type>
<local-home>entity.EventLocalHome</local-home>
<local>entity.EventLocal</local>
<ejb-link>Event</ejb-link>
</ejb-local-ref>
<ejb-local-ref id="EJBLocalRef_1040335538924">
<description></description>
<ejb-ref-name>ejb/LocalUser</ejb-ref-name>
<ejb-ref-type>Entity</ejb-ref-type>
<local-home>entity.UserLocalHome</local-home>
<local>entity.UserLocal</local>
<ejb-link>User</ejb-link>
</ejb-local-ref>
</session>
<session id="LoginFacade">
<ejb-name>LoginFacade</ejb-name>
<home>session.LoginFacadeHome</home>
<remote>session.LoginFacade</remote>
<local-home>session.LoginFacadeLocalHome</local-home>
<local>session.LoginFacadeLocal</local>
<ejb-class>session.LoginFacadeBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
<ejb-local-ref id="EJBLocalRef_1039983293063">
<description></description>
<ejb-ref-name>ejb/LocalUser</ejb-ref-name>
<ejb-ref-type>Entity</ejb-ref-type>
<local-home>entity.UserLocalHome</local-home>
<local>entity.UserLocal</local>
<ejb-link>User</ejb-link>
</ejb-local-ref>
</session>
<entity id="User">
<ejb-name>User</ejb-name>
<local-home>entity.UserLocalHome</local-home>
<local>entity.UserLocal</local>
<ejb-class>entity.UserBean</ejb-class>
<persistence-type>Container</persistence-type>
<prim-key-class>java.lang.String</prim-key-class>
<reentrant>False</reentrant>
<cmp-version>2.x</cmp-version>
<abstract-schema-name>User</abstract-schema-name>
<cmp-field id="CMPAttribute_1039982972362">
<field-name>userId</field-name>
</cmp-field>
<cmp-field id="CMPAttribute_1039982975817">
<field-name>password</field-name>
</cmp-field>
<cmp-field id="CMPAttribute_1039982978932">
<field-name>lastName</field-name>
</cmp-field>
<cmp-field id="CMPAttribute_1039982982357">
<field-name>firstName</field-name>
</cmp-field>
<cmp-field id="CMPAttribute_1039982985481">
<field-name>gender</field-name>
</cmp-field>
<cmp-field id="CMPAttribute_1039982988435">
<field-name>birthDate</field-name>
</cmp-field>
<cmp-field id="CMPAttribute_1039982991480">
<field-name>street</field-name>
</cmp-field>
<cmp-field id="CMPAttribute_1039982994504">
<field-name>houseNrNum</field-name>
</cmp-field>
<cmp-field id="CMPAttribute_1039982997468">
<field-name>houseNrAlpha</field-name>
</cmp-field>
<cmp-field id="CMPAttribute_1039983000372">
<field-name>postalCodeNum</field-name>
</cmp-field>
<cmp-field id="CMPAttribute_1039983003237">
<field-name>postalCodeAlpha</field-name>
</cmp-field>
<cmp-field id="CMPAttribute_1039983005880">
<field-name>city</field-name>
</cmp-field>
<cmp-field id="CMPAttribute_1039983008664">
<field-name>country</field-name>
</cmp-field>
<primkey-field>userId</primkey-field>
<ejb-local-ref id="EJBLocalRef_1042578719424">
<ejb-ref-name>ejb/Event</ejb-ref-name>
<ejb-ref-type>Entity</ejb-ref-type>
<local-home>entity.EventLocalHome</local-home>
<local>entity.EventLocal</local>
<ejb-link>Event</ejb-link>
</ejb-local-ref>
</entity>
<entity id="Event">
<ejb-name>Event</ejb-name>
<local-home>entity.EventLocalHome</local-home>
<local>entity.EventLocal</local>
<ejb-class>entity.EventBean</ejb-class>
<persistence-type>Container</persistence-type>
<prim-key-class>java.lang.String</prim-key-class>
<reentrant>False</reentrant>
<cmp-version>2.x</cmp-version>
<abstract-schema-name>Event</abstract-schema-name>
<cmp-field id="CMPAttribute_1042578642103">
<field-name>id</field-name>
</cmp-field>
<cmp-field id="CMPAttribute_1042578607042">
<field-name>userId</field-name>
</cmp-field>
<cmp-field id="CMPAttribute_1042578642104">
<field-name>subject</field-name>
</cmp-field>
<cmp-field id="CMPAttribute_1042578642113">
<field-name>location</field-name>
</cmp-field>
<cmp-field id="CMPAttribute_1042578642183">
<field-name>date</field-name>
</cmp-field>
<cmp-field id="CMPAttribute_1042578610567">
<field-name>startTime</field-name>
</cmp-field>
<cmp-field id="CMPAttribute_1042578614042">
<field-name>endTime</field-name>
</cmp-field>
<cmp-field id="CMPAttribute_1042578642184">
<field-name>body</field-name>
</cmp-field>
<cmp-field id="CMPAttribute_1042578642193">
<field-name>comment</field-name>
</cmp-field>
<primkey-field>id</primkey-field>
<ejb-local-ref id="EJBLocalRef_1042578719434">
<ejb-ref-name>ejb/User</ejb-ref-name>
<ejb-ref-type>Entity</ejb-ref-type>
<local-home>entity.UserLocalHome</local-home>
<local>entity.UserLocal</local>
<ejb-link>User</ejb-link>
</ejb-local-ref>
<query>
<description></description>
<query-method>
<method-name>findEvents</method-name>
<method-params>
<method-param>java.lang.String</method-param>
<method-param>java.lang.String</method-param>
</method-params>
</query-method>
<ejb-ql>select object(o) from Event o where o.userId = ?1 and o.date = ?2</ejb-ql>
</query>
</entity>
</enterprise-beans>
<relationships>
<ejb-relation>
<description></description>
<ejb-relation-name>User-Events</ejb-relation-name>
<ejb-relationship-role id="EJBRelationshipRole_1042578730169">
<ejb-relationship-role-name>user</ejb-relationship-role-name>
<multiplicity>Many</multiplicity>
<relationship-role-source>
<ejb-name>Event</ejb-name>
</relationship-role-source>
</ejb-relationship-role>
<ejb-relationship-role id="EJBRelationshipRole_1042578733845">
<ejb-relationship-role-name>event</ejb-relationship-role-name>
<multiplicity>One</multiplicity>
<relationship-role-source>
<ejb-name>User</ejb-name>
</relationship-role-source>
<cmr-field>
<cmr-field-name>events</cmr-field-name>
<cmr-field-type>java.util.Collection</cmr-field-type>
</cmr-field>
</ejb-relationship-role>
</ejb-relation>
</relationships>
<assembly-descriptor>
<container-transaction>
<method>
<ejb-name>CalendarFacade</ejb-name>
<method-name>*</method-name>
</method>
<method>
<ejb-name>LoginFacade</ejb-name>
<method-name>*</method-name>
</method>
<trans-attribute>RequiresNew</trans-attribute>
</container-transaction>
<container-transaction>
<method>
<ejb-name>User</ejb-name>
<method-intf>LocalHome</method-intf>
<method-name>*</method-name>
</method>
<trans-attribute>Required</trans-attribute>
</container-transaction>
<container-transaction>
<method>
<ejb-name>Event</ejb-name>
<method-intf>LocalHome</method-intf>
<method-name>*</method-name>
</method>
<trans-attribute>Required</trans-attribute>
</container-transaction>
</assembly-descriptor>
</ejb-jar>