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
你看看对你的是否有效果,情况有点类似。