EclipseLink ignores strategy for id generation - P

2019-09-10 10:48发布

问题:

Please look at my apps configuration. As it is marked in the answer, I have changed target-database to "Database" due to the bug of EclipseLink. I have @GeneratedValue(strategy=GenerationType.IDENTITY) on my entities id. In the database this column is of serial type. When I try to save a new object to the database I get following log:

2015-11-08T23:37:20.748+0100|Finer: client acquired: 133317409 2015-11-08T23:37:20.760+0100|Finer: TX binding to tx mgr, status=MARKED_ROLLBACK 2015-11-08T23:37:20.761+0100|Finer: acquire unit of work: 1890544759 2015-11-08T23:37:20.762+0100|Finest: persist() operation called on: com.amleto.server.model.entities.FacebookDebug@7e0498c2. 2015-11-08T23:37:20.763+0100|Finer: TX beginTransaction, status=MARKED_ROLLBACK 2015-11-08T23:37:20.764+0100|Finest: Execute query DataModifyQuery(name="SEQ_GEN_IDENTITY" sql="UPDATE SEQUENCE SET SEQ_COUNT = SEQ_COUNT + #PREALLOC_SIZE WHERE SEQ_NAME = #SEQ_NAME") 2015-11-08T23:37:20.766+0100|Finest: Connection acquired from connection pool [default]. 2015-11-08T23:37:20.767+0100|Finest: reconnecting to external connection pool 2015-11-08T23:37:20.771+0100|Fine: UPDATE SEQUENCE SET SEQ_COUNT = SEQ_COUNT + ? WHERE SEQ_NAME = ? bind => [1, SEQ_GEN_IDENTITY] 2015-11-08T23:37:20.883+0100|Warning: Local Exception Stack: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.6.1.v20150605-31e8258): org.eclipse.persistence.exceptions.DatabaseException Internal Exception: org.postgresql.util.PSQLException: ERROR: relation "sequence" does not exist Position: 8 Error Code: 0 Call: UPDATE SEQUENCE SET SEQ_COUNT = SEQ_COUNT + ? WHERE SEQ_NAME = ? bind => [1, SEQ_GEN_IDENTITY]

Clearly something is wrong. Do you have any idea?

回答1:

Your solution to your previous problem isn't a solution and should be revisited. Using the 'database' generic platform means you cannot take advantage of database specific features of PostgreSQL, such as identity and is defaulting to a sequence internally that hasn't been created.

Unless you are willing to create a sequence, the only way this will work will be to have set.