Reputation: 780
I'm doing my first application in JSF 2.0 with JPA in Netbeans.
How do I use a different named query of my Java entity in JSF? For example I have this entity,
@Entity
@Table(name = "user")
@XmlRootElement
@NamedQueries({
@NamedQuery(name = "User.findAll", query = "SELECT u FROM User u"),
@NamedQuery(name = "User.findById", query = "SELECT u FROM User u WHERE u.id = :id"),
@NamedQuery(name = "User.findByUser", query = "SELECT u FROM User u WHERE u.user = :user"),
@NamedQuery(name = "User.findByPassword", query = "SELECT u FROM User u WHERE u.password = :password"),
@NamedQuery(name = "User.findByMail", query = "SELECT u FROM User u WHERE u.mail = :mail")})
public class User implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Basic(optional = false)
@NotNull
@Column(name = "id")7
private Integer id;
and I want have the option in JSF to use a different named query like findByMail
, findByUser
, etc.
I see that in the code generated by Netbeans I have a Vector
with the result of findAll
. Is that good? Is that not going to be a big vector if I have a lot of data in my database? Is it not better to do in 100 of 100 queries?
The generated JSF page is always the same. Is this normal? Can I generate a URL?
Upvotes: 0
Views: 1475
Reputation: 12505
You seem to be using the Netbeans wizard - and understand little of the generated code. You are lost to the point where you can't even ask the right question, not to mention understanding the answer. You don't grasp the difference between JSF and JPA, JPQL and SQL, vector and collection etc.
Feel free to ignore my advice, but my strong opinion is that you NEED to learn the technologies used first, and try the wizard later. The Netbeans wizard that generates JSF CRUD pages from database is not meant as an out-of-the-box solution, in fact the templates have known bugs. It could be used for fun, it could be used to impress your friends at a party - but it is an extremely poor as an educational tool.
Upvotes: 3