Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] history table cannot use automatic increment column as primary

I have tried two kinds of the history thing. Let's separate them as

 

Situation 1,

I use the date-time as the primary column, it's also the start-date of the history policy.  When I create an entry with history policy, and then do the merge operation, the exception thrown.

Current database is Mysql, and I use datetime type in database.

 

Situation 2,

As the situation above, I want to solve this. So I add an extra auto increment column with name versionid to the history table, which is different from the id column.

At this situation the above problem disappeared, but when I print the id, after persist, the id was 1, then merge it, the id changed to be 2.

The demo code is here:

Consignee consignee=new Consignee();

em.persist(consignee);

em.flush();

System.out.println(consignee.getId()); //the id is 1

em.merge(consignee);

System.out.println(consignee.getId()); //the id is 2

 

Regards,

Joe

 

-----Original Message-----
From: eclipselink-users-bounces@xxxxxxxxxxx [mailto:eclipselink-users-bounces@xxxxxxxxxxx] On Behalf Of James Sutherland
Sent: Wednesday, October 27, 2010 9:36 PM
To: eclipselink-users@xxxxxxxxxxx
Subject: Re: [eclipselink-users] history table cannot use automatic increment column as primary

 

 

Could you include your mappings and the SQL that is generated.

 

Are you using the HistoryPolicy?  Does it work without the HistroyPolicy?

 

The history table must not use an IDENTITY column, as the id of the source object will be inserted.

 

For the date-time issue, what database are you using, and to what level of precision does it store the date-time?  Are you inserting the same object and then updating it in another transaction in the same millisecond?

 

 

 

Joe(Zhou Xiangtao) wrote:

>

> Hi everyone,

>

>

> The problem is when I use an automatic increment id, the java object

> will get the wrong id, could anyone know how to solve it.

>

>

> For example:

>

>                 Consignee consignee= new Consignee();

>

>                 // . add some data

>

>                 entityManager.persist(consignee);

>

>

> after persist, the consignee.getId() is not the same as in database,

> you can make a test. It's easy.

>

>

> Plus, if I use a datetime column as primary column, the above problem

> solved,  but the duplicated key exception keeps popup, if  the insert

> and update at same time.

>

>

> Regards,

>

> Joe

>

 

 

-----

http://wiki.eclipse.org/User:James.sutherland.oracle.com James Sutherland http://www.eclipse.org/eclipselink/

EclipseLink ,  http://www.oracle.com/technology/products/ias/toplink/

TopLink

Wiki:  http://wiki.eclipse.org/EclipseLink EclipseLink , http://wiki.oracle.com/page/TopLink TopLink

Forums:  http://forums.oracle.com/forums/forum.jspa?forumID=48 TopLink , http://www.nabble.com/EclipseLink-f26430.html EclipseLink

Book:  http://en.wikibooks.org/wiki/Java_Persistence Java Persistence

--

View this message in context: http://old.nabble.com/history-table-cannot-use-automatic-increment-column-as-primary-tp30053636p30067328.html

Sent from the EclipseLink - Users mailing list archive at Nabble.com.

 

_______________________________________________

eclipselink-users mailing list

eclipselink-users@xxxxxxxxxxx

https://dev.eclipse.org/mailman/listinfo/eclipselink-users


Back to the top