Hibernate XML 配置中的 hbm2ddl.auto

SSH系列教材 (四)- hbm2ddl.auto=update 不起作用 在applicationContext.xml的sessionFactory中配置了有。就表示是自动更新表结构,不需要手段创建的变更。但是有的时候,会失效,不能够自动生成表结构。 阅读详情

在本教程中,我们将了解什么是hibernate 中的hbm2ddl.auto配置。

Hibernate hbm2ddl.auto:

hbm2ddl.auto 是一个休眠配置属性。它用于在创建 SessionFactory 时验证模式 DDL 并将其导出到数据库。

如果我们想使用它,我们应该将适当的值传递给hibernate.cfg。xml 如下所示。

hibernate.cfg.xml

<hibernate-configuration>
<session-factory>

<property name="hbm2ddl.auto">value</property>

</session-factory>
</hibernate-configuration>

通过定义 hbm2ddl.auto 属性,我们可以从 hibernate 框架执行 DDL(数据定义语言)命令,同时创建 SessionFactory 本身。

Hibernate的hbm2ddl.auto属性创建或验证数据库表。

hbm2ddl.auto 的可能值:

  • create
  • validate
  • update
  • create-drop

句法 :

hibernate.cfg.xml

<?xml version="1.0" encoding="UTF-8"?>
<hibernate-configuration>
   <session-factory>
      <property name="hbm2ddl.auto">validate/create/update/create-drop</property>
      Or
      <property name="hbm2ddl.auto" value="validate/create/update/create-drop" />
   </session-factory>
</hibernate-configuration>

hbm2ddl.auto create:

如果值为create,则Hibernate首先删除现有表的数据和结构,然后创建新表并在新创建的表上执行操作。

<property name="hbm2ddl.auto">create</property>

值“ create ”的唯一问题是,我们丢失了现有的表数据。

hbm2ddl.auto validate :

如果该值是validate 则 hibernate 只验证表结构——表和列是否存在。如果该表不存在,则Hibernate 将引发异常。

验证是 hbm2ddl.auto 的默认值。

<property name="hbm2ddl.auto">validate</property>

hbm2ddl.auto update :

如果值是update ,那么 Hibernate 会检查表和列。如果表不存在,则它会创建新表,并且如果列不存在,它会为其创建新列。

<property name="hbm2ddl.auto">update</property>

但是在值“更新”的情况下,hibernate 不会删除任何现有的表,因此我们不会丢失现有的表数据,可以用于生产环境。

hbm2ddl.auto create-drop:

如果该值为create-drop那么 Hibernate 首先检查表并执行必要的操作,最后在所有操作完成后删除表。

<property name="hbm2ddl.auto">create-drop</property>

值“ create-drop ”用于对Hibernate 代码进行单元测试。

hibernate.hbm2ddl.auto属性详解 详解hibernate.hbm2ddl.atuo 属性的配置 立即下载

相关推荐

详解hibernate自动创建表的配置

详解hibernate自动创建表的配置 配置自动创建表: update//首次创建项目时用,项目稳定后一般注释这里有4个值: update:表示自动根据model对象来更新表结构,启动hibernate时会自动检查数据库,如果缺少表,则自动建表;如果表里缺少列,则自动添加列。 还有其他的参数: create:启动hibernate时,自动删除原来的表,新建所有的表,所以每次启动后的以前数据都会丢失。 create-drop:启动hibernate时,自动创建表,程序关闭时,自动把相应的表都删除。所以程序

hibernate.hbm2ddl.auto配置

 hibernate.cfg.xml 中hibernate.hbm2ddl.auto配置节点如下:      Hibernate Reference Documentation 3.3.1解释如下:Automatically validate or export schema DDL to the database when the SessionFactory is created.Wi

liudeh_009的专栏 880

Matlab 2023b 科研党必备:MOSEK 10.1.25 安装与配置全记录(附License过期解决方案)

本文详细介绍了在Matlab 2023b中安装与配置MOSEK 10.1.25的全过程,特别针对科研用户提供学术许可申请、证书文件部署及环境集成的实用指南。文章还包含常见问题解决方案和性能调优建议,帮助用户高效完成优化计算任务。

weixin_30598225的博客 171

[Hibernate] Hibernate配制项之hibernate.hbm2ddl.auto

Hibernate配制项之hibernate.hbm2ddl.auto 前言 我们在本地作开发时,经常会定义好实体,继而在相应的数据库中建表。而这样建表继烦琐,浪费时间,又容易出错。而Hibernate的hibernate.hbm2ddl.auto会帮助我们根据定义好的实体,自动创建,更新,验证数据库表。hibernate.hbm2ddl.auto有好几个选项,接下来我们依次介绍。 hibe...

weixin_36210698的博客 3899

【AI概念】迁移学习 vs. 域自适应 vs. 域泛化|定义、核心原理、数学表达、易混淆点与工程选择建议|实际案例、工程实现细节、未来研究趋势、实际应用场景

大家好,我是爱酱。本篇将会详细梳理迁移学习(Transfer Learning)、域自适应(Domain Adaptation)、域泛化(Domain Generalization)三大常被混淆的核心概念,结合数学公式、典型算法与实际应用场景,帮助你厘清它们的本质区别、联系与工程意义。 注:本文章含大量数学算式、详细例子说明及大量代码演示,大量干货,建议先收藏再慢慢观看理解。新频道发展不易,你们的每个赞、收藏跟转发都是我继续分享的动力!

AI人工智能爱酱~你的AI学习好帮手~ 2467

Centos7安装NVIDIA驱动并在docker容器中使用GPU

Centos7安装NVIDIA驱动并在docker容器中使用GPU

运维giao的博客 2084

Hibernate入门第三讲——Hibernate的常见配置

在《Hibernate快速入门》一文中,我有讲到Hibernate的两个配置文件,今天就来详细地介绍这两个配置文件。Hibernate的配置详解在Hibernate中,我们使用时主要有两种配置文件: 核心配置文件——hibernate.cfg.xml(主要描述Hibernate的相关配置) 映射配置文件——xxx.hbm.xml 核心配置文件Hibernate的核心配置文件,即hibernate.c

李阿昀的博客 1万+

python 识别滑块验证码

博客来源于: https://www.cnblogs.com/wyh0923/p/16528354.html # -*- coding: utf-8 -*- # https://gov.pkulaw.cn/ 1. import io 2. import json 3. from pathlib import Path 4. from PIL import Image 5. import bas...

2102

hibernate.cfg.xml 中hibernate.hbm2ddl.auto配置详解

hibernate.cfg.xml 中hibernate.hbm2ddl.auto配置节点如下: Hibernate Reference Documentation 3.3.1解释如下: Automatically validate or export schema DDL to the database when the SessionFactory is created.

IT_COOKIE_SAM的博客 449

【异常】出现“‘git‘ 不是内部或外部命令,也不是可运行的程序”的错误

出现“‘git’ 不是内部或外部命令,也不是可运行的程序”的错误通常意味着 Git 没有被正确安装在你的系统上,或者其可执行文件的路径没有被添加到系统的环境变量中。

奶爸的编程之路,也就一周冷个三天 1389

【AI大模型应用开发】【RAG评估】0. 综述:一文了解RAG评估方法、工具与指标

本文主要总结了当前比较流行的RAG评估方法和指标。当前AI技术的快速发展,RAG和RAG评估是当前比较有前景的发展方向,不断有新的评估工具和理论被提出,让我们持续跟进,了解这些工具和理论,从而在使用时知道如何选择。

同学小张的博客 6826

hibernate.cfg.xml 中hibernate.hbm2ddl.auto配置节点

[size=small]hibernate.cfg.xml 中hibernate.hbm2ddl.auto配置节点如下: 在JBPM4中就有这么一个参数配置,JBPM需要创建自己的一些基础表,所以不管你用哪个数据库,运行jbpm的实例后,Hibernate都会根据这个参数配置和pojo类取自动创建对应的表结构。 其实这个hibernate.hbm2ddl.auto参数的作...

wang_159369的专栏 211

Kimi Code国产AI编程助手安装使用详细教程

Kimi Code 开发者智能编程服务简介:Kimi Code 是专为开发者提供的 AI 编程辅助工具,基于旗舰模型 Kimi K3(2.8万亿参数,支持100万token上下文)。提供 CLI、VS Code 插件等形式,支持代码阅读、编辑等功能。用户可通过API Key接入第三方工具。安装简单(Windows/Mac/Linux一键脚本),需在官网生成API密钥并登录使用。注意账户需充值余额方可正常调用服务。

猿小白的博客 2058

hibernate.cfg.xml:hbm2ddl.auto配置

hibernate.cfg.xml 中hibernate.hbm2ddl.auto配置节点如下: &lt;properties&gt; &lt;property name="hibernate.show_sql" value="true" /&gt; &lt;property name="hibernate.hbm2ddl.auto" value="create" /&

我的Java生活 239

【光子 AI 】LangGraph:Graph = 有向有环图 + 状态机实现原理详解:数据结构模型与核心算法代码实现逻辑解析

LangGraph核心原理解析:基于Pregel模型的消息传递图,结合有向有环图和状态机特性。关键实现包括:1) 共享状态机制(TypedDict/Pydantic模型)配合Reducer逻辑实现状态更新;2) 图拓扑结构通过邻接表维护节点和条件边;3) 检查点机制支持状态持久化和恢复。运行时采用Pregel循环算法,通过超级步迭代执行节点函数、应用状态归约、条件路由下一批节点,同时支持人工中断和异步并行处理。该架构使LangGraph具备循环执行、条件跳转等DAG无法实现的动态流程控制能力。

AI天才研究院 1035

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

hibernate.cfg.xml 中hbm2ddl.auto属性配置说明

简单说一下hibernate中hbm2ddl.auto参数的配置。先放一张图来了解,hibernate的工作流程。 hibernate工作流程主要为以下步骤。 1、Configuration接口:负责配置并启动Hibernate 2、SessionFactory接口:负责初始化Hibernate 3、Session接口:负责持久化对象的CRUD操作 4、Transaction接口

qq_37300675的博客 471

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

hibernate.hbm2ddl.auto参数说明

hibernate.cfg.xml 中hibernate.hbm2ddl.auto配置节点如下: properties>            property name="hibernate.show_sql" value="true" />                  property name="hibernate.hbm2ddl.auto" value="create"

hongweigg的专栏 6008

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

hibernate.hbm2ddl.auto=validate

hibernate.hbm2ddl.auto=validate   validate验证是.hbm.xml里面列在数据库的对应的表里是否存在如果数据库该表里面没有此列则报错, 而数据库里表中有的列在对应的hbm里没有声明的列hibernate不会报错

1190

hibernate配置文件的hibernate.hbm2ddl.auto

今天写了一段代码,通过hibernate首先将数据保存到数据库中,然后再查询出数据。可是,总是查询不到预期的结果,结果却是一个报错,因为用了多对一和一对多关联映射,开始还以为是关系弄错了,检查了半天代码,仍没有结果。最后,才发现竟然栽在一行短短的配置上面了。       它就是hibernate.cfg.xml配置文件中的hibernat.hbm2ddl.auto标签。       先介绍一个

4429

Hibernate.cfg.xml配置文件中的hbm2ddl.auto属性

该属性用于设置创建SessionFactory时,指定根据持久化类的映射关系操作数据库表。该属性值可以为:validate、update、create和create-drop四个值 create: 每次创建SessionFactory时都会重新创建映射的所有数据表 update:每次创建SessionFactory时会检查下对应的数据库里是否已存在与持久化类对应的表,如果没有就creat

qq_27905183的博客 536

hibernate学习的那些事之核心配置文件--hibernate.cfg.xml

hibernate.cfg.xml

奇里蓝天 872

Hibernate的映射约束以及hibernate.cfg.xml配置

1.核心配置约束 要求 位置:放到src下 名称:必须是hibernate.cfg.xml 配置三部分 配置数据库信息(必须的) 配置hibernate的相关信息(不是必须的) 配置引入的映射文件(如果有映射文件必须配置) <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-configuration PU...

AXibaaa的博客 647

用hibernate的xml配置来建索引

现在我都是用这种ORM框架来建数据表了,根本不用手动建,爽到。 今天我来给工作上的项目的一个字段加个索引,就用hibernate来加,还有点难加上。 主要看了2个stackOverFlow: https://stackoverflow.com/questions/858336/how-to-use-hibernate-annotations-to-add-an-index-on-a-lob-

逗题博客 2127

关于Hibernate一个配置参数hibernate.hbm2ddl.auto

hibernate.cfg.xml 中hibernate.hbm2ddl.auto配置节点如下:                               Hibernate Reference Documentation 3.3.1解释如下: Automatically validate or export schema DDL to the database when

漂泊小柒的专栏 1278

hibernate.hbm2ddl.auto节点配置

hibernate.cfg.xml 中hibernate.hbm2ddl.auto配置节点如下:       Hibernate Reference Documentation 3.3.1解释如下: Automatically validate or expor

1530

eclipse学习(第三章:ssh中的Hibernate)——2.Hibernate的一些配置(hibernate.cfg.xml里面的属性)

eclipse学习(第三章:ssh中的Hibernate)——2.Hibernate怎么用前言Hibernate相关jar包的下载位置查看Hibernate 相关属性小提示 前言 本文参考自https://www.w3cschool.cn/hibernate/b79t1iea.html做的一个学习记录。 Hibernate相关jar包的下载位置 hibernate4及以上的jar包http://hibernate.org/orm/releases/ hibernate3的相关jar包下载地址 https:/

weixin_43987277的博客 233
上一篇: Servlet JSP Hibernate MySQL CRUD示例
下一篇: Hibernate 5 示例
allway2
博客等级 码龄16年 6715粉丝 7974原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值