求myeclipse下的hibernate问题的答案!

dotnetguy 2006-04-12 01:49:06
1。Tproduct表为:
主键 Product_id varchar 50
Product_name varchar 50


2。Tproduct.hbm.xml如下:
<?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 package="com.hiber">

<class name="Tproduct" table="TProduct">
<id name="productId" column="Product_id" type="string">
<generator class="native"/>
</id>

<property name="productName" column="Product_name" type="string" />
</class>

</hibernate-mapping>

3。插入程序代码为 :

Transaction tran = null;
try {
Session session = HibernateSessionFactory.currentSession();
tran = session.beginTransaction();
Tproduct tp = new Tproduct();
tp.setProductId("eeeee");

tp.setProductName("fffff");
session.save(tp);
session.flush();


} catch (HibernateException e) {
e.printStackTrace();
Assert.fail(e.getMessage());
if (tran != null) {
try {
tran.rollback();
} catch (HibernateException e1) {
e1.printStackTrace();
}

}

}

4。报错内容如下:
org.hibernate.exception.ConstraintViolationException: could not insert: [com.hiber.Tproduct]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:63)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
。。。。。
Caused by: com.jnetdirect.jsql.JSQLException: 无法将 NULL 值插入列 'Product_id',表 'querytest.dbo.TProduct';该列不允许空值。INSERT 失败。
...全文
115 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
Fibona 2006-04-12
  • 打赏
  • 举报
回复
<generator class="native"/>
改成
<generator class="uuid_hex"/>试试看

58,454

社区成员

发帖
与我相关
我的任务
社区描述
Java Eclipse
社区管理员
  • Eclipse
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧