Hibernate: How to Implement a Custom, Sequence-Based ID Generator

preview_player
Показать описание
Today I will show you how you can Implement a Custom, Sequence-Based ID Generator with #Hibernate. A lot of applications use primary keys that are based on a sequence but use an additional prefix that contains semantic information.

If you like this video, please give me your thumbs up and share it with your friends and co-workers.

Like my channel? Subscribe!

Join the free Member Library:

Want to connect with me?
#Java
#JPA
#Hibernate
Рекомендации по теме
Комментарии
Автор

Hi, Mr.Thorben,

I have a question regarding using this with hibernate 6. I would like to implement this into my project but hibernate 6 had deprecated the LongType class, so I wonder if there's a new method to do this in hibernate 6

I'm using Java 17 with spring boot 3.0.2 and Gradle

thanks in advance

XanderWang
Автор

Hi Thorben... 1 Does using database sequence cause issue in case of distributed database....?? If no, what option can I use if I want to use a custom sequence generator in a distributed environment...?

sbkote
Автор

one of the clients I have is insisting that I create 'hibernating pretext followed by a sequence' to uniquely identify rows in a POSTGRES TABLE. WTF?! I dont know how should I go about it or explain to him why it is a bad idea. I just dont have enough info to explain.

BehruzbekOtayev
Автор

Hi Thorben,
I have implemented this ..but i am getting one error i.e.
com.Project cannot be cast to and Could not instantiate id generator..
Can you please help me out on this?

dineshpanigrahi
Автор

Hi Thorben, thanks, i learned a lot from your videos. But i was encountering Format specifier '%205d'; nested exception is Format specifier '%205d'\r\n\tat when i tried to use your year & month prefix. Could you please help? Thanks again

mrshahcloud
Автор

Sorry, could you please explain the need to override configure method ? It seems to be working fine without overriding it.

pjayanthreddy
Автор

Its not work for me, I used hibernate and spring data jpa in spring boot to create database (MySql) auto. But just only Schema database was created, can you help me fix it. thanks

linhnguyenvan
Автор

Thanks for this. But how about for Non-Id fields?

ryankristofferbartolay
Автор

Hi Thorben,


Great content and very helpful. Have one question though. Does it have to be one sequence generator for each entity if there are multiple entities that need a custom sequence? Because I see that the variable parts are all being passed as parameter values from the entity itself. Can't we reuse the same sequence generator for multiple entities?

rishinjiya
Автор

where is ConfigurationHelper class ?. Help me, plz

truongngocha
Автор

sir how to generate the id as eg, "212200001" As 21 is of this year and 22 of next.

shivendrakumarsingh
Автор

can some one explain why we need INCREAMENT_PARAM..

nandini-ecxl
Автор

exactly what i need, thank you so much!

hadoop
Автор

Anyone else got the could not instantiate id generator exception?

JohnDoe-qzji
Автор

I don't know if this is OOP's fault, or hibernate's, but this is ridiculous, overcomplicated bull$hit.
All we need is getAndIncrement a sequence from the database, and perform an insert in a transaction.
How are we supposed to remember this (which solution doesn't work since hibernate 6)?

AAadamsan