persistence.PersonDAO.java Source code

Java tutorial

Introduction

Here is the source code for persistence.PersonDAO.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package persistence;

import entities.Person;
import entities.User;
import java.util.List;
import static jdk.nashorn.internal.runtime.Debug.id;
import org.hibernate.Session;

/**
 *
 * @author kobatcon
 */
public class PersonDAO {

    public Person getById(final int id) {

        Session session = Conection.getSessionFactory().openSession();
        return (Person) session.get(Person.class, id);

    }

    public List<Person> getByName(final String name) {
        Session session = Conection.getSessionFactory().openSession();
        List<Person> listPerson = session.createQuery("select p from Person as p where p.name = :paramName")
                .setParameter("paramName", name).list();
        session.getSessionFactory().close();
        return listPerson;
    }
}