EJBQL Exception

Hi,

I'm a Java Persistence newbie having a massive problem spotting the error that is triggering an Unknown state or association field exception.

I have created a Persistence Entity based on the PetStore 2.0 Reference App with the following excerpted code, plus the necessary get/set methods:

@Entity

public class Seller implements java.io.Serializable {

private String sellerID;

private String selcatID;

private String name;

public Seller() { }

public Seller(String sellerID, String selcatID, String name)

{

this.sellerID = sellerID;

this.selcatID = selcatID;

this.name = name;

}

In another Java file, I have a method that references the selcatID attribute of the Seller entity:

@SuppressWarnings("unchecked")

public List<Seller> getSellersBySelCatVLH(String selCatID, int start,

int chunkSize){

EntityManager em = emf.createEntityManager();

Query query = em.createQuery("SELECT s FROM Seller s, SelCat t WHERE " +

"s.selcatID = t.selcatID AND t.selcatID = :selcatID AND s.disabled = 0" +

" ORDER BY s.name");

List<Seller> sellers = query.setParameter("selcatID",selCatID).setFirstResult(start).setMaxResults(chunkSize).getResultList();

em.close();

return sellers;

}

Note that the case usage in the selcatID call in the method matches the case used in the Entity definition code. Yet I continue to get this exception:

Exception [TOPLINK-8030] (Oracle TopLink Essentials - 2006.8 (Build 060830)): oracle.toplink.essentials.exceptions.EJBQLException

Exception Description: Unknown state or association field [selcatID] of class [...Seller].

I have been through the server log stack trace and confirmed that this is the only method cited in the trace that references this attribute.

Can anyone spot what I am missing?

Thanks in advance for any guidance.

[1963 byte] By [dmscovillea] at [2007-11-27 2:54:22]
# 1
The seller class is incomplete. for every field that is persistable you need to have a getter and setter method.Thats why it's complaining that selcatID is an unknown state. Define a getter and setter for it.Budyanto
Budyanto.Himawana at 2007-7-12 3:30:08 > top of Java-index,Java Essentials,New To Java...
# 2

Thank you for the input. I do have getter-setter methods for those variables defined in the class, I merely neglected to include them in the paste.

The issue was resolved by changing the reference to the selCatID key in the Seller class to a reference to a SelCat object, adding attributions @ManyToOne and @JoinColumn before the getSelCat() method in Seller, and simplifying the query in the method.

regards,

Doug

dmscovillea at 2007-7-12 3:30:08 > top of Java-index,Java Essentials,New To Java...
# 3

Hi Doug,

I meet the same exception on my project, but not know where my problem lies. Please help. Thank you.

Exception Description: Unknown state or association field [projectNoSub] of class [database.SfcWip].

@Entity

@Table(name = "SFC_WIP")

@NamedQueries( {

@NamedQuery(name = "SfcWip.findByProjectNoSub", query = "SELECT s FROM SfcWip s WHERE s.sfcWipPK.projectNoSub = :projectNoSub"),

@NamedQuery(name = "SfcWip.findByPcbPartNo", query = "SELECT s FROM SfcWip s WHERE s.sfcWipPK.pcbPartNo = :pcbPartNo"),

@NamedQuery(name = "SfcWip.findByPcbQty", query = "SELECT s FROM SfcWip s WHERE s.pcbQty = :pcbQty"),

@NamedQuery(name = "SfcWip.findByFlowId", query = "SELECT s FROM SfcWip s WHERE s.flowId = :flowId"),

@NamedQuery(name = "SfcWip.findByStatus", query = "SELECT s FROM SfcWip s WHERE s.status = :status"),

@NamedQuery(name = "SfcWip.findByRemarks", query = "SELECT s FROM SfcWip s WHERE s.remarks = :remarks")

})

public class SfcWip implements Serializable {

/**

* EmbeddedId primary key field

*/

@EmbeddedId

protected SfcWipPK sfcWipPK;

@Column(name = "PCB_QTY")

private BigDecimal pcbQty;

@Column(name = "FLOW_ID")

private String flowId;

@Column(name = "STATUS")

private String status;

@Column(name = "REMARKS")

private String remarks;

@OneToMany(cascade = CascadeType.ALL, mappedBy = "sfcWip")

private Collection<SfcWiptran> sfcWiptranCollection;

/** Creates a new instance of SfcWip */

public SfcWip() {

}

public SfcWip(SfcWipPK sfcWipPK) {

this.sfcWipPK = sfcWipPK;

}

public SfcWip(String pcbPartNo, String projectNoSub) {

this.sfcWipPK = new SfcWipPK(pcbPartNo, projectNoSub);

}

public SfcWipPK getSfcWipPK() {

return this.sfcWipPK;

}

public void setSfcWipPK(SfcWipPK sfcWipPK) {

this.sfcWipPK = sfcWipPK;

}

public BigDecimal getPcbQty() {

return this.pcbQty;

}

public void setPcbQty(BigDecimal pcbQty) {

this.pcbQty = pcbQty;

}

public String getFlowId() {

return this.flowId;

}

public void setFlowId(String flowId) {

this.flowId = flowId;

}

public String getStatus() {

return this.status;

}

public void setStatus(String status) {

this.status = status;

}

public String getRemarks() {

return this.remarks;

}

public void setRemarks(String remarks) {

this.remarks = remarks;

}

public Collection<SfcWiptran> getSfcWiptranCollection() {

return this.sfcWiptranCollection;

}

public void setSfcWiptranCollection(Collection<SfcWiptran> sfcWiptranCollection) {

this.sfcWiptranCollection = sfcWiptranCollection;

}

@Override

public int hashCode() {

int hash = 0;

hash += (this.sfcWipPK != null ? this.sfcWipPK.hashCode() : 0);

return hash;

}

@Override

public boolean equals(Object object) {

// TODO: Warning - this method won't work in the case the id fields are not set

if (!(object instanceof SfcWip)) {

return false;

}

SfcWip other = (SfcWip)object;

if (this.sfcWipPK != other.sfcWipPK && (this.sfcWipPK == null || !this.sfcWipPK.equals(other.sfcWipPK))) return false;

return true;

}

@Override

public String toString() {

return "database.SfcWip[sfcWipPK=" + sfcWipPK + "]";

}

}

@Embeddable

public class SfcWipPK implements Serializable {

@Column(name = "PROJECT_NO_SUB", nullable = false)

private String projectNoSub;

@Column(name = "PCB_PART_NO", nullable = false)

private String pcbPartNo;

/** Creates a new instance of SfcWipPK */

public SfcWipPK() {

}

public SfcWipPK(String pcbPartNo, String projectNoSub) {

this.pcbPartNo = pcbPartNo;

this.projectNoSub = projectNoSub;

}

public String getProjectNoSub() {

return this.projectNoSub;

}

public void setProjectNoSub(String projectNoSub) {

this.projectNoSub = projectNoSub;

}

public String getPcbPartNo() {

return this.pcbPartNo;

}

public void setPcbPartNo(String pcbPartNo) {

this.pcbPartNo = pcbPartNo;

}

@Override

public int hashCode() {

int hash = 0;

hash += (this.pcbPartNo != null ? this.pcbPartNo.hashCode() : 0);

hash += (this.projectNoSub != null ? this.projectNoSub.hashCode() : 0);

return hash;

}

@Override

public boolean equals(Object object) {

// TODO: Warning - this method won't work in the case the id fields are not set

if (!(object instanceof SfcWipPK)) {

return false;

}

SfcWipPK other = (SfcWipPK)object;

if (this.pcbPartNo != other.pcbPartNo && (this.pcbPartNo == null || !this.pcbPartNo.equals(other.pcbPartNo))) return false;

if (this.projectNoSub != other.projectNoSub && (this.projectNoSub == null || !this.projectNoSub.equals(other.projectNoSub))) return false;

return true;

}

@Override

public String toString() {

return "database.SfcWipPK[pcbPartNo=" + pcbPartNo + ", projectNoSub=" + projectNoSub + "]";

}

}

Ng_Clementa at 2007-7-12 3:30:08 > top of Java-index,Java Essentials,New To Java...