Quantcast

CMP exception: Attempt to cast instance "xxx [java.lang.String]" to PersistenceCapable failed. Ensure that it has been enhanced.

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

CMP exception: Attempt to cast instance "xxx [java.lang.String]" to PersistenceCapable failed. Ensure that it has been enhanced.

Phili
Hi

i've been playing around with a test project consisting of
a cmp entity bean and a simple 1-method-webservice trying to persist on instance of that entity.

deployment of the classes went well but i couldnt get an entity-instance persisted.

the entity class look something like this

@Entity
@Table(name="SOMETABLE")
public class EntityClass implements Serializable
{
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	public int id;
	@Column(length=100)
	public String name;
	
	int getId()
	{
		return id;
	}
	
	void setId(int id)
	{
		this.id = id;
	}
	
	String getName()
	{
		return name;
	}
	
	void setName(String name)
	{
		this.name = name;
	}
}
whereas the webservice implementation is
@Stateless
@WebService(serviceName = "TestWS",
            portName = "TestWSPort",
            endpointInterface = "xxxx",
            targetNamespace = "xxx")
public class TestWSBean implements TestWS {
	
	@PersistenceContext(unitName="TestPU")
	private EntityManager em;

	public String saveName(String value)
	{
		String result = "ok";
		
		try {
			EntityClass b = new EntityClass();
			b.setName(value);
			em.persist(value);	
		}
		catch(Exception ex) {
			ex.printStackTrace();
			result = ex.getLocalizedMessage() + " " + ex.getClass().getName();	
		}
		
		return result;
	}
}
Calling the webservice-method from within the eclipse ws-explorer i get the following message:

Attempt to cast instance "abc [java.lang.String]" to PersistenceCapable failed. Ensure that it has been enhanced. org.apache.openjpa.persistence.ArgumentException

geronimo is 2.1.3.

Kind regards

Phil

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: CMP exception: Attempt to cast instance "xxx [java.lang.String]" to PersistenceCapable failed. Ensure that it has been enhanced.

David Blevins

On Mar 10, 2009, at 7:55 AM, Phili wrote:

> @Stateless
> @WebService(serviceName = "TestWS",
>             portName = "TestWSPort",
>             endpointInterface = "xxxx",
>             targetNamespace = "xxx")
> public class TestWSBean implements TestWS {
>
> @PersistenceContext(unitName="TestPU")
> private EntityManager em;
>
> public String saveName(String value)
> {
> String result = "ok";
>
> try {
> EntityClass b = new EntityClass();
> b.setName(value);
> em.persist(value);
> }
> catch(Exception ex) {
> ex.printStackTrace();
> result = ex.getLocalizedMessage() + " " + ex.getClass().getName();
> }
>
> return result;
> }
> }
>
Looks like you have a typo in your code.   s/em.persist(value)/
em.persist(b)/

Happens to the best of us :)

-David

Loading...