Hi,
we use OpenJPA in WebLogic 10.0 server but we have experience in other
JPA implementations (TopLink and Hibernate). OpenJPA is very good
implementation, but we have one problem (for test I try to use 1.0.1
version). OpenJPA can not use detached instances as parameters in
queries. There is test scenario:
1) Entity:
@Entity
public class PersonEntity {
@Id
private Long id;
private String name;
...
}
2) Query:
List<?> list = em.createQuery("SELECT o FROM PersonEntity o WHERE o =
?1").setParameter(1, pe).getResultList();
3) 'pe' instance
if I use detached instance with id=100
the query failed with exception
<openjpa-1.0.1-r420667:592145 nonfatal user error>
org.apache.openjpa.persistence.ArgumentException: null
at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:808)
...
Caused by: java.lang.UnsupportedOperationException
at
org.apache.openjpa.kernel.DetachedStateManager.fetch(DetachedStateManager.java:922)
if I use new instance
PersonEntity pe = new PersonEntity();
pe.setId(100L);
the query return list but don't return any instance
Both Hibernate and Toplink return correct managed instance of
PersonEntity for both types of parametr values. For resolving condition
in query
SELECT o FROM PersonEntity o WHERE o = ?1
is needed only entity id of parametr ?1 and in both detached and new
instance is id defined.
We must use operation em.find(PersonEntity.class, pe.getId()); which is
not good for performance.
Is this prefered behavior in OpenJPA or is there way to resolve this
issue in next releases?
With regards
Zdenek Machac
Masaryk University, Brno, Czech Republic