[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[List Home]
|
[eclipselink-users] ManyToOne, Composite key problem
|
- From: Fırat KÜÇÜK <firatkucuk@xxxxxxxxx>
- Date: Mon, 20 Jul 2009 11:15:40 +0300
- Delivered-to: eclipselink-users@eclipse.org
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:date:message-id:subject :from:to:content-type:content-transfer-encoding; bh=Qgr05kGzN3FL7eIx6t4SUUvyg/HhlKMORs9kAziptZA=; b=iKxUrrysOM8kHecvY3tDWUL7s1Ow5aseLKbX0zGWQGY+77CPX0l/ZOwyMphW2Lvm0A pX5q5Zt4Y1nhoZL2il6tZZB2luKQBfq5llwBmR+ai2P0aN5m2RpBg/mgXLEuoQFzRPB9 MQTgEjqYnhbEWsLwVYnUU+0q+mdrGwfm9AjJg=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type :content-transfer-encoding; b=bMMoiFIFNaI+SY3K/OQnJrumwimTox0Xuo9KAPIOSEgGkF8rz8YgM5AkXuFAby3tLI v1KpeR3fLC6iyWSJlbz3qBdFM0T4yyrrwRZYWJlz158/sDePPKLcf9a1aUL8JPZfib2W i/jbiFLOc7LIMq7M/p+zE4528RcyIvaCq/vEo=
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