Would you please take a look at my code, I keep getting the following exception when I try to insert a record into the database:

Apr 02, 2014 1:30:53 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [UserEditorServlet] in context with path [/My.Web] threw exception
<openjpa-2.2.2-r422266:1468616 nonfatal general error> org.apache.openjpa.persistence.PersistenceException: error during validation of <unknown>

My table is defined like this:

create table User (

    id bigint primary key not null auto_increment,
    name varchar(200),
    status varchar(30),
    createdOn datetime,
    modifiedOn datetime,
    password varchar(60),

    index(status)

) ENGINE=InnoDB;

and my identity field like this:

@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
protected Long id = null;

it turns out that if I assign a value to my id my exception changes to this:

Apr 02, 2014 1:37:18 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [UserEditorServlet] in context with path [/My.Web] threw exception
<openjpa-2.2.2-r422266:1468616 fatal user error> org.apache.openjpa.persistence.InvalidStateException: Primary key field net.jaimes.Persistent.id of org.apache.openjpa.enhance.ReflectingPersistenceCapable@194765c4 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.

While debugging, I only have one null variable: Id, which is expected to be created by MySQL. At the end, I cannot insert a simple record...

Thank you

有帮助吗?

解决方案

org.apache.openjpa.enhance.ReflectingPersistenceCapable

It appears that you are using openjpa.RuntimeUnenhancedClasses and there are numerous known problems with that feature. If others encounter this problem, please please please refer to the OpenJPA Entity enhancement page on how to properly enhance.

其他提示

It seems to be an OpenJPA bug. After several hours of frustration I tested the same code with EclipseLink and it worked flawlessly.

I also learned that EclipseLink is the reference implementation for JPA. I'm going to stick to it on this project.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top