Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Does Glassfish Enterprise Server v2.1.1 require identity field == null?

843833Dec 15 2009 — edited Dec 22 2009
I recently migrated from J2EE server
Java Platform, Enterprise Edition 5 SDK Update 5
to
Sun GlassFish Enterprise Server v2.1.1 ((v2.1 Patch06)(9.1_02 Patch12)) (build b31g-fcs)
and encountered this problem.

Our entity beans are initialised with an Integer identity field set to -1 (instead of NULL). When an entity is written to the DB, the IDENTITY field is automatically assigned a unique value. The app used to work OK. But the new Glassfish Server attempts to INSERT these entities twice, while persisting collections. If I change the IDENTITY field to NULL then the app functions correctly. Is this a known "feature"? There are a lot of entities in the app and I don't want to spend time rewriting them all (and adding NULL checks in misc methods) unless absolutely necessary.

Does anyone in the Glassfish Community recognise this problem. Thanks!

First the failed trace

ENTRY net.bawtry.webshop.PhraseAdmin[id=65]
client acquired
TX binding to tx mgr, status=STATUS_ACTIVE
Merge clone with references net.bawtry.webshop.PhraseAdmin[id=65]
Execute query ReadObjectQuery(net.bawtry.webshop.entities.Phrase)
reconnecting to external connection pool
SELECT id, phrase, languageCode, phraseAdminID, companyID FROM phrase WHERE (id = ?)
bind => [-1]
Register the object net.bawtry.webshop.PhraseAdmin[id=65]
Execute query DoesExistQuery()
Register the object net.bawtry.webshop.Company [id=3]
Execute query DoesExistQuery()
PERSIST operation called on: net.bawtry.webshop.PhraseAdmin[id=-1].
Execute query ReadObjectQuery(net.bawtry.webshop.entities.Phrase)
reconnecting to external connection pool
SELECT id, phrase, languageCode, phraseAdminID, companyID FROM phrase WHERE (id = ?)
bind => [-1]
Register the object net.bawtry.webshop.PhraseAdmin[id=65]
Execute query DoesExistQuery()
Register the object net.bawtry.webshop.Company [id=3]
Execute query DoesExistQuery()
PERSIST operation called on: net.bawtry.webshop.PhraseAdmin[id=-1].
TX beforeCompletion callback, status=STATUS_ACTIVE
begin unit of work commit
TX beginTransaction, status=STATUS_ACTIVE
Execute query UpdateObjectQuery(net.bawtry.webshop.PhraseAdmin[id=65])
Execute query InsertObjectQuery(net.bawtry.webshop.PhraseAdmin[id=-1])
Execute query WriteObjectQuery(net.bawtry.webshop.PhraseAdmin[id=65])
Execute query WriteObjectQuery(net.bawtry.webshop.Company [id=3])
reconnecting to external connection pool
INSERT INTO phrase (phrase, languageCode, phraseAdminID, companyID) VALUES (?, ?, ?, ?)
bind => [Choisez votre, fr, 65, 3]
Execute query ValueReadQuery()
SELECT @@IDENTITY
assign sequence to the object (69 -> net.bawtry.webshop.PhraseAdmin[id=-1])
Execute query InsertObjectQuery(net.bawtry.webshop.PhraseAdmin[id=-1])
Execute query WriteObjectQuery(net.bawtry.webshop.PhraseAdmin[id=65])
Execute query WriteObjectQuery(net.bawtry.webshop.Company [id=3])
INSERT INTO phrase (phrase, languageCode, phraseAdminID, companyID) VALUES (?, ?, ?, ?)
bind => [Choisez votre, fr, 65, 3]
Local Exception Stack:
Exception [TOPLINK-4002] (Oracle TopLink Essentials - 2.1 (Build b31g-fcs (10/19/2009))): oracle.toplink.essentials.exceptions.DatabaseException
Internal Exception: com.microsoft.sqlserver.jdbc.SQLServerException: Violation of UNIQUE KEY constraint 'ukPhrase'. Cannot insert duplicate key in object 'dbo.phrase'.
Error Code: 2627
Call: INSERT INTO phrase (phrase, languageCode, phraseAdminID, companyID) VALUES (?, ?, ?, ?)
bind => [Choisez votre, fr, 65, 3]
Query: InsertObjectQuery(net.bawtry.webshop.PhraseAdmin[id=-1])
at oracle.toplink.essentials.exceptions.DatabaseException.sqlException(DatabaseException.java:311)
==========================


Now the successful trace with IDENTITY == NULL

ENTRY net.bawtry.webshop.PhraseAdmin[id=65]
client acquired
TX binding to tx mgr, status=STATUS_ACTIVE
Merge clone with references net.bawtry.webshop.PhraseAdmin[id=65]
Register the object net.bawtry.webshop.PhraseAdmin[id=65]
Execute query DoesExistQuery()
Register the object net.bawtry.webshop.Company [id=3]
Execute query DoesExistQuery()
PERSIST operation called on: net.bawtry.webshop.PhraseAdmin[id=null].
TX beforeCompletion callback, status=STATUS_ACTIVE
begin unit of work commit
TX beginTransaction, status=STATUS_ACTIVE
Execute query UpdateObjectQuery(net.bawtry.webshop.PhraseAdmin[id=65])
Execute query InsertObjectQuery(net.bawtry.webshop.PhraseAdmin[id=null])
Execute query WriteObjectQuery(net.bawtry.webshop.PhraseAdmin[id=65])
Execute query WriteObjectQuery(net.bawtry.webshop.Company [id=3])
reconnecting to external connection pool
INSERT INTO phrase (phrase, languageCode, phraseAdminID, companyID) VALUES (?, ?, ?, ?)
bind => [Choisez votre, fr, 65, 3]
Execute query ValueReadQuery()
SELECT @@IDENTITY
assign sequence to the object (66 -> net.bawtry.webshop.PhraseAdmin[id=null])
TX afterCompletion callback, status=COMMITTED
end unit of work commit
ENTRY 125
client acquired
TX binding to tx mgr, status=STATUS_ACTIVE
Execute query ReadObjectQuery(net.bawtry.webshop.entities.PhraseAdmin)
TX beforeCompletion callback, status=STATUS_ACTIVE
begin unit of work commit
TX afterCompletion callback, status=COMMITTED
end unit of work commit
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 19 2010
Added on Dec 15 2009
1 comment
221 views