Search for a query using two or more parameters in JPA

I'm still new at the Hibernate/JPA world and i'm stuck here trying to make a function in the same way of searching by id but i'm trying to search and return fields from the database using two parameters, i did a DAO method to my project too with the basic CRUD operations plus this special one. At the time to do the search it gave me this return stacktrace:

Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Provided id of the wrong type for class com.exemplo.model.Pedido. Expected: class java.lang.Long, got class java.sql.Date
    at org.hibernate.jpa.spi.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:1135)
    at org.hibernate.jpa.spi.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:1068)
    at com.exemplo.repositorio.MySQLPedidoDAO.pesquisarPorData(MySQLPedidoDAO.java:82)
    at com.exemplo.view.ViewPedidos.btBuscarActionPerformed(ViewPedidos.java:322)
    at com.exemplo.view.ViewPedidos.access$000(ViewPedidos.java:23)
    at com.exemplo.view.ViewPedidos$1.actionPerformed(ViewPedidos.java:106)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
    at java.awt.Component.processMouseEvent(Component.java:6533)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
    at java.awt.Component.processEvent(Component.java:6298)
    at java.awt.Container.processEvent(Container.java:2236)
    at java.awt.Component.dispatchEventImpl(Component.java:4889)
    at java.awt.Container.dispatchEventImpl(Container.java:2294)
    at java.awt.Component.dispatchEvent(Component.java:4711)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4888)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4525)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4466)
    at java.awt.Container.dispatchEventImpl(Container.java:2280)
    at java.awt.Window.dispatchEventImpl(Window.java:2746)
    at java.awt.Component.dispatchEvent(Component.java:4711)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
    at java.awt.EventQueue.access$500(EventQueue.java:97)
    at java.awt.EventQueue$3.run(EventQueue.java:709)
    at java.awt.EventQueue$3.run(EventQueue.java:703)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
    at java.awt.EventQueue$4.run(EventQueue.java:731)
    at java.awt.EventQueue$4.run(EventQueue.java:729)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
Caused by: org.hibernate.TypeMismatchException: Provided id of the wrong type for class com.exemplo.model.Pedido. Expected: class java.lang.Long, got class java.sql.Date
    at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:133)
    at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1066)
    at org.hibernate.internal.SessionImpl.access$2000(SessionImpl.java:176)
    at org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.load(SessionImpl.java:2540)
    at org.hibernate.internal.SessionImpl.get(SessionImpl.java:951)
    at org.hibernate.jpa.spi.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:1110)
    ... 41 more

My methods are in this way, DAO class:

public interface DAO <T, K> {

    public void inserir(T o);

    public void alterar(T o);

    public void excluir(T o);

    public T pesquisar(K id);

    public List<T> listar();

}

PedidoDAO:

public interface PedidoDAO extends DAO <Pedido, Long> {

    public Pedido pesquisarPorData(Date dataCadastro);

}

MySQLPedidoDAO: (Error at PesquisarPorData function)

public class MySQLPedidoDAO implements PedidoDAO {

    public ConnectionFactory cf = null;

    public MySQLPedidoDAO(ConnectionFactory cf) {
        this.cf = cf;
    }

    @Override
    public Pedido pesquisar(Long id) {
        cf.createEm().getTransaction().begin();
        Pedido pedido = cf.createEm().find(Pedido.class, id);
        cf.createEm().getTransaction().commit();
        //erro ao deletar pois o factory já está fechado
        //emf.close();
        return pedido;
    }

    @Override
    public Pedido pesquisarPorData(Date dataCadastro) {
        cf.createEm().getTransaction().begin();
        // ERROR AT THE LINE UNDER!!!!!
        Pedido pedido = cf.createEm().find(Pedido.class, dataCadastro);
        cf.createEm().getTransaction().commit();
        //erro ao deletar pois o factory já está fechado
        //emf.close();
        return pedido;
    }

}

ViewPedidos:

public class ViewPedidos extends javax.swing.JInternalFrame {

    private MySQLPedidoDAO mspdao;
    private Pedido ped;
    private boolean editavel;

    /* Getters e Setters from editavel and ped  */

    private void btPesquisaActionPerformed(java.awt.event.ActionEvent evt) {
        habilitarApenasOSeData();
        limparCampos();
        tfPedido.setEditable(true);
        tfPedido.requestFocus();
        btBuscar.setEnabled(true);
    } 

    private void btBuscarActionPerformed(java.awt.event.ActionEvent evt) {
        ConnectionFactory cf = new ConnectionFactory();
        MySQLPedidoDAO mspdao = new MySQLPedidoDAO(cf);
        Pedido ped = new Pedido();

        if(tfPedido.getText().length() == 0  &&  tfDataCad.getText().length() == 0){
             JOptionPane.showMessageDialog(rootPane, "Search not succeed, please fill the fields above", "Search", JOptionPane.INFORMATION_MESSAGE);
        } else {
             ped = mspdao.pesquisar(Long.parseLong(tfPedido.getText()));
             ped = mspdao.pesquisarPorData(new java.sql.Date(((java.util.Date)tfDataCad.getValue()).getTime()));
             setPed(ped);
             setEditable(true);
             carregarCampos();
             habilitarTextFieldEBotoes();
        }

    }   

}

I've tested commenting the codes that involve the date fields only letting the id to be searched and it runned very well, i've tried to do a quick fix to search through id and register date doing two different methods as above, i've tried doing a createQuery and nothing went on, I'd like to know where am i doing wrong? or any tips to make a search function in JPA using two or more params? (Obs: my code is in portuguese because it's a brazilian project sorry for it or any mistake) and thanks in advance!!

The problem is that EntityManager#find requires that you provide the primary key for your entity (which is a Long ). If you want to query using other fields you need to use createQuery instead.

You haven't provided the entity definition in your question. However the query would be something like:

TypedQuery<Pedido> query = cf.createEm().createQuery("id = :id and registerDate = :date", Pedido.class);
query.setParameter("date", dataCadastro);
query.setParameter("id", id);
List<Pedido> results = query.getResultList();

If you're only expecting a single result you can call query.getSingleResult() instead of getResultList() . This will throw NonUniqueResultException if there is not a single result.