You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@geronimo.apache.org by Phili <ge...@annee.de> on 2009/03/10 15:55:44 UTC

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

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
-- 
View this message in context: http://www.nabble.com/CMP-exception%3A-Attempt-to-cast-instance-%22xxx--java.lang.String-%22-to-PersistenceCapable-failed.--Ensure-that-it-has-been-enhanced.-tp22436043s134p22436043.html
Sent from the Apache Geronimo - Users mailing list archive at Nabble.com.

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

Posted by David Blevins <da...@visi.com>.
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