日期:2014-05-17  浏览次数:20682 次

请大家帮我看一下,运行Hibernate时报异常,该怎么处理?谢谢啦!
请大家帮我看一下,运行Hibernate时报异常,该怎么处理?这个异常是什么意思?谢谢啦!

如果我在网上搜这个异常是什么意思,是不是搜“org.hibernate.DuplicateMappingException: Duplicate collection role mapping wxw.hibernate.bean.person.emails
”这一行了?

我是模仿书上写的,麻烦说详细一点,谢谢啦!

异常:
%%%% Error Creating SessionFactory %%%%
org.hibernate.DuplicateMappingException: Duplicate collection role mapping wxw.hibernate.bean.person.emails
at org.hibernate.cfg.Configuration$MappingsImpl.addCollection(Configuration.java:2439)
at org.hibernate.cfg.annotations.CollectionBinder.bind(CollectionBinder.java:511)
at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:1906)
at org.hibernate.cfg.AnnotationBinder.processIdPropertiesIfNotAlready(AnnotationBinder.java:769)
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:733)
at org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:636)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:359)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1377)
at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:954)
at wxw.hibernate.util.HibernateSessionFactory.rebuildSessionFactory(HibernateSessionFactory.java:76)
at wxw.hibernate.util.HibernateSessionFactory.getSession(HibernateSessionFactory.java:59)
at wxw.hibernate.test.t.main(t.java:69)
Exception in thread "main" java.lang.NullPointerException
at wxw.hibernate.test.t.main(t.java:71)


测试类:T
public class t {
public static void main(String[] args) {
person p =new person();
p.setName("用户1");
email e1 =new email();
e1.setAccount("user@126.com");
e1.setPassword("123456");
p.getEmails().add(e1);

email e2 = new email();
e2.setAccount("user@123.com");
e2.setPassword("123456");
p.getEmails().add(e2);

Session session = HibernateSessionFactory.getSession();
// session.beginTransaction();
Transaction trans = session.beginTransaction();
session.persist(p);
// session.getTransaction().commit();
trans.commit();
session.close(); }
}


实体类:Email
@Entity
@Table(name = "tb_email")
public class email {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public Integer id;
@Column(name = "account")
public String account;
@Column(name = "password")
public String password;
省略 get…,set…等方法 
}


实体类:person
@Entity
@Table(name = "tb_person")
public class person {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public Integer id;
@Column(name = "name")
public String name;

// fetch =&nbs