mardi 30 juin 2015

How I get a @NamedQuery Query with WERE Command in Java EE?

hi i have a java ee application and I want to create a Query to get all Tickets from a User.

I have a Ticket class, TicketDAO Interface and TicketBean class I have a User class, UserDAO interface and UserBean class

Here is my User class:

  @Entity
    @NamedQueries({
        @NamedQuery(name=User.QUERY_GETALL,query="SELECT c FROM User c"),
        @NamedQuery(name=User.QUERY_GETALLTICKETS,query="SELECT c FROM Ticket c ...????"),
    })
    public class User implements Serializable{

        /**
         * 
         */
        private static final long serialVersionUID = 1L;

        public static final String QUERY_GETALL = "User.GetAll";

        public static final String QUERY_GETALLTICKETS = "User.GetAllTickets";
...

here is my UserBean class:

@Override
public List<Ticket> getAllUserTickets() {

    return em.createNamedQuery(User.QUERY_GETALLTICKETS,Ticket.class).getResultList();
}

My Ticket Table have the column username.

Aucun commentaire:

Enregistrer un commentaire