-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Help!! Duplicate entry error
PostPosted: Fri Apr 09, 2004 2:04 pm 
Newbie

Joined: Mon Apr 05, 2004 6:25 pm
Posts: 5
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);
}
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.