Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Persist @ElementCollection Map - The list of fields to insert into the table is empty
Persist @ElementCollection Map - The list of fields to insert into the table is empty [message #1737918] Thu, 14 July 2016 07:23 Go to next message
Kamila Prz is currently offline Kamila PrzFriend
Messages: 1
Registered: July 2016
Junior Member
Hello everyone,

I have fallowing table with user properties: ID_USER, KEY, VALUE, where the PK is {ID_USER,KEY}

The entity looks like:

@Table(name = "USER_PROPERTIES")
public class UserProperties implements Serializable {

    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "ID_USER")
    private Integer id;

    @MapKeyColumn(name = "[key]", table = "USER_PROPERTIES")
    @Column(name = "[value]", table = "USER_PROPERTIES")
    @CollectionTable(name = "USER_PROPERTIES", joinColumns = @JoinColumn(name = "ID_USER"))
    private Map<String, String> properties = new HashMap<>();

    public Integer getId() {
        return id;

    public void setId(Integer id) { = id;

    public Map<String, String> getProperties() {
        return properties;

    public void setProperties(Map<String, String> properties) { = properties;

I can successfully read these entity instances from database, but I am not able to save such entity.
Trying fallowing code:
UserProperties up= new UserProperties();
up.getProperties().put(UserPropertiesKeys.FIRST_NAME.toString(), response.getFirst("fName"));
up.getProperties().put(UserPropertiesKeys.LAST_NAME.toString(), response.getFirst("lName"));
up.getProperties().put(UserPropertiesKeys.COMPANY.toString(), response.getFirst("company"));
up.getProperties().put(UserPropertiesKeys.EMAIL.toString(), response.getFirst("mail"));
up.getProperties().put(UserPropertiesKeys.PHONE.toString(), response.getFirst("phone"));

I am getting fallowing exception:
(Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.QueryException
Exception Description: The list of fields to insert into the table [DatabaseTable(USER_PROPERTIES)] is empty.  You must define at least one mapping for this table.
Query: InsertObjectQuery(null)

The entity before saving looks like this (in JSON):

What am I doing wrong? Can you please explain me how to persist such map?
Any help greatly appreciated!
Re: Persist @ElementCollection Map - The list of fields to insert into the table is empty [message #1738870 is a reply to message #1737918] Mon, 25 July 2016 15:51 Go to previous message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1342
Registered: July 2009
Senior Member
I'm not sure what you are after, but you should not be trying to use an ElementCollection to store properties on what appears to be the same table your UserProperties entity is mapped to. Any entries in your element collection will be read in as entities and collection elements.

Try creating a new table for the elementcollection mapping.
Previous Topic:ClassDescriptor.getPrimaryKeyFieldNames() (Dynamic MOXy)
Next Topic:Access raw unmapped data from Entity
Goto Forum:

Current Time: Sun Apr 05 07:14:58 GMT 2020

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

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

Back to the top