This issue can't be edited

Because it belongs to an archived project. Jira admins can restore projects from the archive.

Embeddable object with an ElementCollection that contains Embeddable objects

Description

I have the following objects

@Entity(name = "someClass") public class SomeClass() { @Embedded private EmbeddedObject embeddedObject; }
@Embeddable public class EmbeddedObject () { @ElementCollection private List<ListElement> listElements; }
@Embeddable public class ListElement() { private String name; private String value; }

I was expecting the Mongo object would look like this:

{ "embeddedObject": { "listElements": [ { "name": "someName", "value": "someValue" } ] } }

Instead it looks like this (which is not desired):

{ "embeddedObject": { "listElements": [ { "listElements": { "name": "someName", "value": "someValue" } } ] } }

I can achieve the desired situation as follows:

@Entity(name = "someClass") public class SomeClass() { @ElementCollection private List<ListElement> listElements; }

However, this is not the way I want to store the objects.

Environment

Hibernate HQL: 1.2.0.Final Hibernate OGM: 5.0.0.Final Hibernate OGM MongoDB: 5.0.0.Final MongoDB Java Driver: 3.4.1

Attachments

2
  • 31 Mar 2018, 02:07 PM
  • 31 Mar 2018, 01:59 PM

Activity

Show:

Michael Wirth March 31, 2018 at 2:08 PM

I have the same issue. I really wonder why this issue hasn't come up earlier with more attention as having an ElementCollection in an Embeddable doesn't sound to be an exotic use case. Attention: this is not related having a nestedn ElementCollection in another ElementCollection.

Digging into the code I found the causing issue in the TypeHelper.class in Line 240. The recursive call has no effect at all, as it just copies the values into a new Object array, but doesn't process the result. A quick test showed that the issue can be fixed by applying the result values to the containing object:

Object[] values = replaceAssociations(origComponentValues, targetComponentValues, subtypes, session, (Object) null, copyCache, foreignKeyDirection); componentType.setPropertyValues(target[i], values, null);

Details

Assignee

Reporter

Labels

Bug Testcase Reminder (view)

Bug reports should generally be accompanied by a test case!

Bug Testcase Reminder (edit)

Bug reports should generally be accompanied by a test case!

Participants

MartijnP
Michael Wirth

Components

Affects versions

Priority

Created March 1, 2017 at 1:25 PM
Updated March 31, 2018 at 2:08 PM