我正在尝试将新记录插入到我的mysql数据库中; Hibernate insert语句打印在日志中,但数据库不插入新记录。没有发布错误,但我的rpcService调用打印了我的onFailure消息。另外:我的应用程序从数据库中读取就好了,所以我的应用程序的其他部分运行良好。下面是代码和配置:
hibernate.cfg.xml中:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.password">xxxxxxxx</property>
<property name="hibernate.connection.url">jdbc:mysql://xxxxxxxxx.us-west-1.rds.amazonaws.com/xxxxxxx</property>
<property name="hibernate.connection.username">xxxxxx</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<!-- configuration pool via c3p0-->
<property name="c3p0.acquire_increment">1</property>
<property name="c3p0.idle_test_period">100</property> <!-- seconds -->
<property name="c3p0.max_size">20</property>
<property name="c3p0.max_statements">20</property>
<property name="c3p0.min_size">5</property>
<property name="c3p0.timeout">1800</property> <!-- seconds -->
<property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
<property name="current_session_context_class">thread</property>
<property name="hibernate.show_sql">true</property>
<!-- <property name="hbm2ddl.auto">update</property>-->
<mapping class="com.local.shared.School"/>
<mapping class="com.local.shared.SchoolVideo"/>
<mapping class="com.local.shared.Category"/>
<mapping class="com.local.shared.Administrator"/>
</session-factory>
</hibernate-configuration>
rpcService call:
@Override
public void doUpdateSchoolVideo(SchoolVideo schoolVideo) {
rpcService.updateSchoolVideo(schoolVideo,
new AsyncCallback<SchoolVideo>() {
public void onFailure(Throwable caught) {
caught.printStackTrace();
new Exception().printStackTrace();
Window.alert("Couldn't update schoolVideo info!");
}
public void onSuccess(SchoolVideo schoolVideo) {
System.out.println("SchoolVideo table updated!");
loadSubmittedVideos(Utilities.getSchoolPage()
.getSchool_name());
}
});
}
rpcService实施:
@Override
public SchoolVideo updateSchoolVideo(SchoolVideo schoolVideo) {
System.out.println("Attempting to save the schoolVideo information"
+ "\n");
Transaction tx = null;
Session session = SessionFactoryUtil.getInstance().getCurrentSession();
HttpServletRequest httpServletRequest = this.getThreadLocalRequest();
HttpSession httpSession = httpServletRequest.getSession(false);
School sessionSchool = (School) httpSession.getAttribute("school");
System.out.println("\n updateSchoolVideo school in session is " +
" = " + sessionSchool.getSchool_name() + "\n");
try {
tx = session.beginTransaction();
School school = sessionSchool;
System.out.println("\n cachedSchool = " + school + "\n");
School querySchool = (School) session.get(School.class,
new Integer(school.getId()));
System.out.println(querySchool.getId() + " equals id");
schoolVideo.setSchool_id(querySchool);
schoolVideo.setReviewed(1);
System.out.println(schoolVideo.getVideo_name() + " videoname");
session.save(schoolVideo);
System.out.println("\n Video Should have been saved in database after upload \n");
tx.commit();
} catch (RuntimeException e) {
if (tx != null && tx.isActive()) {
try {
tx.rollback();
} catch (HibernateException e1) {
e1.printStackTrace();
}
throw e;
}
}
return schoolVideo;
}
我的loggin语句显示了Hibernate插入: Hibernate:插入SchoolVideo(category,image_name,review,school_id,video_name)值(?,?,?,?,?)
因此,我的rpcServiceImpl方法一直执行session.save()方法调用。直接在它之后的print语句不打印,所以我知道一切都死了。任何人都知道如何我现在可以跟踪这个db插入的缺乏。