当前位置: 代码迷 >> Java Web开发 >> 小弟我用注解annotation映射数据库时,出现这种异常,大神们,帮忙看下
  详细解决方案

小弟我用注解annotation映射数据库时,出现这种异常,大神们,帮忙看下

热度:65   发布时间:2016-04-16 22:23:57.0
我用注解annotation映射数据库时,出现这种错误,大神们,帮忙看下,
Exception in thread "main" org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [com.qin.co.Teacher#1]
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:168)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:121)
at org.hibernate.event.


import javax.persistence.Entity;
import javax.persistence.Id;

@Entity
public class Teacher {
  private int id;
  private String name;
  private int age;
@Id  
public int getId() {
return id;
}      
public void setId(int id) {
this.id = id;
}

<session-factory>
        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="hibernate.connection.url">jdbc:mysql://localhost/hibernate</property>
        <property name="hibernate.connection.username">root</property>
        <property name="hibernate.connection.password">123</property>
    <property name="show_sql">true</property>
<property name="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</property>
<property name="hbm2ddl.auto">create</property>
  <!-- <mapping resource="com/qin/co/Student.hbm.xml" /> --> 
    <mapping  class="com.qin.co.Teacher"/> 

</session-factory>



------解决方案--------------------
http://blog.csdn.net/ak47947/article/details/3452592
你看看对你的是否有效果,情况有点类似。
  相关解决方案