This content has been marked as final.
Show 3 replies
-
1. Re: primarykey mapping problem
bill.burke Feb 3, 2006 2:39 PM (in response to jzmmek2k2)Use @IdClass
See Hibernate EntityManager doco or specification . I don't have an wxample of it in the tjutotirals Only @EmbeddedId -
2. Re: primarykey mapping problem
jzmmek2k2 Feb 3, 2006 3:54 PM (in response to jzmmek2k2)Thanks for fast reply, but I still having problems get it working.
The following schema is generatedCREATE TABLE t_customer ( customer_id int8 NOT NULL, firstname varchar(255), lastname varchar(255), CONSTRAINT t_customer_pkey PRIMARY KEY (customer_id) ) WITHOUT OIDS; CREATE TABLE t_friendship ( customer bytea NOT NULL, friend bytea NOT NULL, created timestamp, CONSTRAINT t_friendship_pkey PRIMARY KEY (customer, friend) ) WITHOUT OIDS;
When I deploy the following classes@Entity @Table(name="t_customer") public class Customer implements Serializable { private Long pk = null; private String firstname = null; private String lastname = null; public Customer2() { } public String getFirstname() { return firstname; } public void setFirstname(String name) { this.firstname = name; } public String getLastname() { return lastname; } public void setLastname(String name2) { this.lastname = name2; } @Id @GeneratedValue(strategy=GenerationType.AUTO) @Column(name="customer_id") public Long getPk() { return pk; } public void setPk(Long pk) { this.pk = pk; } }
@Embeddable public class FriendshipPK implements Serializable { private Customer customer = null; private Customer friend = null; public FriendshipPK() { } public Customer getCustomer() { return customer; } public void setCustomer(Customer customer) { this.customer = customer; } public Customer getFriend() { return friend; } public void setFriend(Customer friend) { this.friend = friend; } }
@Entity @Table(name="t_friendship") @IdClass(FriendshipPK.class) public class Friendship { private Customer customer = null; private Customer friend = null; private Date created = null; public Friendship() { } public Date getCreated() { return created; } public void setCreated(Date created) { this.created = created; } @EmbeddedId public Customer getCustomer() { return customer; } public void setCustomer(Customer customer) { this.customer = customer; } @EmbeddedId public Customer getFriend() { return friend; } public void setFriend(Customer friend) { this.friend = friend; } }
There is no difference when using "@Id" instead of "@EmbeddedId" in class "Friendship".
It always generates the columns "customer" & "friend" of type "byte" instead of "int8".
I am using EJB3 RC4-PFD.
Looking in the docs does not really help, because it always describes PK consisting of primitive types.
Would be great if anyone could help me.
Regards
Jan -
3. Re: primarykey mapping problem
epbernard Feb 9, 2006 4:28 PM (in response to jzmmek2k2)please reread the whole chapter about composite primary keys you're are mismatching all annotations.