OneToOne + MySQL issue [message #635332] |
Tue, 26 October 2010 12:51 |
Eclipse User |
|
|
|
Originally posted by: karsten.triadiary.com
Hi there,
I have little issue I have three objects:
copcompe => OneToMany => copcomki => OneToOne => coprpref
using the following definition:
copcompe:
//bi-directional many-to-one association to Copcomki
@OneToMany(mappedBy="copcompe", fetch=FetchType.LAZY,
cascade=CascadeType.ALL)
public List<Copcomki> getCopcomkis() {}
copcomki:
// 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();
coprpref.setCopcomki(this);
}
return this.coprpref;
}
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):
org.eclipse.persistence.exceptions.DatabaseException
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.
Thanks.
Karsten
(Yes, I scanned the news history and used google consulting.)
|
|
|
|
Powered by
FUDForum. Page generated in 0.01639 seconds