[hibernate-dev] [OGM] Mapping associations in MongoDB

Guillaume SCHEIBEL guillaume.scheibel at gmail.com
Wed Apr 25 12:06:38 EDT 2012


Simply because I didn't know this annotation :)
next time I won't say anything  ;)

(at least I've learn something)


Guillaume

2012/4/25 Emmanuel Bernard <emmanuel at hibernate.org>

> Why not use @ElementCollection for such a case instead of @OneToMany?
>
>
> On 25 avr. 2012, at 17:54, Guillaume SCHEIBEL <
> guillaume.scheibel at gmail.com> wrote:
>
> No, I don't think so
>
> The first case could be:
> class Post {
>     @OneToMany
>     List<Comment> comments;
>      //...
> }
>
> and so in mongodb
>
> {
>     "_id": ObjectId("4f981b173572f2a35c3826f8"),
>     "title": "About collections",
>     "comments": [
>     {
>         "author": "Emmanuel",
>         "content": "my comment"
>     },
>     {
>         "author": "Sanne",
>         "content": "my comment too"
>     }]
> }
>
>
>
> The second case:
> class Person {
>     @OneToOne
>     Address address;
>     //...
> }
>
> which gives:
> {
>     "_id": ObjectId("4f981dc43572f2a35c3826f9"),
>     "name": "Guillaume",
>     "address": {
>         "city": "Strasbourg",
>         "zipcode": 67000
>     }
> }
>
> Am I completely wrong ?
>
> Guillaume
>
>
> 2012/4/25 Emmanuel Bernard <emmanuel at hibernate.org>
>
>>
>> On 25 avr. 2012, at 10:05, Guillaume SCHEIBEL wrote:
>>
>> At the very beginning, I thought to manage association like this:
>>
>>    - Case of @OneTo* associations could be managed like embeddeds (for
>>    me it makes sens and close to the mongo way)
>>    - Case of @ManyTo* associations could be managed in a usual way
>>    (association collections, etc.)
>>
>>
>> i believe you mean the other way around. Respectively @*ToOne and @*ToMany
>>
>
>


More information about the hibernate-dev mailing list