EJB 3 and JPA: Hibernate query not serializable?

akn

Grünschnabel
Hey guys,
Im pretty new to this, so Im trying to post everything you need to understand my problem:

Im playing around with EJB 3, especially JPA. I have a Session bean that searches for a persistent entity with the JPQL query:

Code:
SELECT x FROM SomeEntity x WHERE x.name = :name

name is replaced by the name that should be in the db. SomeEnttiy is the CLASSNAME of the persistent entity, not the name of the table in the db (just found out that you have to do that this way). The persistent entity has a property

Code:
private String name;

the db table contains a column with the same name. I call the session bean with an RMI client and get this exception:

Code:
Exception in thread "main" javax.ejb.EJBException: java.lang.IllegalArgumentException: org.hibernate.ejb.QueryImpl cannot be cast to java.io.Serializable
	at org.jboss.ejb3.tx.Ejb3TxPolicy.handleExceptionInOurTx(Ejb3TxPolicy.java:63)
	at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:83)
.........

Caused by: java.lang.IllegalArgumentException: org.hibernate.ejb.QueryImpl cannot be cast to java.io.Serializable
	at org.hibernate.ejb.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:191)
...........

Caused by: java.lang.ClassCastException: org.hibernate.ejb.QueryImpl cannot be cast to java.io.Serializable
	at org.hibernate.ejb.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:174)


I dont understand why it should be serializable at all. The client doesnt see the query, since it is used this way:



Code:
public String doStuff()
    {
    		addEntities();
    		findEntities();
    }



private void findEntities() 
    {
    	Query q = em.createQuery("SELECT x FROM SomeEntity x WHERE x.name = :name").setParameter("name", "Egon1");

    	SomeEntity se = em.find(SomeEntity.class, q);
	System.out.println((se == null ? "null" : se.getName()));
	
	se.setName("Egon2");
	em.merge(se);
	q = em.createQuery("SELECT x FROM SomeEntity x WHERE x.name = :name").setParameter("name", "Egon2");
	se = em.find(SomeEntity.class, q);
	System.out.println((se == null ? "null" : se.getName()));
	se.setName("Egon1");
	em.merge(se);
    }

Why do I get the Exception and how can I fix it?
Thanks in advance for your answers.

Cheers
akn
 

Neue Beiträge

Zurück