Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » OneToOne + MySQL issue
OneToOne + MySQL issue [message #635332] Tue, 26 October 2010 12:51 Go to next message
Eclipse UserFriend
Originally posted by:

Hi there,

I have little issue I have three objects:

copcompe => OneToMany => copcomki => OneToOne => coprpref

using the following definition:

//bi-directional many-to-one association to Copcomki
@OneToMany(mappedBy="copcompe", fetch=FetchType.LAZY,
public List<Copcomki> getCopcomkis() {}

// bi-directional many-to-one association to Copcompe
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "COPCOMPE_ID", nullable = false,
referencedColumnName = "ID")
public Copcompe getCopcompe() {
return this.copcompe;

//bi-directional one-to-one association to Coprpref
@OneToOne(fetch=FetchType.LAZY, cascade=CascadeType.ALL, optional=false)
@JoinColumn(name="ID", referencedColumnName="COPCOMKI_ID", unique=true,
insertable=false, updatable=false)
public Coprpref getCoprpref() {
if (coprpref == null) {
coprpref = new Coprpref();
return this.coprpref;

// bi-directional one-to-one association to Copcomki
@OneToOne(mappedBy = "coprpref", optional=false)
public Copcomki getCopcomki() {
return this.copcomki;

After creating a new copcompe adding a copcomki and coprpref I call
persist and the database throws the following exception:

javax.persistence.RollbackException: Exception [EclipseLink-4002]
(Eclipse Persistence Services - 2.1.0.v20100614-r7608):
Internal Exception: java.sql.BatchUpdateException: Field 'COPCOMKI_ID'
doesn't have a default value
Error Code: 1364
Query: ValueReadQuery(sql="SELECT LAST_INSERT_ID()")

I tested several different mapping definition for the one to one part,
but nothing seems to work. Other associations (OneToMany) in my
datamodel work perfect.

Any hints, how to solve that issue.


(Yes, I scanned the news history and used google consulting.)
Re: OneToOne + MySQL issue [message #635638 is a reply to message #635332] Wed, 27 October 2010 14:59 Go to previous message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1294
Registered: July 2009
Senior Member

I believe you have mapped the bidirectional relationship between copcomki and coprpref incorrectly. You seem to have a read-only relationship on copcomki ->coprpref specifying the ID in copcomki is the foreign key and the 'COPCOMKI_ID' field in coprpref is the target. I assume it is read-only since any relationship change would cause your ID field to change which is not allowed. The problem is that the coprpref ->copcomki relationship is set to be mappedby the other side - this means that it too is effectively read-only since the other side controls the relationship in the database.

You may want remove the insertable=false and updatable=false, and switch the joinColumn and Mappedby on the two relationships so that coprpref ->copcomki controls it. This will allow the foreign key in coprpref to be set when the relationship is.

Best Regards,
Previous Topic:Need to figure out how to properly configure EclipseLink
Next Topic:Trouble converting SQL into JPQL with OUTER JOIN
Goto Forum:

Current Time: Sat Apr 21 20:38:36 GMT 2018

Powered by FUDForum. Page generated in 0.02336 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software