users@glassfish.java.net

RE: select after insert issue

From: Gordon Yorke <gordon.yorke_at_oracle.com>
Date: Tue, 2 May 2006 13:21:04 -0400

Hello,
   We are going to need more detail. What is the cascade settings on the relationships from Reservation to User and Asset? Are they Cascade PERSIST or cascade ALL? These pre-existing User and Asset objects are they managed entities or detached entities? Can you provide the code that is performing this operation? Are there unique constraints on the database tables?
--Gordon

-----Original Message-----
From: Marina.Vatkina_at_Sun.COM [mailto:Marina.Vatkina_at_Sun.COM]On Behalf Of
Marina Vatkina
Sent: Tuesday, May 02, 2006 12:44 PM
To: users_at_glassfish.dev.java.net; persistence
Subject: Re: select after insert issue


Hi Davy,

CC-ing persistence alias.
Is it a Java SE or a Java EE application? Do you navigate to the related
objects via getters?

thanks,
-marina

Davy De Durpel wrote:
> Hi,
>
> I have a strange behavior and I have it on build 42 and 46 (the only 2 I
> tested).
>
> The problem in short is that when I do a persist of a new entity and
> then I do a select to retrieve all entities from the database, then all
> referenced objects are empty (all properties are Null). No way to get
> them back then restarting the application. In all other situations
> (selects, updates) I don't have the problem but things go wrong as soon
> as I persist a new Entity to the database.
>
> I will try to explain in more detail.
>
> I have a table 'Reservation' that contains a link to a table 'Asset' and
> a table 'User'.
> I execute this query to get all the reservations for a certain user:
> 'SELECT c FROM Reservation c WHERE c.user = :user'
> Everything is left by default so it should be using eager fetching. The
> result is correct and also the User and Asset information is retrieved
> from the database.
> I now create a new Reservation with some default values. I also add an
> existing Asset and User object (detached from the entity manager).
> I use em.persist to save the reservation in the database and I can
> clearly see that this is done in a correct way.
> I then execute the same query again to retrieve all Reservations for the
> current user from the database but now my 'User' and 'Asset' objects
> have all fields initialized to Null values.
>
> I also tried it with other Entity beans and I have the same behavior.
>
> Any idea what could be causing this behavior or do I need to provide
> more details?
>
> Byeee...
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>