database returned no natively generated 分类:Hibernatehbm.xml中的配置如下:

<id name="logId" type="integer" column="LOGID">
   <generator class="native"/>
</id>

native的功能是:

由数据库从identity,sequence和hilo中选取一个生成器来生成ID。

这样就需要主键设置成自增长的,一定要小心

采用的是Mysql5数据库,但在执行插入的时候报错:

The database returned no natively generated identity value

最后确认原因是数据库的表结构中关于logid,没有设置auto increment。

正确的建库如下:

CREATE TABLE `log` (                        
          `LOGID` int(11) NOT NULL auto_increment,  
          `LOGUSER` varchar(10) default NULL,       
          `LOGTIME` datetime default NULL,          
          `LOGTYPE` char(1) default NULL,           
          PRIMARY KEY  (`LOGID`)                    
        ) ENGINE=InnoDB DEFAULT CHARSET=gbk

完整的hbm.xml如下:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC 
 "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
 "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping 
 package="com.shinyv.dao.hibernate.test">

<class name="Log" table="log" proxy="Log" dynamic-insert="true" dynamic-update="true">
  <id name="logId" type="integer" column="LOGID">
   <generator class="native"/>
  </id>
  <property name="logTime" column="LOGTIME" not-null="true"/>
  <property name="userName" type="string" column="LOGUSER"/>
  <property name="logType" column="LOGTYPE"/>
 </class>
 
</hibernate-mapping>

Database returned no natively generated的更多相关文章

  1. Execption:the database returned no natively generated identity value

    org.hibernate.HibernateException: The database returned no natively generated identity value at org. ...

  2. The database returned no natively generated identity value错误解决方案

    原因:hibernate项目中在学生表的配置文件中: <id name="studentno" column="studentno"> <ge ...

  3. The databse returned no natively generated identity value问题

    com.cqupt.dayday.model 代码 package com.cqupt.dayday.model; import java.util.Date; /** * Created by I ...

  4. Django(博客系统):按照时间分层筛选“/blog/article/?create_time__year=2017”,出现问题:Database returned an invalid datetime value. Are time zone definitions for your database installed?

    问题背景 添加文章时间没问题,但为了设定博客文章按照时间分层筛选(创建时间的年份.年月&月份来搜索文章),我在blog这个django app的admin.py的ArticleAdmin类中做 ...

  5. 解决Database returned an invalid datetime value. Are time zone definitions for your database installed?

    设定博客文章按照时间分层筛选出现问题 ret=Article.objects.filter(user=user).annotate(month=TruncMonth("create_time ...

  6. Database returned an invalid value in QuerySet.datetimes(). Are time zone definitions for your datab

    Database returned an invalid value in QuerySet.datetimes(). Are time zone definitions for your datab ...

  7. 报错Database returned an invalid value in QuerySet.datetimes(). Are time zone definitions for your database and pytz installed?解决

    在django中的setting.py中: LANGUAGE_CODE = 'en-us' TIME_ZONE = 'Asia/Shanghai' #'UTC' USE_I18N = True USE ...

  8. Database returned an invalid datetime value. Are time zone definitions for your database installed?

    在做文章归档的会后,打印结果时报了这个错误 ret = models.Article.objects.filter(user=user).annotate(month=TruncMonth('crea ...

  9. 06:Database returned an invalid datetime value. Are time zone definitions for your database installed?

    出现时区问题 解决方案: 修改settings.py的时区变量. 修改前: LANGUAGE_CODE = 'en-us' TIME_ZONE = 'UTC' USE_I18N =True USE_L ...

随机推荐

  1. The user specified as a definer ('root'@'%') does not exist 解决方法

    mysql> grant all privileges on *.* to root@"%" identified by "."; Query OK, r ...

  2. Digital design之Boolean Algebra

    1. 0 and 1 (duality: 0 -- 1, · -- +) X + 0 = X, X · 1 = X X + 1 = 1, X · 0 = 0 2. Idempotent X + X = ...

  3. dutacm.club_1087_Common Substrings_(KMP)_(结合此题通俗理解kmp的next数组)

    1087: Common Substrings Time Limit:3000/1000 MS (Java/Others)   Memory Limit:163840/131072 KB (Java/ ...

  4. swift protocol 与类继承结合时的bug

    protocol CommonTrait: class { func commonBehavior() -> String } extension CommonTrait { func comm ...

  5. AdMob设计工具google web designer

    一.google web designer工具中文文档: https://support.google.com/webdesigner?hl=zh-Hans#topic=3227692 我用的版本:应 ...

  6. Vue指令1:v-text及v-html

    v-text: //插入一段文本<div id="app"> <p v-text="message"></p></di ...

  7. CAD执行一个带参数的命令(com接口VB语言)

    主要用到函数说明: MxDrawXCustomFunction::Mx_SendStringToExecute 执行一个带参数的命令.详细说明如下: 参数 说明 CString sCmaName 命令 ...

  8. break和continue在多重循环中使用

    break和continue在多重循环中使用 关于break和continue在java中,break的作用是跳出循环,continue的作用是跳出本次循环. 我们一般情况下,这样使用: public ...

  9. python之cookbook-day02

    第一章:数据结构和算法 1.2 解压可迭代对象赋值给多个变量 问题: 如果一个可迭代对象的元素个数超过变量个数时,会抛出一个 ValueError .那么 怎样才能从这个可迭代对象中解压出 N 个元素 ...

  10. IDLE in Python (Ubuntu)

    To lauch IDLE in the Current Woking Directory >>> usr/bin/idle3 Alt + n  # next command Alt ...