-->
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.  [ 5 posts ] 
Author Message
 Post subject: mongodb nested object
PostPosted: Sat Apr 11, 2015 1:14 am 
Newbie

Joined: Wed Mar 18, 2015 11:38 am
Posts: 10
Hi, i am testing this case of use with no luck..all fields of the child object are in the parent object.

this is my sample

@Entity
public class News {

@Id
private String id;
private String title;

@Embedded
private NewsPaper paper;

// getters, setters ...
}

@Embeddable
public class NewsPaper {

private String name;
private String owner;

// getters, setters ...
}

this must be the output in my database

{
"_id" : "1234-5678-0123-4567",
"title": "On the merits of NoSQL",
"paper": {
"name": "NoSQL journal of prophecies",
"owner": "Delphy"
}
}

but this is my output

{ "_id" : "1", "owner" : "any owner", "name" : "any name", "id" : "1", "title" : "any title" }

any help please?

thanks and regards!


Top
 Profile  
 
 Post subject: Re: mongodb nested object
PostPosted: Tue Apr 14, 2015 5:25 am 
Hibernate Team
Hibernate Team

Joined: Fri Sep 09, 2011 3:18 am
Posts: 295
Hi,
that's a very strange behaviour.

Are you using the latest OGM version?
Would you be able to provide a small test case or project that we can try?

That should work, if you can give us something to replicate the issue we will have a look at it.

Thanks,
Davide


Top
 Profile  
 
 Post subject: Re: mongodb nested object
PostPosted: Tue Apr 14, 2015 5:28 am 
Hibernate Team
Hibernate Team

Joined: Sat Jan 24, 2009 12:46 pm
Posts: 388
As Davide says, this should work for sure. E.g. check out this test for embeddables, which asserts the persisted document structure: https://github.com/hibernate/hibernate-ogm/blob/master/mongodb/src/test/java/org/hibernate/ogm/datastore/mongodb/test/embeddable/EmbeddableMappingTest.java

You could e.g. take this test as a basis for creating a reproducer.

Hth,

--Gunnar

_________________
Visit my blog at http://musingsofaprogrammingaddict.blogspot.com/


Top
 Profile  
 
 Post subject: Re: mongodb nested object
PostPosted: Tue Aug 25, 2015 5:28 am 
Newbie

Joined: Wed Mar 18, 2015 11:38 am
Posts: 10
I am sorry for been late answering...i have been out ot this for months..

here is a test with the issue

http://www.filedropper.com/test_40


hope it helps!!

Thanks!


Top
 Profile  
 
 Post subject: Re: mongodb nested object
PostPosted: Tue Aug 25, 2015 7:39 am 
Hibernate Team
Hibernate Team

Joined: Fri Sep 09, 2011 3:18 am
Posts: 295
The problem is in the mapping of NewsPaper:

Code:
@Embeddable
public class NewsPaper {
   
   @Column(name="id")
   private String id;
   
   @Column(name="name")
   private String name;
   
   @Column(name="owner")
   private String owner;
...


The @Column#name attribute will not override only the name of the embedded field but it will override the whole field name in the News Document, Therfore instead of paper.owner you have only owner.
If you remove the annotation it should work as expected.

Cheers,
Davide


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.