0

I have a organization class as follows

@Entity
@Table(name = "org")
public class Organization implements Serializable {

    private static final long serialVersionUID = 1L;
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      private long id;
      private String orgname;

I am trying to link Org table to from userorg table. The link between the two is , userorg table references orgid.

@Entity
@Table(name = "user_org")
public class UserOrganization implements Serializable {

  @Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  private long id;

  private long userid;
  private long orgid;

  @OneToOne(cascade=CascadeType.ALL) 
  @JoinTable(name="user_organizationList",joinColumns={@JoinColumn(name="orgid", referencedColumnName="id")})
  private Organization orgData;

The orgData is always null.

Can anyone please help me to establish this join

RandomWanderer
  • 701
  • 2
  • 12
  • 23
  • try this [How to create join table with JPA annotations -](http://stackoverflow.com/questions/7979382/how-to-create-join-table-with-jpa-annotations) – sasanka Dec 17 '15 at 04:52
  • maybe you need inverseJoinColumns? – Ivan Aracki Dec 17 '15 at 09:55
  • @sasanka the examples join with primary key. In my case, I want to join User and Userorg with orgid where orgid is not a primary key in user table – RandomWanderer Dec 17 '15 at 20:39
  • Following the documentation, maybe you're missing the inverseJoinColmuns part. http://docs.oracle.com/javaee/7/api/javax/persistence/JoinTable.html – Eria Dec 18 '15 at 08:12

0 Answers0