You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by "Csaba Tűz (Created JIRA)" <ji...@apache.org> on 2011/11/12 04:40:51 UTC

[jira] [Created] (OPENJPA-2074) Calling em.persist(...) on simple entity without relations, with null primary key, @GeneratedValue results in InvalidStateException, complaining about non-default primary key.

Calling em.persist(...) on simple entity without relations, with null primary key, @GeneratedValue results in InvalidStateException, complaining about non-default primary key.
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

                 Key: OPENJPA-2074
                 URL: https://issues.apache.org/jira/browse/OPENJPA-2074
             Project: OpenJPA
          Issue Type: Bug
    Affects Versions: 2.1.1
         Environment: Windows 7, Apache Tomcat 5.5, Eclipse Indigo, OpenJPA plugin handles enhancement, JPA facet, JAX-RS facet
            Reporter: Csaba Tűz
            Priority: Blocker


Simple entity without any relations, INT primary key, mapped to Long in POJO.
Entity annotated propery with @Id @GeneratedValue 
DMBS: MySQL with JDBC connection.

I started tracking down the issue. I can't get accustomed with the code around it, but I write my experience: (line numbers are based on source release 2.1.1)
org.apache.openjpa.kernel.StateManagerImpl:
- Line 2966: It seems that the method call results in my entity's id field being assigned with a generated value.
- Line 2967: Then in the for loop after that, we reach the same field (the primary key) again at some point, and at
- Line 2968: assignField(i, true) eventually runs on the same code which assigned the Id the first time, which freaks out, as the field value is already set at this point.
org.apache.openjpa.util.ApplicationIds:481 (seems to be a utility method for me)

I cannot investigate further, however I am pretty confident that this is a bug somewhere in the logic, maybe inside StateManagerImpl#assignField method. I believe org.apache.openjpa.util.ApplicationIds:481 should not be invoked the second time, as it's not idempotent.

The exception message:
Primary key field org.inception.teacher4u.persistence.entity.User.userid of org.inception.teacher4u.persistence.entity.User@635e98be has non-default value. The instance life cycle is in PNewState state and hence an existing non-default value for the identity field is not permitted. You either need to remove the @GeneratedValue annotation or modify the code to remove the initializer processing.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

[jira] [Commented] (OPENJPA-2074) Calling em.persist(...) on simple entity without relations, with null primary key, @GeneratedValue results in InvalidStateException, complaining about non-default primary key.

Posted by "Kevin Sutter (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OPENJPA-2074?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13150625#comment-13150625 ] 

Kevin Sutter commented on OPENJPA-2074:
---------------------------------------

I just linked this issue with OPENJPA-673.  There has to be something more to this Issue than what's currently documented.  The simple example provided is tested several times over in the OpenJPA Junit bucket.  After doing some searching, I came across OPENJPA-673.  The use of a Version column with an unexpected value makes some sense.  But, I thought that issue was resolved recently as well (just couldn't find the JIRA yet).  Since there are multiple JIRAs with similar results, we probably need to take a closer look.
                
> Calling em.persist(...) on simple entity without relations, with null primary key, @GeneratedValue results in InvalidStateException, complaining about non-default primary key.
> -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: OPENJPA-2074
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-2074
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: jpa
>    Affects Versions: 2.1.1
>         Environment: Windows 7, Apache Tomcat 5.5, Eclipse Indigo, OpenJPA plugin handles enhancement, JPA facet, JAX-RS facet
>            Reporter: Csaba Tűz
>            Priority: Blocker
>
> Simple entity without any relations, INT primary key, mapped to Long in POJO.
> Entity annotated propery with @Id @GeneratedValue 
> DMBS: MySQL with JDBC connection.
> I started tracking down the issue. I can't get accustomed with the code around it, but I write my experience: (line numbers are based on source release 2.1.1)
> org.apache.openjpa.kernel.StateManagerImpl:
> - Line 2966: It seems that the method call results in my entity's id field being assigned with a generated value.
> - Line 2967: Then in the for loop after that, we reach the same field (the primary key) again at some point, and at
> - Line 2968: assignField(i, true) eventually runs on the same code which assigned the Id the first time, which freaks out, as the field value is already set at this point.
> org.apache.openjpa.util.ApplicationIds:481 (seems to be a utility method for me)
> I cannot investigate further, however I am pretty confident that this is a bug somewhere in the logic, maybe inside StateManagerImpl#assignField method. I believe org.apache.openjpa.util.ApplicationIds:481 should not be invoked the second time, as it's not idempotent.
> The exception message:
> Primary key field org.inception.teacher4u.persistence.entity.User.userid of org.inception.teacher4u.persistence.entity.User@635e98be has non-default value. The instance life cycle is in PNewState state and hence an existing non-default value for the identity field is not permitted. You either need to remove the @GeneratedValue annotation or modify the code to remove the initializer processing.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

[jira] [Updated] (OPENJPA-2074) Calling em.persist(...) on simple entity without relations, with null primary key, @GeneratedValue results in InvalidStateException, complaining about non-default primary key.

Posted by "Csaba Tűz (Updated JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/OPENJPA-2074?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Csaba Tűz updated OPENJPA-2074:
-------------------------------

    Component/s: jpa
    
> Calling em.persist(...) on simple entity without relations, with null primary key, @GeneratedValue results in InvalidStateException, complaining about non-default primary key.
> -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: OPENJPA-2074
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-2074
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: jpa
>    Affects Versions: 2.1.1
>         Environment: Windows 7, Apache Tomcat 5.5, Eclipse Indigo, OpenJPA plugin handles enhancement, JPA facet, JAX-RS facet
>            Reporter: Csaba Tűz
>            Priority: Blocker
>
> Simple entity without any relations, INT primary key, mapped to Long in POJO.
> Entity annotated propery with @Id @GeneratedValue 
> DMBS: MySQL with JDBC connection.
> I started tracking down the issue. I can't get accustomed with the code around it, but I write my experience: (line numbers are based on source release 2.1.1)
> org.apache.openjpa.kernel.StateManagerImpl:
> - Line 2966: It seems that the method call results in my entity's id field being assigned with a generated value.
> - Line 2967: Then in the for loop after that, we reach the same field (the primary key) again at some point, and at
> - Line 2968: assignField(i, true) eventually runs on the same code which assigned the Id the first time, which freaks out, as the field value is already set at this point.
> org.apache.openjpa.util.ApplicationIds:481 (seems to be a utility method for me)
> I cannot investigate further, however I am pretty confident that this is a bug somewhere in the logic, maybe inside StateManagerImpl#assignField method. I believe org.apache.openjpa.util.ApplicationIds:481 should not be invoked the second time, as it's not idempotent.
> The exception message:
> Primary key field org.inception.teacher4u.persistence.entity.User.userid of org.inception.teacher4u.persistence.entity.User@635e98be has non-default value. The instance life cycle is in PNewState state and hence an existing non-default value for the identity field is not permitted. You either need to remove the @GeneratedValue annotation or modify the code to remove the initializer processing.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

[jira] [Issue Comment Edited] (OPENJPA-2074) Calling em.persist(...) on simple entity without relations, with null primary key, @GeneratedValue results in InvalidStateException, complaining about non-default primary key.

Posted by "Csaba Tűz (Issue Comment Edited JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OPENJPA-2074?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13150381#comment-13150381 ] 

Csaba Tűz edited comment on OPENJPA-2074 at 11/15/11 11:08 AM:
---------------------------------------------------------------

I'm sorry but since I reported the bug heavy development occured, I had to switch to Hibernate, and I cannot afford the time right now to produce the stack trace for you.
Sorry for the annoyance.

Scenario:
I have an entity class as basic as:
@Entity
@Table(name = "myentity")
class MyEntity {
  @Id
  @GeneratedValue
  private Integer id;
  private String name;

  /* getter/setters */
  ...
}

I instantiate it, set the field 'name', leave the field 'id' to be null, then persist it like:

EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
em.persist(newEntity);
em.getTransaction().commit();
em.close();

Result: The exception in my previous post. 
Investigation results:
- Id gets assigned with generated value correctly, and after that, it gets assigned again.
- The code which assigns the generated value checks if field value is default or not, and for the second run it finds obviously that it isn't, that's where the exception is thrown.
                
      was (Author: tuzcsaba):
    I'm sorry but since I reported the bug heavy development occured, I had to switch to Hibernate, and I cannot afford the time right now to produce the stack trace for you.
Sorry for the annoyance.

Scenario:
I have an entity class as basic as:
@Entity
@Table(name = "myentity")
class MyEntity {
  @Id
  @GeneratedValue
  private Integer id;
  private String name;

  /* getter/setters */
  ...
}

I instantiate it, set the field 'name', leave the field 'id' to be null, then persist it like:

EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
em.persist(newEntity);
em.getTransaction().end();
em.close();

Result: The exception in my previous post. 
Investigation results:
- Id gets assigned with generated value correctly, and after that, it gets assigned again.
- The code which assigns the generated value checks if field value is default or not, and for the second run it finds obviously that it isn't, that's where the exception is thrown.
                  
> Calling em.persist(...) on simple entity without relations, with null primary key, @GeneratedValue results in InvalidStateException, complaining about non-default primary key.
> -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: OPENJPA-2074
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-2074
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: jpa
>    Affects Versions: 2.1.1
>         Environment: Windows 7, Apache Tomcat 5.5, Eclipse Indigo, OpenJPA plugin handles enhancement, JPA facet, JAX-RS facet
>            Reporter: Csaba Tűz
>            Priority: Blocker
>
> Simple entity without any relations, INT primary key, mapped to Long in POJO.
> Entity annotated propery with @Id @GeneratedValue 
> DMBS: MySQL with JDBC connection.
> I started tracking down the issue. I can't get accustomed with the code around it, but I write my experience: (line numbers are based on source release 2.1.1)
> org.apache.openjpa.kernel.StateManagerImpl:
> - Line 2966: It seems that the method call results in my entity's id field being assigned with a generated value.
> - Line 2967: Then in the for loop after that, we reach the same field (the primary key) again at some point, and at
> - Line 2968: assignField(i, true) eventually runs on the same code which assigned the Id the first time, which freaks out, as the field value is already set at this point.
> org.apache.openjpa.util.ApplicationIds:481 (seems to be a utility method for me)
> I cannot investigate further, however I am pretty confident that this is a bug somewhere in the logic, maybe inside StateManagerImpl#assignField method. I believe org.apache.openjpa.util.ApplicationIds:481 should not be invoked the second time, as it's not idempotent.
> The exception message:
> Primary key field org.inception.teacher4u.persistence.entity.User.userid of org.inception.teacher4u.persistence.entity.User@635e98be has non-default value. The instance life cycle is in PNewState state and hence an existing non-default value for the identity field is not permitted. You either need to remove the @GeneratedValue annotation or modify the code to remove the initializer processing.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

[jira] [Issue Comment Edited] (OPENJPA-2074) Calling em.persist(...) on simple entity without relations, with null primary key, @GeneratedValue results in InvalidStateException, complaining about non-default primary key.

Posted by "Csaba Tűz (Issue Comment Edited JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OPENJPA-2074?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13150381#comment-13150381 ] 

Csaba Tűz edited comment on OPENJPA-2074 at 11/15/11 11:07 AM:
---------------------------------------------------------------

I'm sorry but since I reported the bug heavy development occured, I had to switch to Hibernate, and I cannot afford the time right now to produce the stack trace for you.
Sorry for the annoyance.

Scenario:
I have an entity class as basic as:
@Entity
@Table(name = "myentity")
class MyEntity {
  @Id
  @GeneratedValue
  private int id;
  private String name;

  /* getter/setters */
  ...
}

I instantiate it, set the field 'name', leave the field 'id' to be null, then persist it like:

EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
em.persist(newEntity);
em.getTransaction().end();
em.close();

Result: The exception in my previous post. 
Investigation results:
- Id gets assigned with generated value correctly, and after that, it gets assigned again.
- The code which assigns the generated value checks if field value is default or not, and for the second run it finds obviously that it isn't, that's where the exception is thrown.
                
      was (Author: tuzcsaba):
    I'm sorry but since I reported the bug heavy development occured, I had to switch to Hibernate, and I cannot afford the time right now to produce the stack trace for you.
Sorry for the annoyance.

Scenario:
I have an entity class as basic as:
class Entity {
  @Id
  @GeneratedValue
  private int id;
  private String name;

  /* getter/setters */
  ...
}

I instantiate it, set the field 'name', leave the field 'id' to be null, then persist it like:

EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
em.persist(newEntity);
em.getTransaction().end();
em.close();

Result: The exception in my previous post. 
Investigation results:
- Id gets assigned with generated value correctly, and after that, it gets assigned again.
- The code which assigns the generated value checks if field value is default or not, and for the second run it finds obviously that it isn't, that's where the exception is thrown.
                  
> Calling em.persist(...) on simple entity without relations, with null primary key, @GeneratedValue results in InvalidStateException, complaining about non-default primary key.
> -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: OPENJPA-2074
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-2074
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: jpa
>    Affects Versions: 2.1.1
>         Environment: Windows 7, Apache Tomcat 5.5, Eclipse Indigo, OpenJPA plugin handles enhancement, JPA facet, JAX-RS facet
>            Reporter: Csaba Tűz
>            Priority: Blocker
>
> Simple entity without any relations, INT primary key, mapped to Long in POJO.
> Entity annotated propery with @Id @GeneratedValue 
> DMBS: MySQL with JDBC connection.
> I started tracking down the issue. I can't get accustomed with the code around it, but I write my experience: (line numbers are based on source release 2.1.1)
> org.apache.openjpa.kernel.StateManagerImpl:
> - Line 2966: It seems that the method call results in my entity's id field being assigned with a generated value.
> - Line 2967: Then in the for loop after that, we reach the same field (the primary key) again at some point, and at
> - Line 2968: assignField(i, true) eventually runs on the same code which assigned the Id the first time, which freaks out, as the field value is already set at this point.
> org.apache.openjpa.util.ApplicationIds:481 (seems to be a utility method for me)
> I cannot investigate further, however I am pretty confident that this is a bug somewhere in the logic, maybe inside StateManagerImpl#assignField method. I believe org.apache.openjpa.util.ApplicationIds:481 should not be invoked the second time, as it's not idempotent.
> The exception message:
> Primary key field org.inception.teacher4u.persistence.entity.User.userid of org.inception.teacher4u.persistence.entity.User@635e98be has non-default value. The instance life cycle is in PNewState state and hence an existing non-default value for the identity field is not permitted. You either need to remove the @GeneratedValue annotation or modify the code to remove the initializer processing.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

[jira] [Commented] (OPENJPA-2074) Calling em.persist(...) on simple entity without relations, with null primary key, @GeneratedValue results in InvalidStateException, complaining about non-default primary key.

Posted by "Csaba Tűz (Commented JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OPENJPA-2074?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13150381#comment-13150381 ] 

Csaba Tűz commented on OPENJPA-2074:
------------------------------------

I'm sorry but since I reported the bug heavy development occured, I had to switch to Hibernate, and I cannot afford the time right now to produce the stack trace for you.
Sorry for the annoyance.

Scenario:
I have an entity class as basic as:
class Entity {
  @Id
  @GeneratedValue
  private int id;
  private String name;

  /* getter/setters */
  ...
}

I instantiate it, set the field 'name', leave the field 'id' to be null, then persist it like:

EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
em.persist(newEntity);
em.getTransaction().end();
em.close();

Result: The exception in my previous post. 
Investigation results:
- Id gets assigned with generated value correctly, and after that, it gets assigned again.
- The code which assigns the generated value checks if field value is default or not, and for the second run it finds obviously that it isn't, that's where the exception is thrown.
                
> Calling em.persist(...) on simple entity without relations, with null primary key, @GeneratedValue results in InvalidStateException, complaining about non-default primary key.
> -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: OPENJPA-2074
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-2074
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: jpa
>    Affects Versions: 2.1.1
>         Environment: Windows 7, Apache Tomcat 5.5, Eclipse Indigo, OpenJPA plugin handles enhancement, JPA facet, JAX-RS facet
>            Reporter: Csaba Tűz
>            Priority: Blocker
>
> Simple entity without any relations, INT primary key, mapped to Long in POJO.
> Entity annotated propery with @Id @GeneratedValue 
> DMBS: MySQL with JDBC connection.
> I started tracking down the issue. I can't get accustomed with the code around it, but I write my experience: (line numbers are based on source release 2.1.1)
> org.apache.openjpa.kernel.StateManagerImpl:
> - Line 2966: It seems that the method call results in my entity's id field being assigned with a generated value.
> - Line 2967: Then in the for loop after that, we reach the same field (the primary key) again at some point, and at
> - Line 2968: assignField(i, true) eventually runs on the same code which assigned the Id the first time, which freaks out, as the field value is already set at this point.
> org.apache.openjpa.util.ApplicationIds:481 (seems to be a utility method for me)
> I cannot investigate further, however I am pretty confident that this is a bug somewhere in the logic, maybe inside StateManagerImpl#assignField method. I believe org.apache.openjpa.util.ApplicationIds:481 should not be invoked the second time, as it's not idempotent.
> The exception message:
> Primary key field org.inception.teacher4u.persistence.entity.User.userid of org.inception.teacher4u.persistence.entity.User@635e98be has non-default value. The instance life cycle is in PNewState state and hence an existing non-default value for the identity field is not permitted. You either need to remove the @GeneratedValue annotation or modify the code to remove the initializer processing.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

[jira] [Commented] (OPENJPA-2074) Calling em.persist(...) on simple entity without relations, with null primary key, @GeneratedValue results in InvalidStateException, complaining about non-default primary key.

Posted by "Csaba Tűz (Commented JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OPENJPA-2074?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13150826#comment-13150826 ] 

Csaba Tűz commented on OPENJPA-2074:
------------------------------------

I installed the OpenJPA Eclipse Tools feature from this
http://people.apache.org/~dwoods/openjpa/devtools/updatesite/
update site.

Then I followed instructions here
http://openjpa.apache.org/openjpaeclipseenhancementbuilder.html

Now I see, that this page lists known bugs. I didn't notice it when installing the thing.
http://openjpa.apache.org/enhancement-with-eclipse.html

Reading the bug OPENJPA-1879 it looks like you are totally right.

Sorry for generating unnecessary noise.
                
> Calling em.persist(...) on simple entity without relations, with null primary key, @GeneratedValue results in InvalidStateException, complaining about non-default primary key.
> -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: OPENJPA-2074
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-2074
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: jpa
>    Affects Versions: 2.1.1
>         Environment: Windows 7, Apache Tomcat 5.5, Eclipse Indigo, OpenJPA plugin handles enhancement, JPA facet, JAX-RS facet
>            Reporter: Csaba Tűz
>            Priority: Blocker
>
> Simple entity without any relations, INT primary key, mapped to Long in POJO.
> Entity annotated propery with @Id @GeneratedValue 
> DMBS: MySQL with JDBC connection.
> I started tracking down the issue. I can't get accustomed with the code around it, but I write my experience: (line numbers are based on source release 2.1.1)
> org.apache.openjpa.kernel.StateManagerImpl:
> - Line 2966: It seems that the method call results in my entity's id field being assigned with a generated value.
> - Line 2967: Then in the for loop after that, we reach the same field (the primary key) again at some point, and at
> - Line 2968: assignField(i, true) eventually runs on the same code which assigned the Id the first time, which freaks out, as the field value is already set at this point.
> org.apache.openjpa.util.ApplicationIds:481 (seems to be a utility method for me)
> I cannot investigate further, however I am pretty confident that this is a bug somewhere in the logic, maybe inside StateManagerImpl#assignField method. I believe org.apache.openjpa.util.ApplicationIds:481 should not be invoked the second time, as it's not idempotent.
> The exception message:
> Primary key field org.inception.teacher4u.persistence.entity.User.userid of org.inception.teacher4u.persistence.entity.User@635e98be has non-default value. The instance life cycle is in PNewState state and hence an existing non-default value for the identity field is not permitted. You either need to remove the @GeneratedValue annotation or modify the code to remove the initializer processing.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

[jira] [Commented] (OPENJPA-2074) Calling em.persist(...) on simple entity without relations, with null primary key, @GeneratedValue results in InvalidStateException, complaining about non-default primary key.

Posted by "Rick Curtis (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OPENJPA-2074?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13150812#comment-13150812 ] 

Rick Curtis commented on OPENJPA-2074:
--------------------------------------

Csaba - 

When you say "OpenJPA plugin handles enhancement", can you please clarify? I suspect this is the same problem as OPENJPA-1879[1].

Thanks,
Rick

[1] https://issues.apache.org/jira/browse/OPENJPA-1879
                
> Calling em.persist(...) on simple entity without relations, with null primary key, @GeneratedValue results in InvalidStateException, complaining about non-default primary key.
> -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: OPENJPA-2074
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-2074
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: jpa
>    Affects Versions: 2.1.1
>         Environment: Windows 7, Apache Tomcat 5.5, Eclipse Indigo, OpenJPA plugin handles enhancement, JPA facet, JAX-RS facet
>            Reporter: Csaba Tűz
>            Priority: Blocker
>
> Simple entity without any relations, INT primary key, mapped to Long in POJO.
> Entity annotated propery with @Id @GeneratedValue 
> DMBS: MySQL with JDBC connection.
> I started tracking down the issue. I can't get accustomed with the code around it, but I write my experience: (line numbers are based on source release 2.1.1)
> org.apache.openjpa.kernel.StateManagerImpl:
> - Line 2966: It seems that the method call results in my entity's id field being assigned with a generated value.
> - Line 2967: Then in the for loop after that, we reach the same field (the primary key) again at some point, and at
> - Line 2968: assignField(i, true) eventually runs on the same code which assigned the Id the first time, which freaks out, as the field value is already set at this point.
> org.apache.openjpa.util.ApplicationIds:481 (seems to be a utility method for me)
> I cannot investigate further, however I am pretty confident that this is a bug somewhere in the logic, maybe inside StateManagerImpl#assignField method. I believe org.apache.openjpa.util.ApplicationIds:481 should not be invoked the second time, as it's not idempotent.
> The exception message:
> Primary key field org.inception.teacher4u.persistence.entity.User.userid of org.inception.teacher4u.persistence.entity.User@635e98be has non-default value. The instance life cycle is in PNewState state and hence an existing non-default value for the identity field is not permitted. You either need to remove the @GeneratedValue annotation or modify the code to remove the initializer processing.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

[jira] [Issue Comment Edited] (OPENJPA-2074) Calling em.persist(...) on simple entity without relations, with null primary key, @GeneratedValue results in InvalidStateException, complaining about non-default primary key.

Posted by "Csaba Tűz (Issue Comment Edited JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OPENJPA-2074?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13150381#comment-13150381 ] 

Csaba Tűz edited comment on OPENJPA-2074 at 11/15/11 11:07 AM:
---------------------------------------------------------------

I'm sorry but since I reported the bug heavy development occured, I had to switch to Hibernate, and I cannot afford the time right now to produce the stack trace for you.
Sorry for the annoyance.

Scenario:
I have an entity class as basic as:
@Entity
@Table(name = "myentity")
class MyEntity {
  @Id
  @GeneratedValue
  private Integer id;
  private String name;

  /* getter/setters */
  ...
}

I instantiate it, set the field 'name', leave the field 'id' to be null, then persist it like:

EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
em.persist(newEntity);
em.getTransaction().end();
em.close();

Result: The exception in my previous post. 
Investigation results:
- Id gets assigned with generated value correctly, and after that, it gets assigned again.
- The code which assigns the generated value checks if field value is default or not, and for the second run it finds obviously that it isn't, that's where the exception is thrown.
                
      was (Author: tuzcsaba):
    I'm sorry but since I reported the bug heavy development occured, I had to switch to Hibernate, and I cannot afford the time right now to produce the stack trace for you.
Sorry for the annoyance.

Scenario:
I have an entity class as basic as:
@Entity
@Table(name = "myentity")
class MyEntity {
  @Id
  @GeneratedValue
  private int id;
  private String name;

  /* getter/setters */
  ...
}

I instantiate it, set the field 'name', leave the field 'id' to be null, then persist it like:

EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
em.persist(newEntity);
em.getTransaction().end();
em.close();

Result: The exception in my previous post. 
Investigation results:
- Id gets assigned with generated value correctly, and after that, it gets assigned again.
- The code which assigns the generated value checks if field value is default or not, and for the second run it finds obviously that it isn't, that's where the exception is thrown.
                  
> Calling em.persist(...) on simple entity without relations, with null primary key, @GeneratedValue results in InvalidStateException, complaining about non-default primary key.
> -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: OPENJPA-2074
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-2074
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: jpa
>    Affects Versions: 2.1.1
>         Environment: Windows 7, Apache Tomcat 5.5, Eclipse Indigo, OpenJPA plugin handles enhancement, JPA facet, JAX-RS facet
>            Reporter: Csaba Tűz
>            Priority: Blocker
>
> Simple entity without any relations, INT primary key, mapped to Long in POJO.
> Entity annotated propery with @Id @GeneratedValue 
> DMBS: MySQL with JDBC connection.
> I started tracking down the issue. I can't get accustomed with the code around it, but I write my experience: (line numbers are based on source release 2.1.1)
> org.apache.openjpa.kernel.StateManagerImpl:
> - Line 2966: It seems that the method call results in my entity's id field being assigned with a generated value.
> - Line 2967: Then in the for loop after that, we reach the same field (the primary key) again at some point, and at
> - Line 2968: assignField(i, true) eventually runs on the same code which assigned the Id the first time, which freaks out, as the field value is already set at this point.
> org.apache.openjpa.util.ApplicationIds:481 (seems to be a utility method for me)
> I cannot investigate further, however I am pretty confident that this is a bug somewhere in the logic, maybe inside StateManagerImpl#assignField method. I believe org.apache.openjpa.util.ApplicationIds:481 should not be invoked the second time, as it's not idempotent.
> The exception message:
> Primary key field org.inception.teacher4u.persistence.entity.User.userid of org.inception.teacher4u.persistence.entity.User@635e98be has non-default value. The instance life cycle is in PNewState state and hence an existing non-default value for the identity field is not permitted. You either need to remove the @GeneratedValue annotation or modify the code to remove the initializer processing.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

[jira] [Commented] (OPENJPA-2074) Calling em.persist(...) on simple entity without relations, with null primary key, @GeneratedValue results in InvalidStateException, complaining about non-default primary key.

Posted by "Rick Curtis (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OPENJPA-2074?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13149658#comment-13149658 ] 

Rick Curtis commented on OPENJPA-2074:
--------------------------------------

Can you please post the full stacktrace?

Also, can you better describe the scenario that you are having problems with? 

Thanks,
Rick
                
> Calling em.persist(...) on simple entity without relations, with null primary key, @GeneratedValue results in InvalidStateException, complaining about non-default primary key.
> -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: OPENJPA-2074
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-2074
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: jpa
>    Affects Versions: 2.1.1
>         Environment: Windows 7, Apache Tomcat 5.5, Eclipse Indigo, OpenJPA plugin handles enhancement, JPA facet, JAX-RS facet
>            Reporter: Csaba Tűz
>            Priority: Blocker
>
> Simple entity without any relations, INT primary key, mapped to Long in POJO.
> Entity annotated propery with @Id @GeneratedValue 
> DMBS: MySQL with JDBC connection.
> I started tracking down the issue. I can't get accustomed with the code around it, but I write my experience: (line numbers are based on source release 2.1.1)
> org.apache.openjpa.kernel.StateManagerImpl:
> - Line 2966: It seems that the method call results in my entity's id field being assigned with a generated value.
> - Line 2967: Then in the for loop after that, we reach the same field (the primary key) again at some point, and at
> - Line 2968: assignField(i, true) eventually runs on the same code which assigned the Id the first time, which freaks out, as the field value is already set at this point.
> org.apache.openjpa.util.ApplicationIds:481 (seems to be a utility method for me)
> I cannot investigate further, however I am pretty confident that this is a bug somewhere in the logic, maybe inside StateManagerImpl#assignField method. I believe org.apache.openjpa.util.ApplicationIds:481 should not be invoked the second time, as it's not idempotent.
> The exception message:
> Primary key field org.inception.teacher4u.persistence.entity.User.userid of org.inception.teacher4u.persistence.entity.User@635e98be has non-default value. The instance life cycle is in PNewState state and hence an existing non-default value for the identity field is not permitted. You either need to remove the @GeneratedValue annotation or modify the code to remove the initializer processing.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

[jira] [Closed] (OPENJPA-2074) Calling em.persist(...) on simple entity without relations, with null primary key, @GeneratedValue results in InvalidStateException, complaining about non-default primary key.

Posted by "Rick Curtis (Closed) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/OPENJPA-2074?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Rick Curtis closed OPENJPA-2074.
--------------------------------

    Resolution: Duplicate

Closing as this is a duplicate of OPENJPA-1879.
                
> Calling em.persist(...) on simple entity without relations, with null primary key, @GeneratedValue results in InvalidStateException, complaining about non-default primary key.
> -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: OPENJPA-2074
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-2074
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: jpa
>    Affects Versions: 2.1.1
>         Environment: Windows 7, Apache Tomcat 5.5, Eclipse Indigo, OpenJPA plugin handles enhancement, JPA facet, JAX-RS facet
>            Reporter: Csaba Tűz
>            Priority: Blocker
>
> Simple entity without any relations, INT primary key, mapped to Long in POJO.
> Entity annotated propery with @Id @GeneratedValue 
> DMBS: MySQL with JDBC connection.
> I started tracking down the issue. I can't get accustomed with the code around it, but I write my experience: (line numbers are based on source release 2.1.1)
> org.apache.openjpa.kernel.StateManagerImpl:
> - Line 2966: It seems that the method call results in my entity's id field being assigned with a generated value.
> - Line 2967: Then in the for loop after that, we reach the same field (the primary key) again at some point, and at
> - Line 2968: assignField(i, true) eventually runs on the same code which assigned the Id the first time, which freaks out, as the field value is already set at this point.
> org.apache.openjpa.util.ApplicationIds:481 (seems to be a utility method for me)
> I cannot investigate further, however I am pretty confident that this is a bug somewhere in the logic, maybe inside StateManagerImpl#assignField method. I believe org.apache.openjpa.util.ApplicationIds:481 should not be invoked the second time, as it's not idempotent.
> The exception message:
> Primary key field org.inception.teacher4u.persistence.entity.User.userid of org.inception.teacher4u.persistence.entity.User@635e98be has non-default value. The instance life cycle is in PNewState state and hence an existing non-default value for the identity field is not permitted. You either need to remove the @GeneratedValue annotation or modify the code to remove the initializer processing.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira