|
With the two classes
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity
public class A {
@Id
@Column(name="AID", length=8)
private String id;
public String getId() {
return id;
}
}
and
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Embeddable;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.MapsId;
@Entity
public class B {
@Embeddable
public static class B_Key implements Serializable {
private static final long serialVersionUID = 1L;
private String aId;
public B_Key() {}
@Column(name = "BB", length = 1)
private String b;
public String getAId() {
return aId;
}
public void setAId(String value) {
aId = value;
}
public String getB() {
return b;
}
public void setB(String value) {
b = value;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null || !(obj.getClass().equals(this.getClass()))) return false;
B_Key other = (B_Key) obj;
return (aId == null && other.aId == null || aId != null && aId.equals(other.aId)) &&
(b == null && other.b == null || b != null && b.equals(other.b));
}
@Override
public int hashCode() {
return (aId == null ? 0 : aId.hashCode()) ^ (b == null ? 0 : b.hashCode());
}
}
@EmbeddedId
private B_Key id;
@MapsId("aId")
@ManyToOne
@JoinColumn(name = "FK_A")
private A a;
public A getA() {
return a;
}
public void setA (A value) {
a = value;
}
public String getB() {
return id.getB();
}
public void setB(String value) {
id.setB(value);
}
}
the SchemaExport generates the following DDL:
create table A (
AID varchar(8) not null,
primary key (AID)
)
create table B (
FK_A varchar(255),
BB varchar(1) not null,
primary key (FK_A, BB)
)
alter table B
add constraint FK_8u5iivujidu0ix4s4f9cw76ns
foreign key (FK_A)
references A
Why is that foreign key FK_A varchar(255)? I would have expected varchar(8). If I remove the @JoinColumn, I do get varchar(8), but I can no longer give it a name.
How do I get both: varchar(8) and the column being named "FK_A"? Am I doing something wrong here, or is there indeed a problem?
|