-->
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.  [ 1 post ] 
Author Message
 Post subject: Share columns between composite key and @ManyToOne JoinColum
PostPosted: Mon Jul 08, 2013 8:36 am 
Newbie

Joined: Mon Jul 08, 2013 8:33 am
Posts: 1
I'm having a problem that I don't know if it's possible to solve just by using hibernate/jpa annotations. The problem is that I have a composite key that has the same column as one of my foreignkey composite id, and I would like to share this same column on the table. For example:

Code:
@Entity
class Id {
  @Id
  @Column(name = "idPessoa")
  public Integer idShared;
}


Code:
@Embeddable
class APK {
  @ManyToOne
  @JoinColumn(name = "idShared")
  public Id idShared;
  public String nKey;
}


Code:
@Entity
class A {
  @EmbeddedId
  public APK id;
}


Code:
@Embeddable
class BPK {
  @ManyToOne
  @JoinColumn(name = "idShared")
  public Id idShared;
  public Integer nCode;
}


Code:
@Entity
class B {
  @EmbeddedId
  public BPK id;

  @ManyToOne
  @JoinColumns({ @JoinColumn(name = "idShared", nullable = false, insertable = false, updatable = false), @JoinColumn(name = "nKey", nullable = false) })
  public A a;
}


The question is how I can share the column idShared between A and B and use it in the @ManyToOne for the foreign key?

I already tried to use @JoinColumn inside @JoinColumns with the name idShared but I get an error saying that I need to use insert = false and update = false, I already put insertable = false and updateable = false, but then I get another error saying that I can't mix things.

I found a possible solution saying to use:

Code:
@ManyToOne
@JoinColumnsOrFormulas(value = {
@JoinColumnOrFormula(formula = @JoinFormula(value = "idShared", referencedColumnName = "idShared")),
@JoinColumnOrFormula(column = @JoinColumn(name = "nKey", nullable = false)) })
public A a;


But it gives me the error:

Unable to find column with logical name in table A
It appears that the "name" property of the column it has to find is blank someway.

Need some help please!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.