org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update

tomorrow619810 2010-07-15 10:11:23
Books.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">
<!--
Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
<class name="root.Books" table="books" dynamic-insert="false" dynamic-update="false" node="TB_BANAB">
<id name="bookId" type="java.lang.Integer" node="@bookId">
<column name="bookId" />
</id>
<property name="bookName" type="java.lang.String" node="@book_name">
<column name="book_name" length="200" />
</property>
<property name="bookAuthor" type="java.lang.String" node="@bookAuthor">
<column name="bookAuthor" length="100" />
</property>
<property name="bookPublish" type="java.lang.String" node="@book_publish">
<column name="book_publish" length="100" />
</property>
<property name="bookDate" type="java.util.Date" node="@book_date">
<column name="book_date" length="0" />
</property>
<property name="bookIsbn" type="java.lang.String" node="@book_isbn">
<column name="book_isbn" length="20" />
</property>
<property name="bookPage" type="java.lang.Integer" node="@book_page">
<column name="book_page" />
</property>
<property name="bookPrice" type="java.lang.Double" node="@book_price">
<column name="book_price" precision="10" />
</property>
<property name="bookContent" type="java.lang.String" node="@book_content">
<column name="book_content" length="100" />
</property>
</class>
</hibernate-mapping>

java 代码内容:
public class Test {

public static void main(String[] args) {

try {
SessionFactory sf = new Configuration().configure().buildSessionFactory();
Session session = sf.openSession();
Transaction tx = session.beginTransaction();
Books pd = new Books();
pd.setBookId(1);
pd.setBookName("教父");
pd.setBookAuthor("Godfather");
pd.setBookPublish("1");
pd.setBookIsbn("DVD");
session.save(pd);
tx.commit();
session.close();
System.out.println("dfsfsdfsdf");
} catch (HibernateException e) {
e.printStackTrace();
}
}
}

报错信息:
Hibernate: insert into books (book_name, bookAuthor, book_publish, book_date, book_isbn, book_page, book_price, book_content, bookId) values (?, ?, ?, ?, ?, ?, ?, ?, ?)
org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update
at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:70)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:181)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:226)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:136)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:730)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:324)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:86)
at root.Test.main(Test.java:25)
Caused by: java.sql.BatchUpdateException: Unknown column 'bookAuthor' in 'field list'
at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:1257)
at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:943)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:57)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:174)
... 8 more

搞了 2天了,还是不知道什么原因,请 大侠 支援下!
...全文
170 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
sasgsc 2010-07-16
  • 打赏
  • 举报
回复
你这算自行了断了啊....
tomorrow619810 2010-07-15
  • 打赏
  • 举报
回复
我自己找出来了,原因是:
<property name="bookAuthor" type="java.lang.String" node="@bookAuthor">
<column name="bookAuthor" length="100" />
</property>
数据库中的字段名是:book_Author,映射时出错了
改成:
<property name="bookAuthor" type="java.lang.String" node="@book_Author">
<column name="book_Author" length="100" />
</property>

58,454

社区成员

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

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