package com.zyp.jpa2; import java.util.List; import javax.persistence.EntityManager; import javax.persistence.EntityManagerFactory; import javax.persistence.Persistence; import javax.persistence.Query; import com.zyp.openjpa.Animal; public class Main { public static void main(String[] args) { EntityManagerFactory factory = Persistence.createEntityManagerFactory("hibernatetest", System.getProperties()); EntityManager em = factory.createEntityManager(); em.getTransaction().begin(); Animal ee = new Animal(); ee.setName("a1"); em.persist(ee); em.getTransaction().commit(); em.close(); EntityManager em2 = factory.createEntityManager(); Query q = em2.createQuery("select m from Animal m"); for (Animal m : (List<Animal>) q.getResultList()) { System.out.println(m.getId() + "--" + m.getName()); } em2.close(); factory.close(); } }

flygrass LV12
2023年12月7日
zmlzsw LV8
2021年12月10日
1171120570 LV1
2020年12月18日
zuiwomengjiaren LV11
2020年9月4日
zhengshuang LV1
2020年5月31日
vpv123
2020年3月7日
暂无贡献等级
Jay1109 LV1
2019年12月11日
Lee9527 LV1
2019年9月12日
dd168168
2019年8月26日
暂无贡献等级
zxx521125 LV9
2019年8月26日