@OneToOne relation PK not filled [message #1781229] |
Sat, 03 February 2018 16:43 |
Arco van der Velden Messages: 6 Registered: October 2017 |
Junior Member |
|
|
I have two entities with a @OneToOne relation the problem is that the PK isn't filled automatically with the @GeneratedValue(strategy = GenerationType.IDENTITY) of the other entity.
I have the following definitions
public class Relatie implements Serializable
{
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "relatienummer", nullable = false)
private Integer relatienummer;
@OneToOne(cascade = CascadeType.ALL, mappedBy = "relatie", fetch = FetchType.LAZY)
private Persoon persoon;
}
public class Persoon implements Serializable
{
private static final long serialVersionUID = 1L;
@Id
@Basic(optional = false)
@NotNull
@Column(name = "relatienummer", nullable = false)
private Integer relatienummer;
@JoinColumn(name = "relatienummer", referencedColumnName = "relatienummer", nullable = false, insertable = false, updatable = false)
@OneToOne(optional = false, fetch = FetchType.LAZY)
private Relatie relatie;
}
When persisting Relatie with Persoon set with entitymanger.persist the following SQL is executed on commit.
Fine: INSERT INTO relatie (notitie, relatietype, taalcode) VALUES (?, ?, ?)
bind => [null, P, DE]
Fine: SELECT LAST_INSERT_ID()
Fine: INSERT INTO persoon (relatienummer, achternaam, initialen, tussenvoegsel, voornaam) VALUES (?, ?, ?, ?, ?)
bind => [null, null, asd, null, null]
Fine: SELECT 1
Warning: Local Exception Stack:
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.6.4.qualifier): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Column 'relatienummer' cannot be null
Can anybody help me out with this ?
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02451 seconds