ITeye博客

13.13.13.13.13.13.13.

taeky · 2009-12-17 16:25 · JPA · 企业架构 · Java · junit · PHP · JPA · Bean · Markdown

13.13.13.13.13.13.13.13.13.13.13.13.

评论(3)

  1. #3 楼 · taeky · 2010-03-08 09:35

    TheMatrix writes:

    [code=java] Teacher teacher = em.find(Teacher.Class, 1); [/code]

    :D :D :idea:

  2. #2 楼 · TheMatrix · 2010-03-07 17:44
    
    Teacher teacher = em.find(Teacher.Class, 1);
    
    
  3. #1 楼 · TheMatrix · 2010-03-07 17:41
    
    import javax.persistence.EntityManager;   
    import javax.persistence.EntityManagerFactory;   
    import javax.persistence.Persistence;   
      
    import org.junit.BeforeClass;   
    import org.junit.Test;   
      
    public class ManyToManyTest {   
      
        @BeforeClass  
        public static void setUpBeforeClass() throws Exception {   
        }
        
        @Test  
        public void save() {
            EntityManagerFactory factory = Persistence.createEntityManagerFactory("forthefuture");
            EntityManager em = factory.createEntityManager();
            em.getTransaction().begin();
            Student student = new Student();
            student.setName("Michael");
            Teacher teacher = new Teacher();
            teacher.setName("Tony");
            student.getTeachers().add(teacher);
            em.persist(student);
            em.getTransaction().commit();
            em.close();
            factory.close();   
        }   
      
    }
    
    

评论功能维护中,当前仅展示历史评论。