You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by pbt123 <pr...@in.ibm.com> on 2012/05/16 22:40:47 UTC
entity is not available in memory-repost
Hello,
I am new on OpenJPA....not sure if it has very common solution.
OpenJpa version: 2.1.1
Running on WAS6.1.37
I have 7 entities in a transaction, first set values in Entity A (fields
id=10203, name, pname..... etc ...one record) then B (2 record), C(5
records), E(3 records), F (2 records), G (2 records) entities.
While again setting values in Entity C, it needs previous entered
data(previous 5 records) from
C using custom query.
Query query = em.createQuery( "SELECT z FROM C z where z.id='10203'");
I am using threadLocal to set EntityManager (I have already checked, it is
trying to get data from the same entityManager which has set value in entity
A ). There are lot of business logic involved in between entity A till G.
The problem is, I am not able to get previous data(5 records) from entity C
using the
above SQL. it always return zero result for id=10203.
Can anyone please help?
Many Thanks.
Prabhu
--
View this message in context: http://openjpa.208410.n2.nabble.com/entity-is-not-available-in-memory-repost-tp7562678.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.
AW: entity is not available in memory-repost
Posted by Boblitz John <Jo...@BERTSCHI.com>.
> -----Ursprüngliche Nachricht-----
> Von: pbt123 [mailto:prabhash@in.ibm.com]
> Gesendet: Mittwoch, 16. Mai 2012 23:56
> An: users@openjpa.apache.org
> Betreff: Re: entity is not available in memory-repost
>
> Thanks for reply
>
> First, the 5 records were not committed into database yet,
> these are still in memory as the transaction has not
> completed and I need to get the same 5 record for some
> business validation purpose.
>
> I am using application-managed persistence. My EMF starts as
> soon as someone login to the GUI and EM will create whenever
> we start a new transaction and close after committing the transaction.
>
> I think, I am missing some basic property which hands this
> condition. Could you please point me to the properties?
>
> Thanks
>
>
> --
> View this message in context:
> http://openjpa.208410.n2.nabble.com/entity-is-not-available-in
> -memory-repost-tp7562678p7562793.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>
That is your problem - you can not retrieve something from the Database that is not
In the Database yet!
However, inside your transaction, you should still have the references to the previously
created "C" Objects and you can still use them / change them ...
John
Re: entity is not available in memory-repost
Posted by Kevin Sutter <kw...@gmail.com>.
Is it okay to flush the data to the database first? Flushing still doesn't
commit the data (not until the transaction commits). But, at least the
data would be available for the query. I would promote this processing
first... Doing the in-memory query analysis can be costly...
As I look into this a bit more, the openjpa.FlushBeforeQueries property has
a default value of "true". So, we should already be pushing the data to
the database. Maybe you need to post your persistence.xml to see what type
of environment you are running with. Something isn't making sense yet...
Kevin
On Wed, May 16, 2012 at 4:55 PM, pbt123 <pr...@in.ibm.com> wrote:
> Thanks for reply
>
> First, the 5 records were not committed into database yet, these are still
> in memory as the transaction has not completed and I need to get the same 5
> record for some business validation purpose.
>
> I am using application-managed persistence. My EMF starts as soon as
> someone
> login to the GUI and EM will create whenever we start a new transaction and
> close after committing the transaction.
>
> I think, I am missing some basic property which hands this condition. Could
> you please point me to the properties?
>
> Thanks
>
>
> --
> View this message in context:
> http://openjpa.208410.n2.nabble.com/entity-is-not-available-in-memory-repost-tp7562678p7562793.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>
Re: entity is not available in memory-repost
Posted by pbt123 <pr...@in.ibm.com>.
Thanks for reply
First, the 5 records were not committed into database yet, these are still
in memory as the transaction has not completed and I need to get the same 5
record for some business validation purpose.
I am using application-managed persistence. My EMF starts as soon as someone
login to the GUI and EM will create whenever we start a new transaction and
close after committing the transaction.
I think, I am missing some basic property which hands this condition. Could
you please point me to the properties?
Thanks
--
View this message in context: http://openjpa.208410.n2.nabble.com/entity-is-not-available-in-memory-repost-tp7562678p7562793.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.
Re: entity is not available in memory-repost
Posted by Kevin Sutter <kw...@gmail.com>.
Hi Prabhu,
First question: Are you sure that your database has the 5 previous records
with z.id ='10203'? That is, have you committed your previous transactions
that would ultimately flush your changes to the database?
Since you are using OpenJPA 2.x with WAS v6.1, you must be using
application-managed persistence. (In order to use container-managed
persistence with OpenJPA 2.x, you would need the OSGi/JPA 2.0 Feature Pack
for WAS v7.) With application-managed persistence, the lifecycle of the
EMF and EM is up to your application. You may be able to tie into the
Transaction demarcation, but that requires a configuration property [1].
Bottom line is that I think you need to review your application and how it
interacts with transactions (JTA or local) and determine whether your
changes are even getting to the database before you attempt to query for
them. BTW, there are ways to do in-memory queries of your current
persistent context, but let's keep this simple until we understand your
scenario better.
Good luck,
Kevin
[1]
http://www.ibm.com/developerworks/websphere/techjournal/0612_barcia/0612_barcia.html
On Wed, May 16, 2012 at 3:40 PM, pbt123 <pr...@in.ibm.com> wrote:
> Hello,
>
> I am new on OpenJPA....not sure if it has very common solution.
>
> OpenJpa version: 2.1.1
> Running on WAS6.1.37
>
> I have 7 entities in a transaction, first set values in Entity A (fields
> id=10203, name, pname..... etc ...one record) then B (2 record), C(5
> records), E(3 records), F (2 records), G (2 records) entities.
>
> While again setting values in Entity C, it needs previous entered
> data(previous 5 records) from
> C using custom query.
>
> Query query = em.createQuery( "SELECT z FROM C z where z.id='10203'");
>
> I am using threadLocal to set EntityManager (I have already checked, it is
> trying to get data from the same entityManager which has set value in
> entity
> A ). There are lot of business logic involved in between entity A till G.
>
> The problem is, I am not able to get previous data(5 records) from entity C
> using the
> above SQL. it always return zero result for id=10203.
>
> Can anyone please help?
>
> Many Thanks.
> Prabhu
>
> --
> View this message in context:
> http://openjpa.208410.n2.nabble.com/entity-is-not-available-in-memory-repost-tp7562678.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>