【发布时间】:2011-03-30 20:39:55
【问题描述】:
我收到以下错误session.save(student);
org.hibernate.HibernateException: The database returned no natively generated identity value
这里是主要功能
{
BasicConfigurator.configure();
Session session = HibernateUtil.getSessionFactory().openSession();
Transaction transaction = null;
try {
transaction = session.beginTransaction();
Address address = new Address("Outer Ring Road", "Delhi", "TN", "110001");
Student student = new Student("kumar", address);
session.save(student);
transaction.commit();
} catch (HibernateException e) {
if (transaction != null) {
transaction.rollback();
}
e.printStackTrace();
} finally {
session.close();
}
}
【问题讨论】:
-
你的SGBD叫什么名字?
-
我正在使用 MySQL Workbench 5.2 CE 数据库。驱动类是
com.mysql.jdbc.Driver -
你能发布你用来映射学生和地址类的映射吗?这有助于调试您的问题。
-
在询问 Hibernate 问题时:告诉我们您使用什么 DB/Dialect,发布您的映射、表格、确切的堆栈跟踪。