-->
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.  [ 2 posts ] 
Author Message
 Post subject: Bidirectional and EmbeddedId
PostPosted: Sun Mar 21, 2010 10:23 am 
Newbie

Joined: Tue Dec 02, 2008 2:47 pm
Posts: 3
Location: Linz, Austria
Hello,

I have model (simplified version described below) and cannot configure bidirectional association.

Exactly to say — I can access A and B from Bind class (Bind freshly fetched from DB).
But I cannot access Binds neither from A or from B (A and B freshly fetched from DB).

getBindings always returns null though mappedBy properly set.

I tried without EmbeddedId - an it works in both directions.

What is wrong in my config?

Many thanks

Code:
@Entity
class A {
  @Id
  private Integer id;
  @OneToMany(mappedBy = "key.a")
  private Collection<Bind> bindings;
}

@Entity
class B {
  @Id
  private Integer id;
  @OneToMany(mappedBy = "key.b")
  private Collection<Bind> bindings;
}

@Entity
class Bind {
  @EmbeddedId
  private BindPK key;
  @Basic
  private String bindProperty;
}

@Embedded
class BindPK {
  @ManyToOne
  private A a;
  @ManyToOne
  private B b;
}

_________________
veni vedi vici


Top
 Profile  
 
 Post subject: Re: Bidirectional and EmbeddedId
PostPosted: Sun Mar 21, 2010 12:27 pm 
Newbie

Joined: Tue Dec 02, 2008 2:47 pm
Posts: 3
Location: Linz, Austria
Solution found in internet — usage of @IdClass instead of @EmbeddedId

Code:
@Entity
class A {
  @Id
  private Integer id;
  @OneToMany(mappedBy = "a")
  private Collection<Bind> bindings;
}

@Entity
class B {
  @Id
  private Integer id;
  @OneToMany(mappedBy = "b")
  private Collection<Bind> bindings;
}

@Entity
@IdClass(BindPK.class)
class Bind {
  @Id
  private A a;
  @Id
  private B b;
  @Basic
  private String bindProperty;
}

@Embedded
class BindPK {
  @ManyToOne
  private A a;
  @ManyToOne
  private B b;
}

_________________
veni vedi vici


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