"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > How to Resolve "Unknown column 'sequence_name' in 'where clause'" Error When Using @GeneratedValue GenerationType.TABLE with a Polymorphic Abstract Superclass in MySQL?

How to Resolve "Unknown column 'sequence_name' in 'where clause'" Error When Using @GeneratedValue GenerationType.TABLE with a Polymorphic Abstract Superclass in MySQL?

Published on 2024-11-17
Browse:593

How to Resolve

@GeneratedValue Polymorphic Abstract Superclass over MySQL

In a Spring MVC application utilizing Hibernate and MySQL, it has been observed that attempting to persist subclasses of an abstract superclass, BaseEntity, encounters a "Table 'docbd.hibernate_sequences' doesn't exist" error. This error arises from the use of GenerationType.TABLE for @GeneratedValue, and the lack of sequence support within MySQL.

Since using GenerationType.IDENTITY is not viable due to the abstract superclass managing entity IDs and GenerationType.SEQUENCE is not supported, it begs the question of how to resolve this issue. The provided code snippets illustrate the abstract superclass (BaseEntity), an example subclass (CCD), Domain Specific Language (DDL), and JPQL code within a Data Access Object (DAO).

The inheritance strategy employed is InheritanceType.TABLE_PER_CLASS, indicating separate tables for each subclass. Given MySQL's inability to use sequences, the alternative of using GenerationType.TABLE inevitably leads to the absence of a hibernate_sequences table.

The poster asserts that using @MappedSuperClass is not a viable option, citing the need for interchangeable ManyToOne relationships. As an example, AccessLog contains an actor_entity and a target_entity, both of which inherit from BaseEntity. In this scenario, using @MappedSuperClass would result in an error indicating that AccessLog cannot locate BaseEntity.

In an attempt to resolve the issue, a hibernate_sequences table was created as suggested. However, a new error emerged: "Unknown column 'sequence_name' in 'where clause.'" This error points to the SQL query initiated by Hibernate: "select sequence_next_hi_value from hibernate_sequences where sequence_name = 'BaseEntity' for update."

To address this specific error, the poster requires assistance in resolving the missing 'sequence_name' column within the hibernate_sequences table.

Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3