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

JPA-Annotation @AttributeOverride at type level is not evaluated properly when also using orm.xml #19867

Closed
fkeichfe opened this issue Sep 2, 2021 · 7 comments · Fixed by #20287
Labels
area/hibernate-orm Hibernate ORM kind/bug Something isn't working
Milestone

Comments

@fkeichfe
Copy link
Contributor

fkeichfe commented Sep 2, 2021

Describe the bug

I have an application with Quarkus using JPA, which has the following problem since I migrated from Quarkus 1.x to 2.x.

There exists a MappedSuperclass named BaseClass, with the following field, which is mapped by default to the database-column 'name':

@MappedSuperclass
public class BaseClass {

    private String name;

    ...
}

Now I have another class named DerivedClass, where I want to map the field to another db-column 'custom_name'.

@Entity
@AttributeOverride(name = "name", column = @Column(name = "custom_name"))  
public class DerivedClass extends BaseClass {
 ... 
}

But apperently the AttributeOverride-Annotation is ignored at runtime, as the application tries to read the (not existing) db-column 'name' - and not the column 'custom_name', as required by the annotation.

I managed to fix the problem via the following entry in the orm.xml-file, but I wonder why the AttributeOverride-Annotation is broken since Quarkus 2.x

    <entity class="DerivedClass">  
        <attribute-override name="name">  
            <column name="custom_name"/>  
        </attribute-override>  
    </entity>

Expected behavior

Expected behaviour is that the database column custom_name is read.

Actual behavior

2021-09-02 14:51:52,332 WARN [org.hib.eng.jdb.spi.SqlExceptionHelper] (executor-thread-0) SQL Error: 0, SQLState: 42703
2021-09-02 14:51:52,333 ERROR [org.hib.eng.jdb.spi.SqlExceptionHelper] (executor-thread-0) ERROR: column derivedclass2_.name does not exist

How to Reproduce?

No response

Output of uname -a or ver

No response

Output of java -version

openjdk version "11.0.10" 2021-01-19 LTS

GraalVM version (if different from Java)

No response

Quarkus version or git rev

2.2.1.Final

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

Maven 3.8.1

Additional information

No response

@fkeichfe fkeichfe added the kind/bug Something isn't working label Sep 2, 2021
@gastaldi gastaldi added area/hibernate-orm Hibernate ORM and removed triage/needs-triage labels Sep 2, 2021
@quarkus-bot
Copy link

quarkus-bot bot commented Sep 2, 2021

/cc @Sanne, @gsmet, @yrodiere

yrodiere added a commit to yrodiere/quarkus that referenced this issue Sep 13, 2021
@yrodiere
Copy link
Member

I just gave it a try on Quarkus 2.2.3.Final, and it works for me...

Are you using the latest version of Quarkus, 2.2.3.Final? If not, which one?

Are you sure you're using javax.persistence.AttributeOverride, and not some similarly-named, but incorrect annotation from your classpath (for example jakarta.persistence.AttributeOverride)?

Are you using Panache?

Can you provide a simple reproducer?

@yrodiere yrodiere added the triage/needs-reproducer We are waiting for a reproducer. label Sep 13, 2021
@fkeichfe
Copy link
Contributor Author

  • If tried it with all versions of Quarkus >= 2.0.1, including 2.2.3.Final, and it doesn't work (with Quarkus 1.x, it worked correctly)
  • I am using the correct version (javax.persistence.AttributeOverride).
  • I am not using Panache.

I will try to strip down my current project so that I can extract a reproducer.

yrodiere added a commit to yrodiere/quarkus that referenced this issue Sep 13, 2021
@fkeichfe
Copy link
Contributor Author

I found out what is triggering the faulty-behaviour:
If I add an orm.xml-file to resources\META-INF, then the AttributeOverride is ignored.

fkeichfe added a commit to fkeichfe/quarkus that referenced this issue Sep 15, 2021
@fkeichfe
Copy link
Contributor Author

@yrodiere
I have modified the Reproducer so that the test now fails:

[ERROR]   AttributeOverrideTest.attributeOverrideTakenIntoAccount:48
Expecting HashSet:
  ["name"]
to contain:
  ["custom_name"]
but could not find the following element(s):
  ["custom_name"]

@yrodiere
Copy link
Member

Thanks @fkeichfe . It seems to be a bug in Hibernate ORM; I filed a ticket upstream: https://hibernate.atlassian.net/browse/HHH-14827 . I will see what needs to be fixed in Hibernate ORM.

@yrodiere yrodiere added triage/upstream and removed triage/needs-reproducer We are waiting for a reproducer. labels Sep 16, 2021
@yrodiere
Copy link
Member

This will get fixed in ORM 5.6.0.Beta2/5.5.8.Final.

@yrodiere yrodiere changed the title JPA-Annotation @AttributeOverride is not evaluated properly JPA-Annotation @AttributeOverride at type level is not evaluated properly when also using orm.xml Sep 17, 2021
@quarkus-bot quarkus-bot bot added this to the 2.3 - main milestone Sep 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/hibernate-orm Hibernate ORM kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants