You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by chintan4181 <ch...@gmail.com> on 2011/04/04 17:54:01 UTC

Need help to understand how getDirtyObjects() works.

Hi,

In my project we are exposing stateless ejb and exposed to other system as a
web service. it has CRUD operations. During Read operation, i am fetching
object from database. and make a change in this object. After that i am
calling Update operation to check whether there are any dirty objects or
not. But it doesn't give me any dirty objects. My code snippet is as below:

//get the entity manager using @persistentcontext
@PersistentContext
private EntityManager em;    		

Read():Loan loan = (Loan) em.createNamedQuery("findByCert_ID", Loan.class)
    				     .setParameter("Cert_ID", certId)
    				     .getSingleResult();
loan.setLoan_Amount(200000);

Update():
    	OpenJPAEntityManager oem = OpenJPAPersistence.cast(em); 
	
		Collection dirtyObjects =oem.getDirtyObjects();
		LOG.info("Dirty Objects:" +dirtyObjects.size()); //this prints 0

I am getting collection.size = 0. 
Doest the EntityManager(em) is closed after read operation? Can somebody
explain me? How do i know which objects are dirty in update()?


Thanks
chintan

--
View this message in context: http://openjpa.208410.n2.nabble.com/Need-help-to-understand-how-getDirtyObjects-works-tp6239101p6239101.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: Need help to understand how getDirtyObjects() works.

Posted by Michael Dick <mi...@gmail.com>.
Hi Chintan,


What you're trying to do is (in my opinion) a gray area. You have a
stateless EJB, but are expecting the EntityManager to track the state of a
set of entities between method calls. If you start a transaction before
calling read() and that transaction is still active when you call update()
your scenario might work. It depends on the application server to associate
a specific EntityManager instance with a transaction (I think most app
servers do this but I could be all wet).

In general if you want an EntityManager to track a set of entities across
method invocations I find it more intuitive to use a Stateful bean, which
guarantees that the same instance of the bean (and EntityManager) will be
used throughout a conversation.

Hope this helps,
-mike


On Wed, Apr 6, 2011 at 11:51 PM, chintan4181 <ch...@gmail.com> wrote:

> Read and Update are two functions exposed as a part of web service.
>
> In first step web service client call read service to get the data.
> in second step it may update values and call update service. and both of
> these methods are part of @stateless EJB.
>
> I think they will not part of same entity. please correct me if i m wrong.
>
> What should be the approach to identify dirty fields/objects?
>
> Thanks
> chintan
>
>
> --
> View this message in context:
> http://openjpa.208410.n2.nabble.com/Need-help-to-understand-how-getDirtyObjects-works-tp6239101p6248646.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>

Re: Need help to understand how getDirtyObjects() works.

Posted by chintan4181 <ch...@gmail.com>.
Read and Update are two functions exposed as a part of web service. 

In first step web service client call read service to get the data.
in second step it may update values and call update service. and both of
these methods are part of @stateless EJB. 

I think they will not part of same entity. please correct me if i m wrong.

What should be the approach to identify dirty fields/objects?

Thanks
chintan


--
View this message in context: http://openjpa.208410.n2.nabble.com/Need-help-to-understand-how-getDirtyObjects-works-tp6239101p6248646.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: Need help to understand how getDirtyObjects() works.

Posted by Rick Curtis <cu...@gmail.com>.
Are your Read operations and Update operations using the same Entity
manager? Why do you need access to the dirty objects anyway?

Thanks,
Rick

On Mon, Apr 4, 2011 at 10:54 AM, chintan4181 <ch...@gmail.com> wrote:

> Hi,
>
> In my project we are exposing stateless ejb and exposed to other system as
> a
> web service. it has CRUD operations. During Read operation, i am fetching
> object from database. and make a change in this object. After that i am
> calling Update operation to check whether there are any dirty objects or
> not. But it doesn't give me any dirty objects. My code snippet is as below:
>
> //get the entity manager using @persistentcontext
> @PersistentContext
> private EntityManager em;
>
> Read():Loan loan = (Loan) em.createNamedQuery("findByCert_ID", Loan.class)
>                                     .setParameter("Cert_ID", certId)
>                                     .getSingleResult();
> loan.setLoan_Amount(200000);
>
> Update():
>        OpenJPAEntityManager oem = OpenJPAPersistence.cast(em);
>
>                Collection dirtyObjects =oem.getDirtyObjects();
>                LOG.info("Dirty Objects:" +dirtyObjects.size()); //this
> prints 0
>
> I am getting collection.size = 0.
> Doest the EntityManager(em) is closed after read operation? Can somebody
> explain me? How do i know which objects are dirty in update()?
>
>
> Thanks
> chintan
>

Re: Need help to understand how getDirtyObjects() works.

Posted by chintan4181 <ch...@gmail.com>.
One more clarification. I am using field level access.

--
View this message in context: http://openjpa.208410.n2.nabble.com/Need-help-to-understand-how-getDirtyObjects-works-tp6239101p6239164.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.