package zhang.jpa.test;
import java.util.Arrays;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;
import javax.persistence.Query;
import org.hibernate.ejb.QueryHints;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import zhang.jpa.helloword.Department;
import zhang.jpa.helloword.Employee;
import zhang.jpa.helloword.Item;
import zhang.jpa.helloword.Manager;
import zhang.jpa.helloword.Type;
import zhang.jpa.helloword.User;
public class Testonetoone {
private EntityManagerFactory entityManagerFactory = null;
private EntityManager entityManager = null;
private EntityTransaction transaction = null;
@Before
public void init() {
String persistenceUnitName = "jpa-1";
entityManagerFactory = Persistence.createEntityManagerFactory(persistenceUnitName);
entityManager = entityManagerFactory.createEntityManager();
transaction = entityManager.getTransaction();
transaction.begin();
}
@After
public void after() {
transaction.commit();
entityManager.close();
entityManagerFactory.close();
}
//
@Test
public void testjpqlupdate(){
String jpql="update Employee set name=? where id=?";
entityManager.createQuery(jpql).setParameter(1, "java").setParameter(2, 2).executeUpdate();
}
//
@Test
public void testjpqldelete(){
String jpql="delete from Employee e where e.id=?";
entityManager.createQuery(jpql).setParameter(1, 1).executeUpdate();
}
@Test
public void testjpqlfunction(){
String jpql="select upper(e.name),upper(e.email),email from Employee e";
List