hilo

hibernate快速入门示例

二次信任 提交于 2020-08-10 04:05:14
hibernate概述 hibernate是一个java的全自动ORM框架,它可以自动生成SQL语句、自动建表、自动执行,使用者可以不使用SQL完成数据的CRUD操作,同时它也是基于JPA规则的一种实现方式 建库建表 在mysql数据库中创建测试库和表 -- 建库 CREATE DATABASE `hibernate-test`; -- 建表 CREATE TABLE `hibernate-test`.`h_user` ( `id` int(11) NOT NULL AUTO_INCREMENT, `username` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `password` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, PRIMARY KEY (`id`) USING BTREE ) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic; -- 插入数据 INSERT INTO h_user ( username,

Hibernate --主键生成策略

别等时光非礼了梦想. 提交于 2020-08-05 04:03:21
<id name="cust_id" column="cust_id"> <generator class ="native"></generator> </id> increment:代理主键,适合于所有数据库,由hibernate维护主键自增,和底层数据库无关,但是不适合于2个或以上hibernate进程。 identity:代理主键,适合于 Mysql 或ms sql server等支持自增的dbms,主键值不由hibernate维护。 sequence:代理主键,适合于 oracle 等支持序列的dbms,主键值不由hibernate维护,由序列产生。 native :代理主键,根据底层数据库的具体特性选择适合的主键生成策略, 如果是mysql或sqlserver,选择identity,如果是oracle,选择sequence 。 hilo:代理主键,hibernate把特定表的字段作为hign值,生成主键值 uuid.hex:代理主键,hibernate采用uuid 128位算法生成基于字符串的主键值 assign:适合于应用程序维护的自然主键。 来源: oschina 链接: https://my.oschina.net/u/4254945/blog/4290279

Hibernate 的主键生成策略

喜欢而已 提交于 2020-03-25 11:30:11
3 月,跳不动了?>>> 原文链接: http://www.yiidian.com/hibernate/hibernate-generator.html Hibernate提供的主键生成策略,使我们可以在实体类的映射xml文件中设定关键字来告诉hibernate我们要使用的主键生成方式,然后hibernate会根据设定完成数据库的主键控制。 1 生成策略配置格式 用户User的实体类User.java package com.yiidian.domain; import java.util.Date; public class User { private String id; private String name; public User(){} public String getId() { return id; } public void setId(String id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } } User.java对应的映射文件User.hbm.xml <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-

The Hibernate hilo strategy does not generate the values according to the next database sequence value

自作多情 提交于 2020-02-25 05:55:35
问题 I have a jpa configuration like this: @Id //@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seq_gen") @GeneratedValue(generator = "timedep_seq_gen") @GenericGenerator( name = "seq_gen", strategy = "org.hibernate.id.enhanced.SequenceStyleGenerator", parameters = { @Parameter(name = "sequence_name", value = "sequence_myseq"), @Parameter(name = "initial_value", value = "1"), @Parameter(name = "increment_size", value = "10"), @Parameter(name = "optimizer", value ="hilo") } ) private

The Hibernate hilo strategy does not generate the values according to the next database sequence value

限于喜欢 提交于 2020-02-25 05:55:06
问题 I have a jpa configuration like this: @Id //@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seq_gen") @GeneratedValue(generator = "timedep_seq_gen") @GenericGenerator( name = "seq_gen", strategy = "org.hibernate.id.enhanced.SequenceStyleGenerator", parameters = { @Parameter(name = "sequence_name", value = "sequence_myseq"), @Parameter(name = "initial_value", value = "1"), @Parameter(name = "increment_size", value = "10"), @Parameter(name = "optimizer", value ="hilo") } ) private

What are all the NHibernate HiLo generator params?

谁说胖子不能爱 提交于 2020-01-22 19:04:22
问题 I've seen some docs by Fabio Maulo that shows the following params: <id name="Id" type="Int64" column="cat_id"> <generator class="hilo"> <param name="table">hi_value</param> <param name="column">next_value</param> <param name="max_lo">100</param> </generator> </id> However, on this question the poster uses a <param name="schema">... I'd like to be able to specify schema for the HiLo generator. Is there definitive documentation for all generator parameters? I've tried googling it without

Error with hilo in NHibernate - “could not read a hi value - you need to populate the table”

倾然丶 夕夏残阳落幕 提交于 2019-12-20 19:56:12
问题 I've genereated a schema for my (SQL 2005) db using SchemaExport, and it's created a table CREATE TABLE [dbo].[hibernate_unique_key]( [next_hi] [int] NULL ) ON [PRIMARY] When I try to add an entity, I get the error "could not read a hi value - you need to populate the table". What am I meant to do? edit: I've inserted a 1 into the table, and it seems to work. Is this the correct value to have in there? 回答1: NHibernate expects to find a value that stores the current hi value in that table, ie

NHibernate, HiLo and many-to-many association

僤鯓⒐⒋嵵緔 提交于 2019-12-11 12:36:00
问题 I have two entities, Role and Permission , each with its table in the database and properly set-up ID generation with a HiLo algorithm. This works fine. However, there is one more table in the database, ROLE_PERMISSION_ASSIGNMENT , simply containing foreign keys to the two forementioned tables, binding the entities together. This table does not have a entity counterpart in my application. The mapping for the Role entity looks like this: public class RoleMap : ClassMap<Role> { public RoleMap()

NHibernate HiLo generation and SQL 2005/8 Schemas

寵の児 提交于 2019-12-08 00:02:06
问题 I have an issue on my hands that I've spent several days searching for an answer to no avail... We're using HiLo Id generation, and everything seems to be working fine, as long as the entity table is in the same schema as the hibernate_unique_key table. The table structure is pretty simple. I have my hi value table in the db as dbo.hibernate_unique_key. Several entity table are also in the dbo schema, and they work without issue. Then we have tables under the "Contact" schema (such as Contact

NHibernate Hi/Lo - gaps in ids

天涯浪子 提交于 2019-12-07 22:34:34
问题 Scenario: Hi/Lo is initialized for MyEntity with Lo 100 The table is empty. Two sessions with different connections have both inserted three items. TableIds 1 2 3 100 101 102 If a third one comes in at a later time and inserts three items: TableIds ... 200 201 202 Is there a way to not get these gaps? 回答1: The Lo value is stored against the SessionFactory, not the Session. You only ever get gaps when you restart your application and create a new instance of the SessionFactory. A new Hi value