spring boot - Error: "Mapped superclass 'BaseClass' may not specify a @Table" when using only

I am currently upgrading my project from Spring Boot 2.x to 3.x, and as part of this, I am also upgradi

I am currently upgrading my project from Spring Boot 2.x to 3.x, and as part of this, I am also upgrading from Hibernate 5.x to 6.6. The issue I’m facing occurs with a mapped-superclass that’s only defined using XML mapping (orm.xml), without any annotations in the Java class.

Problem: After the upgrade, I started getting the following error when trying to define a mapped-superclass in orm.xml:

Mapped superclass 'com.example.BaseClass' may not specify a @Table This was working fine in Hibernate 5.x, but after upgrading to Hibernate 6.6, I started encountering this error.

Setup: The Java class (BaseClass) is not annotated with any JPA annotations like @Entity, @Table, or @Id.

I am using only XML for mapping (no annotations).

I have defined the mapped-superclass in orm.xml and mapped the fields there.

The error indicates that JPA/Hibernate is trying to interpret the base class as an entity, but I am not using any annotations, only XML-based mapping.

orm.xml Configuration: Here is the configuration I have in orm.xml:

<entity-mappings xmlns=";
                 xmlns:xsi=";
                 xsi:schemaLocation="
                                     .xsd"
                 version="3.2">

    <!-- MappedSuperclass for common fields -->
    <mapped-superclass class="com.example.BaseClass" access="FIELD" metadata-complete="true">
        <attributes>
            <id name="id">
                <column name="id"/>
                <generated-value strategy="IDENTITY"/>
            </id>
            <basic name="ticker">
                <column name="ticker"/>
                <enumerated>STRING</enumerated>
            </basic>
        </attributes>
    </mapped-superclass>

</entity-mappings>

The issue: The error states: "Mapped superclass 'com.example.BaseClass' may not specify a @Table".

However, there are no annotations in the BaseClass Java file (no @Table or any other JPA annotations).

The BaseClass should not map to a table directly; it should only define common fields for its subclasses.

What I’ve tried: I’ve tried setting metadata-complete="true" to ensure that JPA only uses the XML configuration and ignores annotations, but the error persists.

I’ve verified that the class does not contain any annotations like @Table, @Entity, or @Id.

Questions: What am I doing wrong with the mapped-superclass configuration?

Why am I getting the "Mapped superclass may not specify a @Table" error when I'm not using any annotations?

Is there something in the XML configuration that I missed that is causing JPA to treat the mapped-superclass like an entity?

Could this issue be related to the upgrade from Hibernate 5.x to 6.6 or Spring Boot 2.x to 3.x? It was working fine with Hibernate 5.x.

Any help or suggestions would be greatly appreciated!

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1743751513a4500987.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信