Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » EclipseLink and Nullable Parts composite key
EclipseLink and Nullable Parts composite key [message #1700871] Tue, 07 July 2015 18:48 Go to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13751
Registered: July 2009
Senior Member
I Have the Following Database Table

Some_Table
----------------
ID_A INT
ID_B INT
ID_C STRING
VALUE STRING

(ID_A,ID_B and ID_C) together for the composite key.
but it may be that ID_A or ID_B is null

i try to solve this as follows

@Entity
@Table(name="Some_Table")
public class SomeTable {

@Column(name="VALUE")
private String value;

@EmbeddedId
private MyKey id;
}

public class MyKey {

@Column(name="ID_C", insertable=false, updatable=false) //cause actually
private String idC;

@Column(name="ID_A", insertable=false, updatable=false)
private BigDecimal idA;

@Column(name="ID_B", insertable=false, updatable=false)
private BigDecimal idB;
}

but that is not working:

during the execution of the query was detected to be null. Primary keys must not contain null.

i even tried to add a @Convert(converter=KeyConverter.class) AttributeConverter
but that doesn work either since the converter is never called an so i cannot return a dummy BigDecimal if DB value is Null



Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: EclipseLink and Nullable Parts composite key [message #1701197 is a reply to message #1700871] Thu, 09 July 2015 19:06 Go to previous messageGo to next message
Jan Horyna is currently offline Jan HorynaFriend
Messages: 3
Registered: June 2015
Junior Member
Hi,
I had the same problem some weeks ago.
The true is no part of the compound key can contain nulls.

Workaround: We created new column (Varchar) as new id column and stringified all the values of the old compound key, i.e. 'Val1nullVal2null'.
This way we alway had a valid id.

Have fun
Jan
Re: EclipseLink and Nullable Parts composite key [message #1701293 is a reply to message #1701197] Fri, 10 July 2015 15:01 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13751
Registered: July 2009
Senior Member
thanks, this is the same a we did (change the db) but i hoped for a client side only solution

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Database creation not working in eclipselink with glassfish 4 and postgress
Next Topic:Criteria API and Regexp
Goto Forum:
  


Current Time: Fri Feb 26 07:41:35 GMT 2021

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

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

Back to the top