hutorny wrote:
illusion wrote:
Hey,
Is there a way to query individual fields of a composite key. I find with the way stated every field of the key must be specified. If I wanted to query just one field of say a 3 field key how to get around it.
thanks in advance for your assistance
Try this. Folks saying it should work.
Code:
String querystring ="from Group group where group.NamePK.FirstName = 'myname'";
Hi, i'm trying to do this, but i still cant.
Look at my classes
Code:
@Embeddable
public class CustomerPK implements Serializable {
private static final long serialVersionUID = 314150377756575581L;
private long id;
private long dId;
private int wId;
@Column(name = "C_ID", nullable = false)
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
@Column(name = "C_D_ID", nullable = false)
public long getDId() {
return dId;
}
public void setDId(long id) {
dId = id;
}
@Column(name = "C_W_ID", nullable = false)
public int getWId() {
return wId;
}
...
Code:
@Entity
@Table(name = "CUSTOMER")
@NamedQueries({
@NamedQuery(name = "selectAllCustomers", query = "select c from Customer c"),
@NamedQuery(name = "countAllCustomers", query = "select count(*) from Customer c"),
@NamedQuery(name = "deleteAllCustomers", query = "delete from Customer c"),
@NamedQuery(name = "getCustomerByLastNameAndHomeWarehouse", query = "from " +
"Customer c where c.cPk.dId=:dId and c.cPk.wId=:wId and c.last=:last")
})
public class Customer implements Serializable {
private static final long serialVersionUID = -6640493644418267201L;
private CustomerPK cPk;
...
private String last;
...
@EmbeddedId
@AttributeOverrides({
@AttributeOverride(name="id", column=@Column(name="C_ID", nullable = false)),
@AttributeOverride(name="dId", column=@Column(name="C_D_ID", nullable = false)),
@AttributeOverride(name="wId", column=@Column(name="C_W_ID", nullable = false))
})
public CustomerPK getCPk() {
return cPk;
}
....
When i try to obtain an EntityManagerFactory, un exception raises:
ERROR [main] (Log4JLogger.java:119) - Error in named query: getCustomerByLastNameAndHomeWarehouse
org.hibernate.QueryException: could not resolve property: cPK of: br.ufpr.***.Customer [from br.ufpr.***.Customer c where c.cPK.dId=:dId and c.cPk.wId=:wId and c.last=:last]
Does anyone knows why is this happening?
Thks.
Murilo