Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Error in Eclipselink with @ElementCollectionMap and @JoinColumn

You currently can not use a non-id field within the join columns of your element collection.

Note: This is an optional component of the spec (section 10.1.21):

"Support for referenced columns that are not primary key columns of the referenced table is optional. Applications that use such mappings will not be portable."

Feel free to log an enhancement request.


----- Original Message ----- From: "vide" <vidas.timukas@xxxxxxxxx>
To: <eclipselink-users@xxxxxxxxxxx>
Sent: Wednesday, March 10, 2010 8:22 AM
Subject: [eclipselink-users] Error in Eclipselink with @ElementCollectionMap and @JoinColumn


I stuck with problem when I try to use @ElementCollection join to Map with
@JoinColumn, which is not a primary key. When I try to update a Map,
JoinColumn value becomes null and Eclipselink return with error.

My entity:
---------------- @Entity
@Table(name = "cust")
public class Customer implements Serializable {
   private static final long serialVersionUID = 1L;
   @GeneratedValue(strategy = GenerationType.IDENTITY)
   @Column(name = "id")
   private Long id;
   @Column(name = "name")
   private String name;
   @Column(name = "address", nullable = false)
   private String address;

   @CollectionTable(name = "address_info",
       joinColumns = {
           @JoinColumn(name = "x_address", referencedColumnName =
   @MapKeyColumn(name = "info_tag")
   @Column(name = "info_value")
   private Map<String, String> extInfo;

   public Customer() {
       extInfo = new HashMap<String, String>();

   public Customer(String name, String address) {
       this(); = name;
       this.address = address;

   ...Getters and setters

------------- Customer cust = new Customer("My Customer", "Arctic");
cust.setInfo("postIndex", "12345");

Error log:
------------- FINE: INSERT INTO cust (address, name) VALUES (?, ?)
       bind => [Arctic, My Customer]
FINE: SELECT id, address, name FROM cust WHERE (id = ?)
       bind => [1]
FINE: SELECT t0.info_value, t0.info_tag FROM address_info t0 WHERE
(t0.x_address = ?)
       bind => [Arctic]
FINE: INSERT INTO address_info (x_address, info_value, info_tag) VALUES (?,
?, ?)
       bind => [null, 12345, postIndex]
WARNING: Local Exception Stack:
Exception [EclipseLink-4002] (Eclipse Persistence Services -
2.0.0.v20091127-r5931): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception:
Column 'x_address' cannot be null
Error Code: 1048
Call: INSERT INTO address_info (x_address, info_value, info_tag) VALUES (?,
?, ?)
       bind => [null, 12345, postIndex]
Query: DataModifyQuery(sql="INSERT INTO address_info (x_address, info_value,
info_tag) VALUES (?, ?, ?)")

When I remove em.flush() and em.refresh(cust), everything works fine, until
next transaction, when I try to find inserted entity and make an update to
Map, error returns. If I change JoinColumn to use entity's ID, problem
disappears. Why I can't use JoinColumn, different from ID column?


View this message in context:
Sent from the EclipseLink - Users mailing list archive at

eclipselink-users mailing list

Back to the top