-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Manually created sequence in postgresql is not working correctly #11591
Comments
I'm no JPA expert but shouldn't be |
I think you are right. I followed this quickstart guide: https://quarkus.io/guides/hibernate-orm without thinking too much, I guess the guide should be corrected ? |
Yes, would you care to send a PR? CC @Sanne |
right, this is a bit confusing. The default ID generation strategy uses an in-memory pool, and assumes an initial value of I wonder if we should trigger a warning when the |
BTW, the quickstart guide isn't necessarily wrong; I'm not sure which entities that example is supposed to use, but it is possible that they have a compatible mapping. |
@Sanne @svinther there is only one example entity in the guide and the fact that there is no |
The annotation is not mandatory, so why is that confusing? The I'm playing devil's advocate.. I'm open to suggestions but I'm just not sure what to do here. Clearly, the mapped objects and the physical schema need to match, or the ORM won't work - but I hope this doesn't come as a surprise, we can only automate this to some extent. |
I'm sorry for my ignorance but if the annotation is not present then we expect a generator of name My point is that if you follow the guide you'll not end up with a functional app...
|
no if it refers to a generator |
Ok, thanks for clarification. In that case, this issue is very likely a bug... |
Are you sure about that Sanne? Isn't that only the case when you have actually explicitly defined a
|
Yeah, if you just use |
Oh wait, are you guys talking about a case where you have written I would have thought that that would be a hard error at startup. AFAIK, that isn't something that's allowed. |
@Sanne I feel like this is sort of a bug in Hibernate. The |
I agree @gavinking , I've also just learned via this issue that it doesn't fail hard - as I would also except. on the other hand I see how it tries to get out of the way and make a reasonable assumption, and even if it's questionable I don't think we can "fix" this without breaking a lot of existing applications. But in conclusion this is only a problem in combination with self-defined schemas.. and this is an area in which people need to take care for "manually": I'd say it's always going to be error prone, no matter what we do. Not sure about this being a bug. Ideally, wondering if we can test the sequence state at initialization. |
Yup. I think we should go with your suggestion above and emit a warning, at least. And if we had some sort of "strict" mode I would upgrade it to an error in H6. |
Ufff, I think I found something worse. According to the spec, generator names are global to a persistence unit, and the definition of a But according to my tests, in Hibernate 6 the generator name is local to the class the annotation occurs in, and can't be shared between entities or defined in a separate utility class. (I haven't tested 5.5 yet.) Am I understanding this correctly @sebersole? |
Starting in 5.3 we added a setting
(`hibernate.jpa.compliance.global_id_generators`) to control whether those
names are global or local. As you say JPA says they should be global
regardless of placement. Our setting allows that to happen in a more
natural (imo) paradigm.
I am not sure I have tested that aspect in 6 yet.
…On Sat, Aug 29, 2020 at 7:26 AM Gavin King ***@***.***> wrote:
Ufff, I think I found something worse. According to the spec, generator
names are global to a persistence unit, and the definition of a
SequenceGenerator is shared between all the classes in the PU.
But according to my tests, in Hibernate 6 the generator name is local to
the class the annotation occurs in, and can't be shared between entities or
defined in a separate utility class.
(I haven't tested 5.5 yet.)
Am I understanding this correctly @sebersole
<https://github.com/sebersole>?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#11591 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AABZIE6FU3N5UWYQHJHQOCLSDDXVBANCNFSM4QKHQ74Q>
.
|
Ah perfect, thanks, I will try that out. Indeed, I'm tempted to set that by default in Hibernate Reactive, WDYT? |
Oh wait you mean that in H5 the JPA-compliant behavior already is the default. OK that's good. |
FWIW I don't agree with the spec on this one and I'm happy we have the option to offer a better strategy. It would be tempting to switch the Quarkus default to use the non-global definitions. |
I agree that the single global sequence thing is a bit strange. |
I think we did in ORM 6.0, at least to some extent?
By the way, heads-up to @Sanne: we may need to expose this configuration property in Quarkus 3 to provide a migration path for users who created their schema with Hibernate ORM 5? Maybe that should be part of a more general effort to provide a migration guide to users of the Hibernate ORM extension for Quarkus, because I suspect there are other breaking changes. We got sidetracked, though. I must admit I'm not sure I understand the exact problem we need to solve in order to close this issue. I think the conclusion was there: (Sanne)
(Gavin)
Do I understand correctly that you would like to log a warning on startup (upon validating the schema?) when there is a |
Good point. Not sure about it being worth to itemize it all or simply go through the entire migration guide of ORM after we're done with the upgrade, and itemize+prioritize those - clearly we can't do it all but we should dedicate some time towards this. I'd not say it's a blocker for Quarkus 3 though, we can keep improving in subsequent minors.
Well you might say "sidetracked", I say "priorities" - the schema is wrong, we could improve the validation to be more user friendly but it doesn't feel super urgent to me, especially compared to other ongoing things.
Correct |
Describe the bug
Given an Entity with a Long type
@Id
column, when manually creating the sequence for the id columnCREATE SEQUENCE giftSeq
the behaviour of assigning is broken.Expected behavior
id's assignment follow the natural series development 1,2,3,...
Actual behavior
The id's assigned to follow the path 1,2,-46,-45,... until a collision happens
To Reproduce
Reproducer example here, with test case https://github.com/svinther/quarkus-problem-messysequence
Configuration
Environment (please complete the following information):
Additional context
If creating the sequence as "CREATE sequence giftSeq start 1 increment 50;" as seems to be hibernates default behavior, then everything seems to work correctly
The text was updated successfully, but these errors were encountered: