CMR java.lang.ClassCastException
vbatista Sep 12, 2002 12:48 PMHello!
I am trying to establish a relationship between two entity beans. Although, when I try to call any of the accessors, I get the following exception:
16:24:46,744 ERROR [LogInterceptor] TransactionRolledbackException, causedBy:
java.lang.ClassCastException: enk.interfaces.PlaceData
at org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMRFieldBridge.setInstance
alue(JDBCCMRFieldBridge.java:624)
at org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMRFieldBridge.setValue(JD
CCMRFieldBridge.java:563)
at org.jboss.ejb.plugins.cmp.bridge.EntityBridgeInvocationHandler.invok
(EntityBridgeInvocationHandler.java:125)
at org.jboss.proxy.compiler.Runtime.invoke(Runtime.java:59)
at enk.entity.PersonCMP$Proxy.setPlace()
....
I am using JBoss 3.0.0 with bundled tomcat 4.0.3. I am using only local interfaces to access the relation methods.
My beans are Person and Place. Each person belongs to one place, and each place can have multiple Persons (1-N).
Person Bean:
/**
*
* @ejb:relation name="Person-Place"
* role-name="Person-Has-One-Place"
* target-multiple="yes"
*
* @jboss:relation related-pk-field="placeId"
* fk-column="pplaceid"
*
* @ejb:interface-method view-type="local"
*
**/
public abstract enk.interfaces.PlaceData getPlace();
/**
* @ejb:interface-method view-type="local"
**/
public abstract void setPlace(enk.interfaces.PlaceData place);
Place Bean:
/**
*
* @ejb:relation name="Person-Place"
* role-name="Place-Has-Many-Addresses"
* @ejb:interface-method view-type="local"
*
**/
public abstract java.util.Set getPersons();
/**
* @ejb:interface-method view-type="local"
*
**/
public abstract void setPersons(java.util.Set persons);
I create persons from a Session Bean through the local interface of the Person bean:
/**
* insertPerson method.
*
* @return an int value.
*
* @ejb:interface-method view-type="local"
*
*/
public int insertPerson(String person, int placeId)
// throws RemoteException
{
int ret = 0;
try {
PlaceData place = getPlace(placeId); //Returns the correct Place object
PersonData lData = null;
Context lContext = new InitialContext();
PersonLocalHome lHome = (PersonLocalHome) lContext.lookup("ejb/test/PersonLocal");
lData = new PersonData();
lData.setName(person);
PersonLocal lEntity = lHome.create( lData, place );
PersonPK pk = (PersonPK) lEntity.getPrimaryKey();
ret = pk.getId();
} catch ( Exception e ) {
e.printStackTrace();
}
return ret;
}
The ejbCreate of the Person Bean is as follows:
public PersonPK ejbCreate(PersonData key, PlaceData place)
throws
InvalidValueException,
EJBException,
CreateException
{
setId(count++);
setName(key.getName());
setPlace(place);
return null;
}
First of all, I create a few places.
When I try to create the one person, I get the exception above.
I would appreciate any help. I am getting crazy .....
Thanks in advance,
Victor Batista