You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by Chris Joysn <jo...@gmail.com> on 2011/02/20 00:07:50 UTC

@Id not loaded when loading an entity

Hello,

when i load an entity the id value is not populated. The entity that was
created using the following test code has the id attribute set correct,
and i can verify this in the database table too, but when i re-read the
entity the id attribute is not populated.

-----8<-----
        em = getEntityManagerFactory().createEntityManager();

        EntityTransaction tx = em.getTransaction();
        tx.begin();

        // insert order

        Order order = new Order();
        order.setStatus("testStatus");
        em.persist(order);

        tx.commit();

        // verify if order was inserted correct

        final String query = "SELECT o FROM Order AS o WHERE o.status = ?1";

        Query q = em.createQuery(query);
        q.setParameter(1, "testStatus");

        Order orderLoaded = null;
        orderLoaded = (Order) q.getSingleResult();
        em.detach(orderLoaded);

        assertNotNull(orderLoaded);
        assertTrue(orderLoaded.getId() > 0);
        assertEquals(order.getStatus(), orderLoaded.getStatus());
-----8<-----

i am using OpenJPA 2.0.1 with MySQL JDBC 5.1.10 and MySQL Server 5.1.49.
with the following entity:

@Entity
@Table(name="orders")
public class Order implements Serializable {

    /** serial for Serializable */
    private static final long serialVersionUID = -8061887078955032972L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int id;

    @Version
    private int version;

    @Column(nullable = false, length = 50)
    private String status;

    @Column
    private Date created;

    ... remaining code skipped ...

as i am not able to find a solution via the docs and using the internet, can
anybody help on why
the id column is not populated?

Thanks

Re: @Id not loaded when loading an entity

Posted by Michael Dick <mi...@gmail.com>.
Part of the problem is that the Eclipse plugin was listed first on the
enhancing with eclipse page. I've moved it after the custom ant task (which
is admittedly more work). I also added links to the two issues with the
eclipse plugin that I'm aware of.

That should help steer new users away from the plugin for now - at least
until we fix the bugs.

-mike

On Mon, Feb 21, 2011 at 1:41 PM, Rick Curtis <cu...@gmail.com> wrote:

> Kevin -
>  >It sounds like this plugin is not performing the enhancement processing
> and, thus, the entities are falling back to the old subclassing support
> (which is known to have issues).
> I think what is happening is even worse than running with subclassing... If
> I remember correctly the classes do implement PersistenceCapable, they just
> don't implement it correctly. I opened a JIRA[1] for this issue a while
> back.
>
> [1] https://issues.apache.org/jira/browse/OPENJPA-1879
>
> Thanks,
> Rick
>
> On Mon, Feb 21, 2011 at 1:19 PM, Kevin Sutter <kw...@gmail.com> wrote:
>
> > Okay, but if there's a problem with the OpenJPA Eclipse plugin, shouldn't
> > that be fixed?  It sounds like this plugin is not performing the
> > enhancement
> > processing and, thus, the entities are falling back to the old
> subclassing
> > support (which is known to have issues).
> >
> > Kevin
> >
> > On Sun, Feb 20, 2011 at 9:07 AM, Rick Curtis <cu...@gmail.com> wrote:
> >
> > > Lucky guess!
> > >
> > > Thanks,
> > > Rick
> > >
> > > On Feb 20, 2011, at 2:17 AM, Chris Joysn <jo...@gmail.com> wrote:
> > >
> > > > That was a good hint :)
> > > >
> > > > i was using the OpenJPA Eclipse Plugin to enhance the entities, and
> it
> > > seems
> > > > that
> > > > this caused the problem. Now i am enhancing using ant and the
> > > PCEnhancerTask
> > > > and the loading of the @Id column works.
> > > >
> > > > Thanks,
> > > > Chris
> > > >
> > > > 2011/2/20 Rick Curtis <cu...@gmail.com>
> > > >
> > > >> How are you enhancing your entities?
> > > >>
> > > >> Thanks,
> > > >> Rick
> > > >>
> > > >> On Feb 19, 2011, at 5:07 PM, Chris Joysn <jo...@gmail.com> wrote:
> > > >>
> > > >>> Hello,
> > > >>>
> > > >>> when i load an entity the id value is not populated. The entity
> that
> > > was
> > > >>> created using the following test code has the id attribute set
> > correct,
> > > >>> and i can verify this in the database table too, but when i re-read
> > the
> > > >>> entity the id attribute is not populated.
> > > >>>
> > > >>> -----8<-----
> > > >>>       em = getEntityManagerFactory().createEntityManager();
> > > >>>
> > > >>>       EntityTransaction tx = em.getTransaction();
> > > >>>       tx.begin();
> > > >>>
> > > >>>       // insert order
> > > >>>
> > > >>>       Order order = new Order();
> > > >>>       order.setStatus("testStatus");
> > > >>>       em.persist(order);
> > > >>>
> > > >>>       tx.commit();
> > > >>>
> > > >>>       // verify if order was inserted correct
> > > >>>
> > > >>>       final String query = "SELECT o FROM Order AS o WHERE o.status
> =
> > > >> ?1";
> > > >>>
> > > >>>       Query q = em.createQuery(query);
> > > >>>       q.setParameter(1, "testStatus");
> > > >>>
> > > >>>       Order orderLoaded = null;
> > > >>>       orderLoaded = (Order) q.getSingleResult();
> > > >>>       em.detach(orderLoaded);
> > > >>>
> > > >>>       assertNotNull(orderLoaded);
> > > >>>       assertTrue(orderLoaded.getId() > 0);
> > > >>>       assertEquals(order.getStatus(), orderLoaded.getStatus());
> > > >>> -----8<-----
> > > >>>
> > > >>> i am using OpenJPA 2.0.1 with MySQL JDBC 5.1.10 and MySQL Server
> > > 5.1.49.
> > > >>> with the following entity:
> > > >>>
> > > >>> @Entity
> > > >>> @Table(name="orders")
> > > >>> public class Order implements Serializable {
> > > >>>
> > > >>>   /** serial for Serializable */
> > > >>>   private static final long serialVersionUID =
> -8061887078955032972L;
> > > >>>
> > > >>>   @Id
> > > >>>   @GeneratedValue(strategy = GenerationType.IDENTITY)
> > > >>>   private int id;
> > > >>>
> > > >>>   @Version
> > > >>>   private int version;
> > > >>>
> > > >>>   @Column(nullable = false, length = 50)
> > > >>>   private String status;
> > > >>>
> > > >>>   @Column
> > > >>>   private Date created;
> > > >>>
> > > >>>   ... remaining code skipped ...
> > > >>>
> > > >>> as i am not able to find a solution via the docs and using the
> > > internet,
> > > >> can
> > > >>> anybody help on why
> > > >>> the id column is not populated?
> > > >>>
> > > >>> Thanks
> > > >>
> > >
> >
>

Re: @Id not loaded when loading an entity

Posted by Rick Curtis <cu...@gmail.com>.
Kevin -
 >It sounds like this plugin is not performing the enhancement processing
and, thus, the entities are falling back to the old subclassing support
(which is known to have issues).
I think what is happening is even worse than running with subclassing... If
I remember correctly the classes do implement PersistenceCapable, they just
don't implement it correctly. I opened a JIRA[1] for this issue a while
back.

[1] https://issues.apache.org/jira/browse/OPENJPA-1879

Thanks,
Rick

On Mon, Feb 21, 2011 at 1:19 PM, Kevin Sutter <kw...@gmail.com> wrote:

> Okay, but if there's a problem with the OpenJPA Eclipse plugin, shouldn't
> that be fixed?  It sounds like this plugin is not performing the
> enhancement
> processing and, thus, the entities are falling back to the old subclassing
> support (which is known to have issues).
>
> Kevin
>
> On Sun, Feb 20, 2011 at 9:07 AM, Rick Curtis <cu...@gmail.com> wrote:
>
> > Lucky guess!
> >
> > Thanks,
> > Rick
> >
> > On Feb 20, 2011, at 2:17 AM, Chris Joysn <jo...@gmail.com> wrote:
> >
> > > That was a good hint :)
> > >
> > > i was using the OpenJPA Eclipse Plugin to enhance the entities, and it
> > seems
> > > that
> > > this caused the problem. Now i am enhancing using ant and the
> > PCEnhancerTask
> > > and the loading of the @Id column works.
> > >
> > > Thanks,
> > > Chris
> > >
> > > 2011/2/20 Rick Curtis <cu...@gmail.com>
> > >
> > >> How are you enhancing your entities?
> > >>
> > >> Thanks,
> > >> Rick
> > >>
> > >> On Feb 19, 2011, at 5:07 PM, Chris Joysn <jo...@gmail.com> wrote:
> > >>
> > >>> Hello,
> > >>>
> > >>> when i load an entity the id value is not populated. The entity that
> > was
> > >>> created using the following test code has the id attribute set
> correct,
> > >>> and i can verify this in the database table too, but when i re-read
> the
> > >>> entity the id attribute is not populated.
> > >>>
> > >>> -----8<-----
> > >>>       em = getEntityManagerFactory().createEntityManager();
> > >>>
> > >>>       EntityTransaction tx = em.getTransaction();
> > >>>       tx.begin();
> > >>>
> > >>>       // insert order
> > >>>
> > >>>       Order order = new Order();
> > >>>       order.setStatus("testStatus");
> > >>>       em.persist(order);
> > >>>
> > >>>       tx.commit();
> > >>>
> > >>>       // verify if order was inserted correct
> > >>>
> > >>>       final String query = "SELECT o FROM Order AS o WHERE o.status =
> > >> ?1";
> > >>>
> > >>>       Query q = em.createQuery(query);
> > >>>       q.setParameter(1, "testStatus");
> > >>>
> > >>>       Order orderLoaded = null;
> > >>>       orderLoaded = (Order) q.getSingleResult();
> > >>>       em.detach(orderLoaded);
> > >>>
> > >>>       assertNotNull(orderLoaded);
> > >>>       assertTrue(orderLoaded.getId() > 0);
> > >>>       assertEquals(order.getStatus(), orderLoaded.getStatus());
> > >>> -----8<-----
> > >>>
> > >>> i am using OpenJPA 2.0.1 with MySQL JDBC 5.1.10 and MySQL Server
> > 5.1.49.
> > >>> with the following entity:
> > >>>
> > >>> @Entity
> > >>> @Table(name="orders")
> > >>> public class Order implements Serializable {
> > >>>
> > >>>   /** serial for Serializable */
> > >>>   private static final long serialVersionUID = -8061887078955032972L;
> > >>>
> > >>>   @Id
> > >>>   @GeneratedValue(strategy = GenerationType.IDENTITY)
> > >>>   private int id;
> > >>>
> > >>>   @Version
> > >>>   private int version;
> > >>>
> > >>>   @Column(nullable = false, length = 50)
> > >>>   private String status;
> > >>>
> > >>>   @Column
> > >>>   private Date created;
> > >>>
> > >>>   ... remaining code skipped ...
> > >>>
> > >>> as i am not able to find a solution via the docs and using the
> > internet,
> > >> can
> > >>> anybody help on why
> > >>> the id column is not populated?
> > >>>
> > >>> Thanks
> > >>
> >
>

Re: @Id not loaded when loading an entity

Posted by Kevin Sutter <kw...@gmail.com>.
Okay, but if there's a problem with the OpenJPA Eclipse plugin, shouldn't
that be fixed?  It sounds like this plugin is not performing the enhancement
processing and, thus, the entities are falling back to the old subclassing
support (which is known to have issues).

Kevin

On Sun, Feb 20, 2011 at 9:07 AM, Rick Curtis <cu...@gmail.com> wrote:

> Lucky guess!
>
> Thanks,
> Rick
>
> On Feb 20, 2011, at 2:17 AM, Chris Joysn <jo...@gmail.com> wrote:
>
> > That was a good hint :)
> >
> > i was using the OpenJPA Eclipse Plugin to enhance the entities, and it
> seems
> > that
> > this caused the problem. Now i am enhancing using ant and the
> PCEnhancerTask
> > and the loading of the @Id column works.
> >
> > Thanks,
> > Chris
> >
> > 2011/2/20 Rick Curtis <cu...@gmail.com>
> >
> >> How are you enhancing your entities?
> >>
> >> Thanks,
> >> Rick
> >>
> >> On Feb 19, 2011, at 5:07 PM, Chris Joysn <jo...@gmail.com> wrote:
> >>
> >>> Hello,
> >>>
> >>> when i load an entity the id value is not populated. The entity that
> was
> >>> created using the following test code has the id attribute set correct,
> >>> and i can verify this in the database table too, but when i re-read the
> >>> entity the id attribute is not populated.
> >>>
> >>> -----8<-----
> >>>       em = getEntityManagerFactory().createEntityManager();
> >>>
> >>>       EntityTransaction tx = em.getTransaction();
> >>>       tx.begin();
> >>>
> >>>       // insert order
> >>>
> >>>       Order order = new Order();
> >>>       order.setStatus("testStatus");
> >>>       em.persist(order);
> >>>
> >>>       tx.commit();
> >>>
> >>>       // verify if order was inserted correct
> >>>
> >>>       final String query = "SELECT o FROM Order AS o WHERE o.status =
> >> ?1";
> >>>
> >>>       Query q = em.createQuery(query);
> >>>       q.setParameter(1, "testStatus");
> >>>
> >>>       Order orderLoaded = null;
> >>>       orderLoaded = (Order) q.getSingleResult();
> >>>       em.detach(orderLoaded);
> >>>
> >>>       assertNotNull(orderLoaded);
> >>>       assertTrue(orderLoaded.getId() > 0);
> >>>       assertEquals(order.getStatus(), orderLoaded.getStatus());
> >>> -----8<-----
> >>>
> >>> i am using OpenJPA 2.0.1 with MySQL JDBC 5.1.10 and MySQL Server
> 5.1.49.
> >>> with the following entity:
> >>>
> >>> @Entity
> >>> @Table(name="orders")
> >>> public class Order implements Serializable {
> >>>
> >>>   /** serial for Serializable */
> >>>   private static final long serialVersionUID = -8061887078955032972L;
> >>>
> >>>   @Id
> >>>   @GeneratedValue(strategy = GenerationType.IDENTITY)
> >>>   private int id;
> >>>
> >>>   @Version
> >>>   private int version;
> >>>
> >>>   @Column(nullable = false, length = 50)
> >>>   private String status;
> >>>
> >>>   @Column
> >>>   private Date created;
> >>>
> >>>   ... remaining code skipped ...
> >>>
> >>> as i am not able to find a solution via the docs and using the
> internet,
> >> can
> >>> anybody help on why
> >>> the id column is not populated?
> >>>
> >>> Thanks
> >>
>

Re: @Id not loaded when loading an entity

Posted by Rick Curtis <cu...@gmail.com>.
Lucky guess!

Thanks,
Rick

On Feb 20, 2011, at 2:17 AM, Chris Joysn <jo...@gmail.com> wrote:

> That was a good hint :)
> 
> i was using the OpenJPA Eclipse Plugin to enhance the entities, and it seems
> that
> this caused the problem. Now i am enhancing using ant and the PCEnhancerTask
> and the loading of the @Id column works.
> 
> Thanks,
> Chris
> 
> 2011/2/20 Rick Curtis <cu...@gmail.com>
> 
>> How are you enhancing your entities?
>> 
>> Thanks,
>> Rick
>> 
>> On Feb 19, 2011, at 5:07 PM, Chris Joysn <jo...@gmail.com> wrote:
>> 
>>> Hello,
>>> 
>>> when i load an entity the id value is not populated. The entity that was
>>> created using the following test code has the id attribute set correct,
>>> and i can verify this in the database table too, but when i re-read the
>>> entity the id attribute is not populated.
>>> 
>>> -----8<-----
>>>       em = getEntityManagerFactory().createEntityManager();
>>> 
>>>       EntityTransaction tx = em.getTransaction();
>>>       tx.begin();
>>> 
>>>       // insert order
>>> 
>>>       Order order = new Order();
>>>       order.setStatus("testStatus");
>>>       em.persist(order);
>>> 
>>>       tx.commit();
>>> 
>>>       // verify if order was inserted correct
>>> 
>>>       final String query = "SELECT o FROM Order AS o WHERE o.status =
>> ?1";
>>> 
>>>       Query q = em.createQuery(query);
>>>       q.setParameter(1, "testStatus");
>>> 
>>>       Order orderLoaded = null;
>>>       orderLoaded = (Order) q.getSingleResult();
>>>       em.detach(orderLoaded);
>>> 
>>>       assertNotNull(orderLoaded);
>>>       assertTrue(orderLoaded.getId() > 0);
>>>       assertEquals(order.getStatus(), orderLoaded.getStatus());
>>> -----8<-----
>>> 
>>> i am using OpenJPA 2.0.1 with MySQL JDBC 5.1.10 and MySQL Server 5.1.49.
>>> with the following entity:
>>> 
>>> @Entity
>>> @Table(name="orders")
>>> public class Order implements Serializable {
>>> 
>>>   /** serial for Serializable */
>>>   private static final long serialVersionUID = -8061887078955032972L;
>>> 
>>>   @Id
>>>   @GeneratedValue(strategy = GenerationType.IDENTITY)
>>>   private int id;
>>> 
>>>   @Version
>>>   private int version;
>>> 
>>>   @Column(nullable = false, length = 50)
>>>   private String status;
>>> 
>>>   @Column
>>>   private Date created;
>>> 
>>>   ... remaining code skipped ...
>>> 
>>> as i am not able to find a solution via the docs and using the internet,
>> can
>>> anybody help on why
>>> the id column is not populated?
>>> 
>>> Thanks
>> 

Re: @Id not loaded when loading an entity

Posted by Chris Joysn <jo...@gmail.com>.
That was a good hint :)

i was using the OpenJPA Eclipse Plugin to enhance the entities, and it seems
that
this caused the problem. Now i am enhancing using ant and the PCEnhancerTask
and the loading of the @Id column works.

Thanks,
Chris

2011/2/20 Rick Curtis <cu...@gmail.com>

> How are you enhancing your entities?
>
> Thanks,
> Rick
>
> On Feb 19, 2011, at 5:07 PM, Chris Joysn <jo...@gmail.com> wrote:
>
> > Hello,
> >
> > when i load an entity the id value is not populated. The entity that was
> > created using the following test code has the id attribute set correct,
> > and i can verify this in the database table too, but when i re-read the
> > entity the id attribute is not populated.
> >
> > -----8<-----
> >        em = getEntityManagerFactory().createEntityManager();
> >
> >        EntityTransaction tx = em.getTransaction();
> >        tx.begin();
> >
> >        // insert order
> >
> >        Order order = new Order();
> >        order.setStatus("testStatus");
> >        em.persist(order);
> >
> >        tx.commit();
> >
> >        // verify if order was inserted correct
> >
> >        final String query = "SELECT o FROM Order AS o WHERE o.status =
> ?1";
> >
> >        Query q = em.createQuery(query);
> >        q.setParameter(1, "testStatus");
> >
> >        Order orderLoaded = null;
> >        orderLoaded = (Order) q.getSingleResult();
> >        em.detach(orderLoaded);
> >
> >        assertNotNull(orderLoaded);
> >        assertTrue(orderLoaded.getId() > 0);
> >        assertEquals(order.getStatus(), orderLoaded.getStatus());
> > -----8<-----
> >
> > i am using OpenJPA 2.0.1 with MySQL JDBC 5.1.10 and MySQL Server 5.1.49.
> > with the following entity:
> >
> > @Entity
> > @Table(name="orders")
> > public class Order implements Serializable {
> >
> >    /** serial for Serializable */
> >    private static final long serialVersionUID = -8061887078955032972L;
> >
> >    @Id
> >    @GeneratedValue(strategy = GenerationType.IDENTITY)
> >    private int id;
> >
> >    @Version
> >    private int version;
> >
> >    @Column(nullable = false, length = 50)
> >    private String status;
> >
> >    @Column
> >    private Date created;
> >
> >    ... remaining code skipped ...
> >
> > as i am not able to find a solution via the docs and using the internet,
> can
> > anybody help on why
> > the id column is not populated?
> >
> > Thanks
>

Re: @Id not loaded when loading an entity

Posted by Rick Curtis <cu...@gmail.com>.
How are you enhancing your entities?

Thanks,
Rick

On Feb 19, 2011, at 5:07 PM, Chris Joysn <jo...@gmail.com> wrote:

> Hello,
> 
> when i load an entity the id value is not populated. The entity that was
> created using the following test code has the id attribute set correct,
> and i can verify this in the database table too, but when i re-read the
> entity the id attribute is not populated.
> 
> -----8<-----
>        em = getEntityManagerFactory().createEntityManager();
> 
>        EntityTransaction tx = em.getTransaction();
>        tx.begin();
> 
>        // insert order
> 
>        Order order = new Order();
>        order.setStatus("testStatus");
>        em.persist(order);
> 
>        tx.commit();
> 
>        // verify if order was inserted correct
> 
>        final String query = "SELECT o FROM Order AS o WHERE o.status = ?1";
> 
>        Query q = em.createQuery(query);
>        q.setParameter(1, "testStatus");
> 
>        Order orderLoaded = null;
>        orderLoaded = (Order) q.getSingleResult();
>        em.detach(orderLoaded);
> 
>        assertNotNull(orderLoaded);
>        assertTrue(orderLoaded.getId() > 0);
>        assertEquals(order.getStatus(), orderLoaded.getStatus());
> -----8<-----
> 
> i am using OpenJPA 2.0.1 with MySQL JDBC 5.1.10 and MySQL Server 5.1.49.
> with the following entity:
> 
> @Entity
> @Table(name="orders")
> public class Order implements Serializable {
> 
>    /** serial for Serializable */
>    private static final long serialVersionUID = -8061887078955032972L;
> 
>    @Id
>    @GeneratedValue(strategy = GenerationType.IDENTITY)
>    private int id;
> 
>    @Version
>    private int version;
> 
>    @Column(nullable = false, length = 50)
>    private String status;
> 
>    @Column
>    private Date created;
> 
>    ... remaining code skipped ...
> 
> as i am not able to find a solution via the docs and using the internet, can
> anybody help on why
> the id column is not populated?
> 
> Thanks