users@glassfish.java.net

Re: exception inserted a deleted entity

From: <glassfish_at_javadesktop.org>
Date: Tue, 22 May 2007 02:24:13 PDT

> em.cache()?

First of all I cannot see this function?

> Does remote EJB call mean a new EM and a new
> transaction?

Yes. I think i've been a bit confused by how the EM works. EJB call is a remote call to a SLSB, within which i create an EntityManager using injection. The transaction level is set to the container default, which from studying it means it creates a new transaction around the inserts but doesn't use a transaction for the selects.


> Do you use a native query or a JPQL query to clear
> the database? If it's the latter, TopLink should mark
> the affected entities in the EMF (2-nd level global
> for all EMs in this EMF) cache as invalid. If this
> doesn't happen, it's a bug. But if you use a native
> query, it just goes to the database, and the EMF
> cache is not being updated, so that the next time you
> try to persist an entity with the id that existed in
> the previous run, TopLink code will still find it in
> the EMF cache and report a problem.


I believe the delete query is in JPQL as it is created by using

[i]@NamedQuery (name="deleteQ", query="DELETE FROM yyy WHERE xxx");
[/i]
and called by
[i]
@PersistenceContext
private EntityManager em;

public void func(){
  em.createNamedQuery("deleteQ").executeUpdate();
}[/i]

but i could be wrong. I thought i had to use @NamedNativeQuery or em.createNativeQuery to execute a native query?
[Message sent by forum member 'jsl123' (jsl123)]

http://forums.java.net/jive/thread.jspa?messageID=218280