Questions tagged [id-generation]

74 questions
105
votes
4 answers

How to choose the id generation strategy when using JPA and Hibernate

I was going through Id generation section of the Hibernate reference guide and "java persistence with Hibernate" There are quite a few options available with Hibernate and JPA combined. I was looking for a further documentation on how to choose the…
user1317764
22
votes
3 answers

Hibernate with Oracle sequence doesn't use it

I have configured hibernate to use oracle sequence. Sequence is created with cache=20, increment=1. All works fine, hibernate persisting entities. The id value is strange: 50,51....76,201,202...209,1008,1009,5129,5130 .... If I ask for sequence…
Vlada
  • 539
  • 2
  • 11
  • 25
11
votes
2 answers

native generator class in hibernate

I have this part of hibernate mapping xml file, and I was looking for a good example for what does native mean.
Rimchik
  • 135
  • 1
  • 2
  • 8
11
votes
1 answer

@GeneratedValue with strategy=GenerationType.AUTO generates repeated value after restart

I have a hibernate entity with an ID configured as @Id @GeneratedValue(strategy=GenerationType.AUTO) private Long id; The creation of new elements works ok in the first run. But if I restart my application and retrieve back the records, the next…
Thomas
  • 2,695
  • 5
  • 29
  • 50
10
votes
2 answers

How to insert a record with custom id use Spring data jdbc?

For Spring Data JPA, I can use annotation @GeneratedValue(strategy = GenerationType.AUTO) insert a record with custom id, but for Spring Data JDBC, how to insert a record with custom id? I had tried to insert with id, but no any exception threw, and…
harrell hao
  • 101
  • 1
  • 4
9
votes
3 answers

Hibernate ID Generator

Anyone know of some good tutorials on how to create a custom ID generator for hibernate?
mainstringargs
  • 11,482
  • 33
  • 101
  • 163
6
votes
3 answers

Sequence increment by 50 instead of 1

I created an Oracle sequence: Create sequence seq_acteurs start with 1 increment by 1; Normally the sequence must be incremented by 1, but when insert into Acteurs table, the sequence s incremented by 50! That doesn't seem logical. Why is this…
cascadox
  • 833
  • 4
  • 14
  • 30
6
votes
2 answers

org.hibernate.MappingException: The increment size of the sequence is set to [10] in the entity mapping while ... size is [1]

We run into a problem when updating to Spring Boot 2.2 and the associated Hibernate 5.4.x. We do have the following sequence generator @Id @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "hilo_sequence_generator") @GenericGenerator( …
Gerd Aschemann
  • 424
  • 4
  • 13
6
votes
2 answers

Why would you append a shard ID to a generated ID?

I'm reading this: https://instagram-engineering.com/sharding-ids-at-instagram-1cf5a71e5a5c In in the last section "Solution", where they are generating a globally unique ID based on the DB's autoincrement feature + milliseconds since epoch + shard…
user1008636
  • 2,109
  • 7
  • 21
  • 38
6
votes
2 answers

Hibernate, what is the most efficient id generation strategy?

I need to insert many entities into the database via Hibernate. So, I want to find the most effective algorithm for Id generation. Accordingly Hibernate Documentation exists four widely used generation strategies: IDENTITY SEQUENCE TABLE AUTO I…
Taky
  • 5,076
  • 1
  • 16
  • 28
5
votes
1 answer

difference between native and increment id generator type

What is the basic difference between when we use native and increment types id generator in hibernate. As i was having a entity, in which the generator was previuosly native, but then changed it to incremental for some time, it was working…
M.J.
  • 14,866
  • 25
  • 70
  • 95
4
votes
2 answers

Hibernate. Enhanced identifier generators

I decided to make use of a Hibernate id generator which meet the following requirements: - safe id generation when the domain is accessed from different applications(different JVMs) - make use of id intervals (do not query the database every time a…
Bax
  • 3,876
  • 3
  • 35
  • 59
4
votes
1 answer

How to get the generated key for a column with lowercase characters from Oracle using JdbcTemplate (or plain JDBC)

If I create a table like this: create table standard ( id NUMBER GENERATED by default on null as IDENTITY PRIMARY KEY, text varchar2(200) ) I can insert some data and get the generated id back with a method like this: Object…
Jens Schauder
  • 65,795
  • 24
  • 148
  • 294
4
votes
2 answers

In NHibernate ID Generator section in mapping files, What is the meaning of assigned and select?

In NHibernate ID Generator section in mapping files, What is the meaning of assigned and select?
masoud ramezani
  • 20,058
  • 28
  • 92
  • 149
3
votes
3 answers

MySQL 5 atomic id generator

My logic need to know the ID of a table before INSERT (setting the id manually while inserting). Because the logic using this ID is on more than one server, letting mysql create an id might be a good idea but the function I wrote is not atomic so…
Christof Aenderl
  • 3,345
  • 2
  • 27
  • 41
1
2 3 4 5