-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: Mapping of embedded collection field names in MongoDB
PostPosted: Mon Oct 22, 2012 11:55 am 
Newbie

Joined: Mon Oct 22, 2012 11:41 am
Posts: 4
I'm experimenting with OGM and MongoDB with a JPA annotated model. I have an entity/class that contains an embedded collection:

Code:
    @ElementCollection()
    public java.util.List<Context> getContext() {


with Context.java being:

Code:
@Embeddable
public class Context implements java.io.Externalizable {
    private Type _type=Type.Conversation;
    private String _value=null;
    .....
    // suitable accessors and modifiers for these two fields


When I examine some test data in the MongoDB, I see:

Code:
{ "_id" : { "unitId" : "au1", "unitIndex" : 0 }, "context" : [    {    "context.collection&&element.type" : 2,    "context.collection&&element.value" : "corr1" },    {    "context.collection&&element.type" : 0,    "context.collection&&element.value" : "12345" } ], "properties" : [    {    "name" : "customer",    "value" : "Fred" },    {    "name" : "trader",    "value" : "Joe" } ] }


The 'properties' field is an element collection also, but a map as opposed to a list, but it seems to be represented as I would expect. However the context elements have unexpected field names?

Is there a way that these fields can simply have the 'type' and 'value' names that I would get if I serialized the object model to JSON?

Second question relates to the way enumerated types are stored. The 'type' field is an enumerated type, and being stored as its numerical value. However a jackson/json serialized form uses the enumerated value's name rather than index, which from a query perspective seems more natural. Is there a way to configure the datastore provider to use this approach instead?

Thanks in advance.


Top
 Profile  
 
 Post subject: Re: Mapping of embedded collection field names in MongoDB
PostPosted: Tue Oct 23, 2012 10:09 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Damn that is not supposed to happen.
It looks like you have fallen in the same issue described at https://hibernate.onjira.com/browse/HHH-6005

Can you do me a favor and send me a unit test to reproduce your issue as well as as much information as possible (configuration file etc etc). I have opened a dedicated issue for this https://hibernate.onjira.com/browse/OGM-251

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Re: Mapping of embedded collection field names in MongoDB
PostPosted: Tue Oct 23, 2012 11:52 am 
Newbie

Joined: Mon Oct 22, 2012 11:41 am
Posts: 4
Sure, I'll get one sorted out tomorrow and attach to the jira.

Regards
Gary


Top
 Profile  
 
 Post subject: Re: Mapping of embedded collection field names in MongoDB
PostPosted: Wed Oct 24, 2012 6:17 am 
Newbie

Joined: Mon Oct 22, 2012 11:41 am
Posts: 4
Hi Emmanuel

Test case has now been attached to the jira.

Any thoughts on the second point, regarding the representation of the enumerated types? Is it possible to use the text value instead of index?

Regards
Gary


Top
 Profile  
 
 Post subject: Re: Mapping of embedded collection field names in MongoDB
PostPosted: Wed Oct 24, 2012 8:48 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Thanks.
By the way in the mean time you can map your data using a @OneToMany. This will have the same effect for MongoDB than @ElementCollection. The alternative is to explicit set the column names which also work around the issue.

About enums, have you tried @Enumerated? It might not work in which case open a JIRA issue.

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Re: Mapping of embedded collection field names in MongoDB
PostPosted: Wed Oct 24, 2012 10:16 am 
Newbie

Joined: Mon Oct 22, 2012 11:41 am
Posts: 4
Thanks Emmanuel, both of those suggestions worked.

Regards
Gary


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.