日期:2014-05-17  浏览次数:20723 次

Hibernate 映射文件的问题
映射文件如下:
<hibernate-mapping>

<class name="com.qzj.model.Person" table="User">
<id name="id" column="ID" type="integer">
<generator class="native"></generator>
</id>
<property name="username" column="username" type="string"></property>
<property name="password" column="password" type="string"></property>
<property name="age" column="age" type="integer"></property>
<property name="register" column="register" type="date"></property>
</class>
</hibernate-mapping>

运行的时候正常,打印出的Hibernate语句如下:

Hibernate: insert into User (username, password, age, register) values (?, ?, ?, ?)

但是数据库表中并没有数据,

我故意把映射代码中的表名改错,例如,把 User 改为 Userddd ,竟然还是运行成功,Hibernate语句如下

Hibernate: insert into Userddd (username, password, age, register) values (?, ?, ?, ?)

数据库中也还是没有数据,

求解!!!!!

------解决方案--------------------
catch(Exception ex){
if(null != tx)
{
tx.rollback();
}
}
你这么写代码连是否发生了异常都不知道。就不能不catch?
或者:
catch(Exception ex){
if(null != tx)
{
tx.rollback();
}
throw new RuntimeException(e);
}
最起码你也得打印个输出吧:

catch(Exception ex){
if(null != tx)
{
tx.rollback();
}
System.out.println(e.getMessage());
}