I'm new in the JSP/EL/EJB WORLD so take it in count please... heheh
My question is a continuation of a PREVIOUS Q?
so in the comments/answers of the question above is recommended to use customerFacade.findByUserName(String userName), but the problem is that I can't do use of such @NamedQuery.
My code is as Follow:
CustomerFacade
package Session;
//imports **
@Stateless
public class CustomerFacade extends AbstractFacade<Customer> {
@PersistenceContext(unitName = "OnlineStorePU")
private EntityManager em;
@Override
protected EntityManager getEntityManager() {
return em;
}
public CustomerFacade() {
super(Customer.class);
}
}
Customer
package Entity;
//imports***
@Entity
@Table(name = "customer")
@XmlRootElement
@NamedQueries({
@NamedQuery(name = "Customer.findAll", query = "SELECT c FROM Customer c"),
@NamedQuery(name = "Customer.findById", query = "SELECT c FROM Customer c WHERE c.id = :id"),
@NamedQuery(name = "Customer.findByName", query = "SELECT c FROM Customer c WHERE c.name = :name"),
@NamedQuery(name = "Customer.findByMobile", query = "SELECT c FROM Customer c WHERE c.mobile = :mobile"),
@NamedQuery(name = "Customer.findByEmail", query = "SELECT c FROM Customer c WHERE c.email = :email"),
@NamedQuery(name = "Customer.findByAddress", query = "SELECT c FROM Customer c WHERE c.address = :address"),
@NamedQuery(name = "Customer.findByFax", query = "SELECT c FROM Customer c WHERE c.fax = :fax"),
@NamedQuery(name = "Customer.findByTelephone", query = "SELECT c FROM Customer c WHERE c.telephone = :telephone"),
@NamedQuery(name = "Customer.findByUsername", query = "SELECT c FROM Customer c WHERE c.username = :username")})
public class Customer implements Serializable {
/**
* all generated attributes from DB import Wizard
* no findAll() or findByXxxxx() is declared here
* So that is the reason I Assume that all @NamedQueries{}
* are somehow creating functions with Name as @NameQuery
*
*/
}
My question is Do I need to implement the @NamedQuery as functions, if so HOW?
You must use something like this
You can use
TypedQuey
: