-
1. Re: Is there any easy way to a create primary key for combin
bill.burke Feb 2, 2006 3:41 PM (in response to liudan2005)Yes.
But there are two ways:
@IdClass - PK class is not a property of your class.
@EmbeddedId - PK class is a property in your class -
2. Re: Is there any easy way to a create primary key for combin
liudan2005 Feb 2, 2006 4:34 PM (in response to liudan2005)I get following error:
org.hibernate.PropertyNotFoundException: Could not find a setter for property bytes in class java.lang.String
here is what my code looks like:
@EmbeddedId
public String getFirstname() {
return firstname;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
}
@EmbeddedId
public String getLastname() {
return lastname;
}
public void setLastname(String lastname) {
this.lastname = lastname;
} -
3. Re: Is there any easy way to a create primary key for combin
mooktarus Feb 2, 2006 5:59 PM (in response to liudan2005)You still haven't made a PK class!
From PFD:
"There must be only one EmbeddedId annotation and no Id annotation when the EmbeddedId annotation is used."
Geez, I'm getting to be a spec weenie!
You need to define a PK class that contains firstname and lastname. You can then use @AttributeOverrides with the @EmbeddedId to map the columns to the members of your PK class, though that may be unnecessary. Check out the composite tutorial that came with the EJB3 distribution. -
4. Re: Is there any easy way to a create primary key for combin
truto Feb 3, 2006 12:13 PM (in response to liudan2005)I use both idcall and embeddedid on entity classes but had no much
luck -- a "select table Table from Table table" having Table an idclass annotation or using the embeddedid pattern, returned a list with the correct number of entries, but all of them NULL
... then I abandoned that idea and use rowid from oracle as id for all tables with more than one ID, or none at all :-( -
5. Re: Is there any easy way to a create primary key for combin
epbernard Feb 9, 2006 4:33 PM (in response to liudan2005)there are working examples in the hibernate annotations documentation. Check http://annotations.hibernate.org