You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by elkhawajah <el...@gmail.com> on 2010/08/21 17:24:55 UTC

entityManager.merge


@Transactional
public void createMessageType(MessageType messageType){
            getEntityManager().merge(messageType);
            getEntityManager().flush();
}

1) I am trying to write a failure test for the code above, what I am doing
is that I am passing non-existing entity to merge method.

I am getting InvalidStateException when flush method is called, my question
is shouldn't merge throw IllegalArgumentException when trying to merging
non-existing entity? why I am getting InvalidStateException?

2) I am using @Transactional annotation in the method above, but I found
that I must invoke flush explicitly, shouldn't that annotation handle
flushing instead of calling flush method explicitly?

I have uploaded 
http://openjpa.208410.n2.nabble.com/file/n5447762/persistence.xml
persistence.xml , and 
http://openjpa.208410.n2.nabble.com/file/n5447762/applicationContext.xml
applicationContext.xml .

Thx!
-- 
View this message in context: http://openjpa.208410.n2.nabble.com/entityManager-merge-tp5447762p5447762.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: entityManager.merge

Posted by Kevin Sutter <kw...@gmail.com>.
Hi elkhawaja,
According to the spec and our javadoc [1], you are correct.  We should be
issuing the illegalArgumentException instead of the IllegalStateException.
I'm surprised that we don't have a unit test for this situation.  Is it
possible for you to provide a testcase that demonstrates this?  Just to make
sure that we're talking about the same situation.

OpenJPA documents their APIs via javadoc [2].  When we extend the standard
JPA interfaces, we'll document the new methods and requirements via updated
javadoc.  But, when we use the standard JPA interfaces, then we'll refer
back to the javax.persistence.* package.

Additional information on OpenJPA's functionality can be found in our online
manual [3].

Depending on the application server in use, the @Transactional should be
providing the proper transactional context and there should be no reason to
explicitly invoke flush().  That is more of a question of the application
server providing this functionality, rather than the JPA provider.  Are you
indicating that this same application in the same application server is
working as expected with other JPA providers (in the context of the
transaction)?

Thanks,
Kevin


[1]
http://download.oracle.com/javaee/6/api/javax/persistence/EntityManager.html#merge(T)
[2]
http://openjpa.apache.org/builds/2.0.0/apache-openjpa-2.0.0/docs/javadoc/index.html
[3]  http://openjpa.apache.org/documentation.html

On Sat, Aug 21, 2010 at 10:45 AM, elkhawajah <el...@gmail.com> wrote:

>
> 3) I don't know why I am not getting the exception as documented in
>
> http://download.oracle.com/javaee/5/api/javax/persistence/EntityManager.html#merge(T)<http://download.oracle.com/javaee/5/api/javax/persistence/EntityManager.html#merge%28T%29>
> .
>
> Does OpenJPA override these excpetions? as I recall in Hibernate, that if I
> passed non-existing component to merge method, I will get
> IllegalArgumentException, but heere I am getting InvalidStateException when
> calling flush.
>
> Also, unfortunatelly, I am not able to find a comprehensive documentation
> about the thrown exception from EntityManagerImpl of OpenJPA.
> --
> View this message in context:
> http://openjpa.208410.n2.nabble.com/entityManager-merge-tp5447762p5447804.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>

Re: entityManager.merge

Posted by elkhawajah <el...@gmail.com>.
3) I don't know why I am not getting the exception as documented in
http://download.oracle.com/javaee/5/api/javax/persistence/EntityManager.html#merge(T).

Does OpenJPA override these excpetions? as I recall in Hibernate, that if I
passed non-existing component to merge method, I will get
IllegalArgumentException, but heere I am getting InvalidStateException when
calling flush.

Also, unfortunatelly, I am not able to find a comprehensive documentation
about the thrown exception from EntityManagerImpl of OpenJPA.
-- 
View this message in context: http://openjpa.208410.n2.nabble.com/entityManager-merge-tp5447762p5447804.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.