I meet a strange problem with spring and hibernate.
I am developing a forum. With a thread there are many thread bodies. Any thread body has a foreign key to a thread.
When I call getHibernateTemplate().save(thread) method, there is no any exceptions and the SQL is shown normally. Then I checked the thread object and found that the ID is set with a uuid. In the same session I saved a thread body with that thread and there is no exception too. BUT there is nothing saved into database.
I use OpenSessionInView and org.springframework.transaction.interceptor.TransactionProxyFactoryBean to provide a writable session.
There is no problem with any other table, and this problem happens sometime. About a half of threads can't be written into database, and the others is correct.
Thank you very much!
Hibernate version:
3.0.5
Mapping documents:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.lintun.bbs.domain.Thread" table="thread">
<id column="id" name="id" length="32" type="java.lang.String">
<generator class="uuid.hex"/>
</id>
<property column="topic" length="100" name="topic" not-null="true" type="java.lang.String"/>
<many-to-one column="poster" name="poster" class="com.lintun.bbs.domain.User"/>
<property column="start_time" name="startTime" not-null="true" type="java.util.Calendar"/>
<property column="post_time" name="postTime" not-null="true" type="java.util.Calendar"/>
<many-to-one column="last_replier" name="lastReplier" class="com.lintun.bbs.domain.User"/>
<property column="is_prime" name="isPrime" not-null="true" type="java.lang.Boolean"/>
<property column="is_top" name="isTop" not-null="true" type="java.lang.Boolean"/>
<property column="reply_count" name="replyCount" not-null="true" type="java.lang.Integer"/>
<property column="click_count" name="clickCount" not-null="true" type="java.lang.Integer"/>
<property column="reply_count_today" name="replyCountToday" not-null="true" type="java.lang.Integer"/>
<property column="click_count_today" name="clickCountToday" not-null="true" type="java.lang.Integer"/>
<many-to-one column="board" name="board" class="com.lintun.bbs.domain.Board"/>
<many-to-one column="section" name="section" class="com.lintun.bbs.domain.Section"/>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
getHibernateTemplate().save(thread);
Full stack trace of any exception that occurs:
No any exception
Name and version of the database you are using:
Postgresql 8.1.1
The generated SQL (show_sql=true):
Hibernate: insert into thread (topic, poster, start_time, post_time, last_replier, is_prime, is_top, reply_count, click_count, reply_count_today, click_count_today, board, section, id) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
Debug level Hibernate log excerpt:
N/A
|