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.
The above is the detailed content of How to Resolve "Unknown column 'sequence_name' in 'where clause'" Error When Using @GeneratedValue GenerationType.TABLE with a Polymorphic Abstract Superclass in MySQL?. For more information, please follow other related articles on the PHP Chinese website!