[hibernate-dev] [OGM] AssociationKey table property during the create tuple association

Emmanuel Bernard emmanuel at hibernate.org
Wed Mar 7 12:16:11 EST 2012


On 7 mars 2012, at 18:00, Guillaume SCHEIBEL wrote:

> OK, but to set the fk to B into A I need to retrieve (from the DB would be good I think) the current instance of B. 

No, why?
In this case you will need to create a mongodb document that contains the navigational information to go from a to b. That's what Hibernate OGM expects conceptually at least.
And Hibernate OGM will ask and load the right association keys and then the entity keys to load the object graph.

> When you say " you should have two RowKeys " you mean, two calls to the createAssociationTuple method right ?
> 

Ahhhh sorry, I did not mean rowKey but EntityKey. Sorry about this confusion.

> 
> Guillaume
> 
> 
> 2012/3/7 Emmanuel Bernard <emmanuel at hibernate.org>
> No, you should have two RowKeys, one for Entity A and one for Entity B (speaking of instances here).
> AssociationKey represents the navigational info to go from A to B (B to A would be represented by a second AssociationKey object).
> And what would be stored is the list of navigational info (in your case one to one, the list is of size 0 or 1).
> 
> The nav info is made of:
> - the fk from A
> - the fk to B
> - optionally the index or map key value
> 
> The AssociationKey is made of:
> 
> - the association table name (in your example EntityA)
> - the asso fk name and value, in your case entityb_id: "abc"
> 
> On 7 mars 2012, at 17:08, Guillaume SCHEIBEL wrote:
> 
> > Hello,
> >
> > I'm writting the OGM dialect for mongodb and I work on the @OneToOne
> > association.
> > When the createTupleAssociation method is called, there is an
> > AssociationKey parameter which should (I think) represents the object to
> > which we are associated.
> >
> > Let's take a very short example:
> >
> > class EntityA {
> >
> >       @Id
> >       String id;
> >
> >       @OneToOne
> >       EntityB entityb;
> >
> >       //with getters, setters,  etc.
> > }
> >
> > class EntityB {
> >       @Id
> >       String id;
> >
> >       //with getters, setters,  etc.
> > }
> >
> > Currently, the rowKey object refers to EntityA (with the table name and the
> > id) and AssociationKey refers to EntityB. But the table property of
> > AssociationKey is set to entityA and not entityB as it should be.
> >
> > Did I miss something or is it a real "bug" ?
> >
> > Thanks
> > Guillaume
> > _______________________________________________
> > hibernate-dev mailing list
> > hibernate-dev at lists.jboss.org
> > https://lists.jboss.org/mailman/listinfo/hibernate-dev
> 
> 




More information about the hibernate-dev mailing list