users@glassfish.java.net

Re: EJBQL Exception

From: <glassfish_at_javadesktop.org>
Date: Mon, 30 Apr 2007 22:28:15 PDT

Thanks to the two people who have made suggestions.

I tried adding the @ManyToOne and @JoinColumns attributes as suggested below and revising my query as you suggested on the mailing list. Unfortunately, it seems to break the application, as it would not run with Seller defined in that manner. (At one point the application server even hung, so I had to reinstall, thus the lengthy delay to my reply). I had to roll back to my original definition to restore the application to run at all, though it still leaves me with the Exception regarding the query.

In hopes it will help generate more ideas, here are the entire definition files for the Entities Seller and SelCat. I followed the form used in a Java reference application from Sun, which I am coming to see is not well-formed.

Thanks again for the suggestions to this point.

Seller.java:

package com.sun.javaee.blueprints.petstore.model;

import com.sun.javaee.blueprints.petstore.util.PetstoreUtil;
import java.util.ArrayList;
import java.util.Arrays;
import static javax.persistence.CascadeType.ALL;
import java.util.Collection;
import java.util.Vector;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.TableGenerator;

/**_at_NamedQueries(
 { @NamedQuery(
      name="Seller.getSellersPerDesignation",
      query="SELECT s FROM Seller s WHERE s.selcatid = :selcatid and s.disabled = 0"
    ),
    @NamedQuery(
      name="Seller.getAllZipCityState",
      query="SELECT z FROM ZipLocation z"
    )
  }
)
*/

@Entity
public class Seller implements java.io.Serializable {

    private String sellerID;
    private String selcatID;
    private String name;
    private Address address;
    private SellerContactInfo contactInfo;
    private int disabled;

      
    public Seller() { }
    public Seller(String selcatID, String name,
            Address address, SellerContactInfo contactInfo)
    {
        this.selcatID = selcatID;
        this.name = name;
        this.address = address;
        this.contactInfo = contactInfo;
        this.disabled = 0;
    }
    
    @TableGenerator(name="SELLER_ID_GEN",
            table="ID_GEN",
            pkColumnName="GEN_KEY",
            valueColumnName="GEN_VALUE",
            pkColumnValue="SELLER_ID",
            allocationSize=1)
    @GeneratedValue(strategy=GenerationType.TABLE,generator="SELLER_ID_GEN")
    
    @Id
    public String getSellerID() {
        return sellerID;
    }
    
    public String getSelCatID() {
        return selcatID;
    }

    public String getName() {
        return name;
    }

    @OneToOne(cascade={CascadeType.PERSIST})
    public Address getAddress() {
        return address;
    }
    
    @OneToOne(cascade={CascadeType.PERSIST})
    public SellerContactInfo getContactInfo() {
        return contactInfo;
    }
 
    public int getDisabled() {
        return disabled;
    }
    
    public void setSellerID(String sellerID) {
        this.sellerID = sellerID;
    }
    public void setSelCatID(String selcatID) {
        this.selcatID = selcatID;
    }
    public void setName(String name) {
        this.name = name;
    }
    public void setAddress(Address address) {
        this.address = address;
    }
    public void setContactInfo(SellerContactInfo contactInfo) {
        this.contactInfo = contactInfo;
    }
    public void setDisabled(int disabled) {
        this.disabled = disabled;
    }
    
    /**
     * This method checks to make sure the class values are valid
     *
     * @return Message(s) of validation errors or and empty array (zero length) if class is valid
     */
    public String[] validateWithMessage() {
        ArrayList<String> valMess=new ArrayList<String>();
        
        if(name == null || name.equals("")) {
            valMess.add(PetstoreUtil.getMessage("invalid_contact_firstname"));
        }

        // to make sure seller is valid, have to check address and contact also
        valMess.addAll(Arrays.asList(contactInfo.validateWithMessage()));
        valMess.addAll(Arrays.asList(address.validateWithMessage()));
        
        return valMess.toArray(new String[valMess.size()]);
    }
    
}


SelCat.java:

package com.sun.javaee.blueprints.petstore.model;

import com.sun.javaee.blueprints.petstore.util.PetstoreUtil;
import java.util.ArrayList;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.TableGenerator;

@Entity
public class SelCat implements java.io.Serializable {
    
    private String selcatID;
    private String name;
     
    public SelCat() { }
    public SelCat(String name) {
        this.name = name;
    }
    
    @TableGenerator(name="SELCAT_ID_GEN",
            table="ID_GEN",
            pkColumnName="GEN_KEY",
            valueColumnName="GEN_VALUE",
            pkColumnValue="SELCAT_ID",
            allocationSize=1)
            @GeneratedValue(strategy=GenerationType.TABLE,generator="SELCAT_ID_GEN")
 
           @Id
            public String getSelCatID() {
        return selcatID;
    }
    
    public String getName() {
        return name;
    }
    
    public void setSelCatID(String selcatID) {
        this.selcatID = selcatID;
    }
    public void setName(String name) {
        this.name = name;
    }
     
    /**
     * This method checks to make sure the class values are valid
     *
     * @return Message(s) of validation errors or and empty array (zero length) if class is valid
     */
    public String[] validateWithMessage() {
        ArrayList<String> valMess=new ArrayList<String>();
        
        // make sure make and address is entered
        if(name == null || name.equals("")) {
            valMess.add(PetstoreUtil.getMessage("invalid_contact_lastname"));
        }
            
        return valMess.toArray(new String[valMess.size()]);
    }
    
}
[Message sent by forum member 'drscoville' (drscoville)]

http://forums.java.net/jive/thread.jspa?messageID=215006