Skip to content
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

Hibernate statup error since 3.7.x #38744

Closed
itatdcer opened this issue Feb 12, 2024 · 3 comments
Closed

Hibernate statup error since 3.7.x #38744

itatdcer opened this issue Feb 12, 2024 · 3 comments
Labels
area/hibernate-orm Hibernate ORM area/persistence OBSOLETE, DO NOT USE kind/bug Something isn't working triage/invalid This doesn't seem right

Comments

@itatdcer
Copy link

itatdcer commented Feb 12, 2024

Describe the bug

On app startup, I get the error:

2024-02-12 23:24:38,854 ERROR [io.qua.run.boo.StartupActionImpl] (Quarkus Main Thread) Error running Quarkus: java.lang.reflect.InvocationTargetException                                                                                                                                                                                                    
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)                                                                                                                                                                                                                                                                    
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)                                                                                                                                                                                                                                                  
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)                                                                                                                                                                                                                                          
        at java.base/java.lang.reflect.Method.invoke(Method.java:568)
        at io.quarkus.runner.bootstrap.StartupActionImpl$1.run(StartupActionImpl.java:113)
        at java.base/java.lang.Thread.run(Thread.java:840)
Caused by: java.lang.ExceptionInInitializerError
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
        at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
        at io.quarkus.runtime.Quarkus.run(Quarkus.java:70)
        at io.quarkus.runtime.Quarkus.run(Quarkus.java:44)
        at io.quarkus.runtime.Quarkus.run(Quarkus.java:124)
        at io.quarkus.runner.GeneratedMain.main(Unknown Source)
        ... 6 more
Caused by: java.lang.RuntimeException: Failed to start quarkus
        at io.quarkus.runner.ApplicationImpl.<clinit>(Unknown Source)
        ... 15 more
Caused by: org.hibernate.AnnotationException: Property 'dcer.portal.lkp.persistence.LkpRetencaoFonte.id' is annotated @GeneratedValue but is not part of an identifier
        at org.hibernate.boot.model.internal.EntityBinder.processIdPropertiesIfNotAlready(EntityBinder.java:1038)
        at org.hibernate.boot.model.internal.EntityBinder.handleIdentifier(EntityBinder.java:357)
        at org.hibernate.boot.model.internal.EntityBinder.bindEntityClass(EntityBinder.java:237)
        at org.hibernate.boot.model.internal.AnnotationBinder.bindClass(AnnotationBinder.java:423)
        at org.hibernate.boot.model.source.internal.annotations.AnnotationMetadataSourceProcessorImpl.processEntityHierarchies(AnnotationMetadataSourceProcessorImpl.java:256)
        at org.hibernate.boot.model.process.spi.MetadataBuildingProcess$1.processEntityHierarchies(MetadataBuildingProcess.java:279)
        at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:322)
        at io.quarkus.hibernate.orm.runtime.boot.FastBootMetadataBuilder.build(FastBootMetadataBuilder.java:415)
        at io.quarkus.hibernate.orm.runtime.PersistenceUnitsHolder.createMetadata(PersistenceUnitsHolder.java:101)
        at io.quarkus.hibernate.orm.runtime.PersistenceUnitsHolder.constructMetadataAdvance(PersistenceUnitsHolder.java:73)
        at io.quarkus.hibernate.orm.runtime.PersistenceUnitsHolder.initializeJpa(PersistenceUnitsHolder.java:40)
        at io.quarkus.hibernate.orm.runtime.HibernateOrmRecorder$1.created(HibernateOrmRecorder.java:78)
        at io.quarkus.arc.runtime.ArcRecorder.initBeanContainer(ArcRecorder.java:79)
        at io.quarkus.deployment.steps.ArcProcessor$notifyBeanContainerListeners1304312071.deploy_0(Unknown Source)
        at io.quarkus.deployment.steps.ArcProcessor$notifyBeanContainerListeners1304312071.deploy(Unknown Source)
        ... 16 more

The same code worked just fine with 3.6.x.

Basically, my entitites extends a MappedSuperclass entity like the following:

@MappedSuperclass
public abstract class IdRevisionBaseEntity implements Serializable {
    
    @Id
    private String guid;
    
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    @Column(name = "removed_at")
    private LocalDateTime removedAt;
    
    private Integer version;
    
    private Boolean active;
    
    @Column(name = "created_at")
    private LocalDateTime createdAt;
    
    @Column(name = "created_by")
    private Long createdBy;
    
    @Column(name = "updated_at")
    private LocalDateTime updatedAt;
    
    @Column(name = "updated_by")
    private Long updatedBy;
}

Getters / setters and all omitted. My PK is a "dummy" UUID and my functional key is composed by id and removedAt.

My BD is a MySql 8.

Expected behavior

Have the same behavior that existed in 3.6.x where this code worked seamless.

Actual behavior

Quarkus can't start with the reported error

How to Reproduce?

No response

Output of uname -a or ver

No response

Output of java -version

No response

Quarkus version or git rev

No response

Build tool (ie. output of mvnw --version or gradlew --version)

No response

Additional information

No response

@itatdcer itatdcer added the kind/bug Something isn't working label Feb 12, 2024
@quarkus-bot quarkus-bot bot added area/hibernate-orm Hibernate ORM area/persistence OBSOLETE, DO NOT USE labels Feb 12, 2024
Copy link

quarkus-bot bot commented Feb 12, 2024

/cc @gsmet (hibernate-orm), @yrodiere (hibernate-orm)

@itatdcer
Copy link
Author

Just in case, I created a small reproducer:

[email protected]:itatdcer/hibernate-startup-error.git

There is a unit test to run.

Changing quarkus platform version between 3.6.3 and 3.7.2 will not show / show the error on startup.

@yrodiere
Copy link
Member

yrodiere commented Feb 13, 2024

Hi,

Thanks for reporting.

You're trying to use @GeneratedValue(strategy = GenerationType.IDENTITY) on a column that is not the primary key.

From what I can see this has been disallowed in this commit: hibernate/hibernate-orm@0900622
This was to solve HHH-17653, where you can see in the comments:

the @GeneratedValue(strategy = GenerationType.IDENTITY) should not be applied to a non Identifier property, it happens to work in previous versions because the annotation was ignored.

So, turns out you're just getting an exception now, but your mapping was invalid even on Quarkus 3.6.

If you want more information, I would suggest discussing this with the Hibernate ORM developers directly: https://hibernate.zulipchat.com/#narrow/stream/132096-hibernate-user

Since this doesn't seem related to Quarkus at all, I'm closing this issue. Feel free to comment here if it turns out I was wrong.

@yrodiere yrodiere closed this as not planned Won't fix, can't repro, duplicate, stale Feb 13, 2024
@yrodiere yrodiere added triage/invalid This doesn't seem right triage/upstream labels Feb 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/hibernate-orm Hibernate ORM area/persistence OBSOLETE, DO NOT USE kind/bug Something isn't working triage/invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

2 participants