Hi there:
From my web interface when I insert a word to the database, it works fine. But, when I insert the second it gives me the following error. It seems Hibernate is trying to insert the second one with the same ID as the first one. I have stuck with this problem for a week. Please help:
Does this have anything to do with cached objects in a session? But, I closed the session everytime after the insert.
Below is the error messages, config file and the code that caused them:
error message
-------------------------
2004-04-06 16:29:19,494 net.sf.hibernate.util.JDBCExceptionReporter ERROR-could not insert: [com.blu.words.Word#0238b990fbc1b95400fbc1b9a1720006]java.sql.SQLException: Invalid argument value, message from server: "Duplicate entry '0238b990fbc1b95400fb' for key 1"
2004-04-06 16:29:19,494 net.sf.hibernate.impl.SessionImpl ERROR-Could not synchronize database state with sessionnet.sf.hibernate.JDBCException: could not insert: [com.blu.words.Word#0238b990fbc1b95400fbc1b9a1720006]
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:478)
config file
-----------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="com.blu.words.Word"
table="mywords">
<id name="id" type="string"
unsaved-value="null">
<column name="ID" sql-type="char(20)"
not-null="true"/>
<generator class="uuid.hex"/>
</id>
<property name="word">
<column name="word" sql-type="char(20)"
not-null="true"/>
</property>
<property name="gloss">
<column name="gloss" sql-type="char(50)"
not-null="true"/>
</property>
<property name="detail">
<column name="detail" sql-type="char(255)"
not-null="false"/>
</property>
<property name="created">
<column name="created" sql-type="date"
not-null="true"/>
</property>
<property name="reviewed">
<column name="reviewed" sql-type="integer"
not-null="true"/>
</property>
<property name="degree">
<column name="degree" sql-type="integer"
not-null="true"/>
</property>
</class>
</hibernate-mapping>
code
----------------
public void insertWord(WordView view){
Word word = new Word();
word.setWord(view.getWord());
word.setGloss(view.getGloss());
word.setDetail(view.getDetail());
log.debug("insert word: "+word);
try{
Session session = HibernateUtil.currentSession();
Transaction tx = session.beginTransaction();
session.save(word);
tx.commit();
HibernateUtil.closeSession();
}catch(Exception ex){
log.error("in insertWord(): "+ex);
}
}
|