{"id":20474163,"url":"https://github.com/marschall/hibernate-batch-sequence-generator","last_synced_at":"2025-04-13T11:32:32.148Z","repository":{"id":42048936,"uuid":"94752359","full_name":"marschall/hibernate-batch-sequence-generator","owner":"marschall","description":"Special purpose implementation of a Hibernate sequence generator","archived":false,"fork":false,"pushed_at":"2024-06-21T15:54:46.000Z","size":165,"stargazers_count":7,"open_issues_count":1,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-27T02:43:13.583Z","etag":null,"topics":["batch-insert","database-access","database-sequence","hibernate","rdbms","sql"],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/marschall.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-06-19T08:08:55.000Z","updated_at":"2024-08-05T08:29:17.000Z","dependencies_parsed_at":"2024-01-26T14:30:05.975Z","dependency_job_id":"cf06c697-918b-40fb-8482-52057c3d5986","html_url":"https://github.com/marschall/hibernate-batch-sequence-generator","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marschall%2Fhibernate-batch-sequence-generator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marschall%2Fhibernate-batch-sequence-generator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marschall%2Fhibernate-batch-sequence-generator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marschall%2Fhibernate-batch-sequence-generator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/marschall","download_url":"https://codeload.github.com/marschall/hibernate-batch-sequence-generator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248705524,"owners_count":21148549,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["batch-insert","database-access","database-sequence","hibernate","rdbms","sql"],"created_at":"2024-11-15T14:28:26.402Z","updated_at":"2025-04-13T11:32:32.126Z","avatar_url":"https://github.com/marschall.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"Hibernate Batch Sequence Generator [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.marschall/hibernate-batch-sequence-generator/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.github.marschall/hibernate-batch-sequence-generator) [![Javadocs](https://www.javadoc.io/badge/com.github.marschall/hibernate-batch-sequence-generator.svg)](https://www.javadoc.io/doc/com.github.marschall/hibernate-batch-sequence-generator)  [![Build Status](https://travis-ci.org/marschall/hibernate-batch-sequence-generator.svg?branch=master)](https://travis-ci.org/marschall/hibernate-batch-sequence-generator)\n==================================\n\nA batch sequence generator for Hibernate that uses [recursive queries](https://en.wikipedia.org/wiki/Hierarchical_and_recursive_queries_in_SQL) to preallocate multiple values in a single database access.\n\nThe code is also present in [Hibernate Types](https://github.com/vladmihalcea/hibernate-types) starting with version 2.13.1.\n\n```xml\n\u003cdependency\u003e\n  \u003cgroupId\u003ecom.github.marschall\u003c/groupId\u003e\n  \u003cartifactId\u003ehibernate-batch-sequence-generator\u003c/artifactId\u003e\n  \u003cversion\u003e2.2.0\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\nVersions 2.2.x support Hibernate 6.5.\n\nVersions 2.1.x support Hibernate 6.4.\n\nVersions 2.0.x support Hibernate 6.x.\n\nVersions 1.x support Hibernate 5.6.\n\nThis sequence generator combines the advantages of several existing sequence generators and avoids their disadvantages:\n\n- [hi/lo](https://vladmihalcea.com/2014/06/23/the-hilo-algorithm/)\n  - all database access has to be aware of it\n  - there is no clear relationship between the current sequence value and the column value\n- `pooled` and `pooledlo`\n  - `INCREMENT BY` has to be set on the database sequence\n  - direct use of the sequence can cause a lot of identifier waste\n  - the pool size and the `INCREMENT BY` value need to match\n- `IDENTITY`\n  - does not support JDBC batch inserts\n- `TABLE`\n  - has bad write performance\n\nThe limitations of this sequence generator are:\n\n- limited database dialect support (see below)\n- if you're using hbm2ddl then the `CACHE` value on the sequence is not set\n\nUsage\n-----\n\nYou can use this sequence generator like this\n\n```java\n@Id\n@BatchSequence(name = \"SOME_SEQUENCE_NAME\", fetch_size = SOME_FETCH_SIZE_VALUE)\nprivate Long someColumnName;\n```\n\nYou need to configure the following things\n\n\u003cdl\u003e\n\u003cdt\u003eSOME_SEQUENCE_NAME\u003c/dt\u003e\n\u003cdd\u003ethe SQL name of the sequence from which the values should be fetched\u003c/dd\u003e\n\u003cdt\u003eSOME_FETCH_SIZE_VALUE\u003c/dt\u003e\n\u003cdd\u003einteger, how many values should be fetched at once, this should be equal to the \u003ccode\u003eCACHE\u003c/code\u003e value of the sequence, optional, default value is 10\u003c/dd\u003e\n\u003c/dl\u003e\n\n\nDatabase Support\n----------------\n\nThe following RDBMS have been verified to work\n\n- DB2\n- Firebird\n- H2\n- HSQLDB\n- MariaDB 10.3 with Hibernate 5.2.17 or later\n- Oracle\n- Postgres\n- SQL Sever\n- In theory any RDBMS that supports `WITH RECURSIVE` and sequences is supported.\n\nUnfortunately these RDBMS are currently not supported\n\n- MySQL due to the lack of sequence support\n\nDDL\n---\n\nFor the best possible performance the `CACHE` value of the database sequence should be set to the same value as the `\"fetch_size\"` parameter.\n\nHibernate Versions\n------------------\n\nThe project has been developed and tested against Hibernate 6.5.\n\nDependencies\n------------\n\nThe project has no dependencies other than Hibernate.\n\nFurther Reading\n---------------\n\n- https://vladmihalcea.com/hibernate-batch-sequence-generator/\n- https://vladmihalcea.com/how-to-batch-insert-and-update-statements-with-hibernate/\n- https://docs.jboss.org/hibernate/orm/5.0/manual/en-US/html/ch03.html#configuration-optional-properties\n- https://vladmihalcea.com/hibernate-identity-sequence-and-table-sequence-generator/\n- https://dzone.com/articles/how-batch-insert-and-update\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarschall%2Fhibernate-batch-sequence-generator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarschall%2Fhibernate-batch-sequence-generator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarschall%2Fhibernate-batch-sequence-generator/lists"}