aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes enhancement ?? ejb3 entity Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Reply locked New topic
Author

enhancement ?? ejb3 entity

U Kvistborg
Greenhorn

Joined: Oct 14, 2002
Posts: 29
Problem with my first ejb3 entity.

Hi I have just attempted to make my first ejb3 entity, but I get an error stating that it have not been enhanced. and I have no idea of what it is talking about ?
I have tried to search for an answer but still been unable to find any.

I get this error.

[09-03-19 09:19:50:380 CET] 00000026 SystemOut O StatelessUserBean:increment - caught unexpected exception: <openjpa-1.0.3-SNAPSHOT-r420667:649224 nonfatal user error> org.apache.openjpa.persistence.ArgumentException: Attempt to cast instance "com.incase.orp.ejb.cmp.JPAUserEntity@3b983b98" to PersistenceCapable failed. Ensure that it has been enhanced.
FailedObject: com.incase.orp.ejb.cmp.JPAUserEntity@3b983b98
[09-03-19 09:19:50:380 CET] 00000026 SystemErr are <openjpa-1.0.3-SNAPSHOT-r420667:649224 nonfatal user error> org.apache.openjpa.persistence.ArgumentException: Attempt to cast instance "com.incase.orp.ejb.cmp.JPAUserEntity@3b983b98" to PersistenceCapable failed. Ensure that it has been enhanced.
FailedObject: com.incase.orp.ejb.cmp.JPAUserEntity@3b983b98
[09-03-19 09:19:50:380 CET] 00000026 SystemErr are at org.apache.openjpa.kernel.BrokerImpl.assertPersistenceCapable(BrokerImpl.java:4286)
[09-03-19 09:19:50:380 CET] 00000026 SystemErr are at org.apache.openjpa.kernel.BrokerImpl.persist(BrokerImpl.java:2365)
[09-03-19 09:19:50:380 CET] 00000026 SystemErr are at org.apache.openjpa.kernel.BrokerImpl.persist(BrokerImpl.java:2225)
[09-03-19 09:19:50:380 CET] 00000026 SystemErr are at org.apache.openjpa.kernel.DelegatingBroker.persist(DelegatingBroker.java:1005)
[09-03-19 09:19:50:380 CET] 00000026 SystemErr are at org.apache.openjpa.persistence.EntityManagerImpl.persist(EntityManagerImpl.java:541)
[09-03-19 09:19:50:380 CET] 00000026 SystemErr are at com.ibm.ws.jpa.management.JPAExEmInvocation.persist(JPAExEmInvocation.java:348)
[09-03-19 09:19:50:380 CET] 00000026 SystemErr are at com.ibm.ws.jpa.management.JPAEntityManager.persist(JPAEntityManager.java:109)
[09-03-19 09:19:50:380 CET] 00000026 SystemErr are at com.incase.orp.ejb.cmp.UsersSessionBean.update(UsersSessionBean.java:51)
[09-03-19 09:19:50:380 CET] 00000026 SystemErr are at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[09-03-19 09:19:50:380 CET] 00000026 SystemErr are at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:79)
[09-03-19 09:19:50:380 CET] 00000026 SystemErr are at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[09-03-19 09:19:50:380 CET] 00000026 SystemErr are at java.lang.reflect.Method.invoke(Method.java:618)
[09-03-19 09:19:50:380 CET] 00000026 SystemErr are at com.ibm.ejs.container.interceptors.InvocationContextImpl.proceed(InvocationContextImpl.java:547)
[09-03-19 09:19:50:380 CET] 00000026 SystemErr are at com.incase.orp.ejb.cmp.Audit.methodChecker(Audit.java:15)

I have this method in a session bean:
@Stateless
@Interceptors(Audit.class)
public class UsersSessionBean implements LocalUser, RemoteUser {

@PersistenceContext (unitName="User")
private EntityManager em;

public void update(Long id,
String userid,
String password,
String fname,
String lname,
String role1,
String loginstatus,
String email,
String country,
Long partner)
{

try {

JPAUserEntity user = null;//em.find(JPAUserEntity.class, id);

if ( user == null ){
user = new JPAUserEntity();
user.setId(System.currentTimeMillis());
user.setUserid(userid);
user.setPassword(password);
user.setFname(fname);
user.setLname(lname);
user.setRole1(role1);
user.setLoginstatus(loginstatus);
user.setEmail(email);
user.setCountry(country);
user.setPartner(partner);
em.persist( user );
} else{
user.setUserid(userid);
user.setPassword(password);
user.setFname(fname);
user.setLname(lname);
user.setRole1(role1);
user.setLoginstatus(loginstatus);
user.setEmail(email);
user.setCountry(country);
user.setPartner(partner);
em.persist( user );
}

em.flush();
em.clear();

} catch (Throwable t) {
System.out.println("StatelessUserBean:increment - caught unexpected exception: " + t);
t.printStackTrace();
}

return;
}

and my interceptor is

public class Audit implements Serializable {

private static final long serialVersionUID = 4267181799103606230L;

@AroundInvoke
public Object methodChecker(InvocationContext ic) throws Exception {
System.out.println("Audit:methodChecker - About to execute method: "
+ ic.getMethod());
Object result = ic.proceed();
return result;
}
}
and my bean is like this:

@Entity
@Table(name="USERS")
public class JPAUserEntity {
private static final long serialVersionUID = 1L;

@Id
private Long id;

private String userid;
private String password;
private String fname;
private String lname;
private String role1;
private String loginstatus;
private String email;
private String country;
private Long partner;


public void setId( Long newKey )
{
System.out.println ("JPAUserEntity:setPrimaryKey = '" + newKey + "'");
id = newKey;
}

public Long getId()
{
System.out.println ("JPAUserEntity:getPrimaryKey = '" + id + "'");
return id;
}
and with getters and setters for the rest of the fields aswell making them into the bean properties.

and my persistence xml looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="User">
<jta-data-source>jdbc/ISSDS</jta-data-source>
<class>com.incase.orpejb.cmp.JPAUserEntity</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
</persistence-unit>
</persistence>

I call it from a servlet, and this call seems to be fine, it is only in the em.persist that seems to fail, and I am at a loss as to why ?? and what is this enhancement the error is talking about ?


SCJP 1.4/1.5, SCWCD 1.4, SCBCD 1.3
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10207
    
166

Duplicate of http://www.coderanch.com/t/436760/Object-Relational-Mapping/java/enhancement-ejb-entity


[My Blog] [JavaRanch Journal]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: enhancement ?? ejb3 entity