[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[eclipselink-users] ManyToOne, Composite key problem
|
Hi i want to use just one of the composite keys. But i always get:
".... is incomplete. When the source entity class uses a composite
primary key, a @JoinColumn must be specified for each join column
using the @JoinColumns. Both the name and the referenceColumnName
elements must be specified in each such @JoinColumn." error.
my first table is:
table_with_composite_keys
----
* CPK1 - INTEGER
* CPK1 - INTEGER
my second table is:
normal_table
----
* ID - INTEGER
FK_CPK1 - INTEGER
and followings are my entity classes;
---------------------------------
@Entity
@Table(name = "table_with_composite_keys", catalog = "test", schema = "")
public class TableWithCompositeKeys implements Serializable {
private static final long serialVersionUID = 1L;
@EmbeddedId
protected TableWithCompositeKeysPK pk;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "tableWithCompositeKeys")
private List<NormalTable> normalTableList;
public TableWithCompositeKeys() {
}
// .... getters, setters
}
---------------------------------
---------------------------------
@Embeddable
public class TableWithCompositeKeysPK implements Serializable {
@Basic(optional = false)
@Column(name = "CPK1", nullable = false)
private int cpk1;
@Basic(optional = false)
@Column(name = "CPK2", nullable = false)
private int cpk2;
public TableWithCompositeKeysPK() {
}
// getters, setters
}
---------------------------------
---------------------------------
@Entity
@Table(name = "normal_table", catalog = "test", schema = "")
public class NormalTable implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "ID", nullable = false)
private Integer id;
@ManyToOne(optional = false)
@JoinColumn(name = "FK_CPK1", referencedColumnName = "CPK1", nullable = false)
private TableWithCompositeKeys tableWithCompositeKeys;
public NormalTable() {
}
// getters, setters
}
---------------------------------
this is weird but i used same column twice. And it worked.
@JoinColumns({
@JoinColumn(name = "FK_CPK1", referencedColumnName = "CPK1",
nullable = false),
@JoinColumn(name = "FK_CPK1", referencedColumnName = "CPK1",
insertable = false, updatable = false)
})
--
FIRAT KÜÇÜK