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. npm——nrm

    nrm 是镜像地址,方便国内下载 npm i nrm -g nrm ls nrm use taobao // 切换地址

  2. GAN生成图像论文总结

    GAN Theory Modifyingthe Optimization of GAN 题目 内容 GAN   DCGAN   WGAN   Least-square GAN   Loss Sensi ...

  3. Call stack-函数调用栈

    https://en.wikipedia.org/wiki/Call_stack#STACK-FRAME In computer science, a call stack is a stack da ...

  4. 【转载】eclipse设置护眼色详细教程

    先上一张效果图:     下面开始设置: 首先设置代码区的背景色: Window–>preference-->General-->Editors-->Test Editors ...

  5. javaHashcode与equals

    转载自:http://blog.csdn.net/jiangwei0910410003/article/details/22739953 Java中的equals方法和hashCode方法是Objec ...

  6. mysql5.7报Access denied for xxx@localhost 的解决

    使用root用户登录mysql数据库若如下报错 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using passwor ...

  7. Linux 应用总结:自动删除n天前的日志

    linux是一个很能自动产生文件的系统,日志.邮件.备份等.虽然现在硬盘廉价,我们可以有很多硬盘空间供这些文件浪费,让系统定时清理一些不需要的文件很有一种爽快的事情.不用你去每天惦记着是否需要清理日志 ...

  8. 59.关系型与document类型数据模型对比

    现假设有如下两个类: class Department(object): def __init__(self, dept_id, name, desc, employees=[]): self.dep ...

  9. win10 ubuntu 子系统安装php

    apt-get install python-software-propertiesadd-apt-repository ppa:ondrej/phpapt-get updateapt-get ins ...

  10. kvm virsh命令详解

    [root@ok home]# virsh list Id Name State ---------------------------------------------------- 1 13sv ...