本帖最后由 lpy3654321 于 2011-11-14 17:39:00 编辑

解决方案 »

  1.   

    会不会是需要加:@ManyToMany(fetch = FetchType.LAZY)
      

  2.   

    但是运行不过去啊。这是测试代码
    import org.hibernate.Session;
    import org.hibernate.SessionFactory;
    import org.hibernate.cfg.AnnotationConfiguration;
    import org.hibernate.tool.hbm2ddl.SchemaExport;
    import org.junit.AfterClass;
    import org.junit.BeforeClass;
    import org.junit.Test;import com.model.*;
    public class StudentTest {
    private static SessionFactory sessionFactory = null;

    // @BeforeClass
    public static void beforeClass(){
    sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();
    }
    // @AfterClass
    public static void afterClass(){
    sessionFactory.close();
    }

    @Test
    public void testSchemaExport() {
    new SchemaExport(new AnnotationConfiguration().configure()).create(false, true);
    }}
      

  3.   

    发现在问题了:集合必要为Set ,我弄成HashSet了。大家可以试一下我这个,看看。
      

  4.   


    配置文件中集合支持hashSet么? 
    好像hibernate的配置文件支持:set,map,list,array,bag
      

  5.   

    就是因为不支持HashSet所以才错的。 
      

  6.   

    最好不要用“ManyToMany”,因为中间表往往还有其他字段。
      

  7.   

    Hibernate 中不能使用实体类的,要用接口
      

  8.   

    转化为两个@OneToMany,中间表作为Many方。
      

  9.   

    改成Set<Teacher> teachers = new HashSet<Teacher>();这样就行了。