Hbm2java for PK=FK generates invalid sources

For table defined alike:

CREATE TABLE FTS
(
myId INT NOT NULL,
CONSTRAINT PK PRIMARY KEY (myId),
CONSTRAINT FK
FOREIGN KEY (myId) REFERENCES TS ON DELETE CASCADE


);

then with pom.xml:

<build.hibernate-tools.version>6.6.10.Final</build.hibernate-tools.version> <!-- should match SB -->
...

<goals>
     <goal>hbm2java</goal>   </goals>
   <configuration>     <propertyFile>       ${project.build.directory}/resources/hibernate.properties</propertyFile>
     <ejb3>true</ejb3>
     <jdk5>true</jdk5>
     <detectOptimisticLock>false</detectOptimisticLock>
     <revengFile>src/main/hibernate/reveng.xml</revengFile>
     <packageName>dbo</packageName>
   </configuration> </execution>

results in:

@GenericGenerator(name="dbo.FTSIdGenerator", strategy="foreign")@Id @GeneratedValue(generator="dbo.FTSIdGenerator")
@Column(name="myId", unique=true, nullable=false)
public int getMyId() {
return this.myId;
}

but in runtime with

<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-core</artifactId>
<version>6.6.49.Final</version>

getting:

Caused by: org.hibernate.MappingException: param named "property" is required for foreign id generation strategy
at org.hibernate.id.ForeignGenerator.configure(ForeignGenerator.java:84)
at org.hibernate.id.factory.internal.StandardIdentifierGeneratorFactory.createIdentifierGenerator(StandardIdentifierGeneratorFactory.java:231)
... 22 more

My expectation is that generator generates mapping that loads without exceptions. I speculate that:

@GenericGenerator(name="dbo.FTSIdGenerator", strategy="foreign") @GeneratedValue(generator="dbo.FTSIdGenerator")

annotations are not needed at the raw column property.

Hi all,

With more experiments, patching the hbm2java generated code with:

<replaceregexp
        flags="m"
        match='^\s*@GenericGenerator\(name="dbo\.FTSIdGenerator".*$'
        replace='    @Id // PK=FK issue patched'>

helps. So I guess I could report as a new issue in the hmb2java tool.

Any objections, please?

Hi @pekuz,
This bug is present in the 6.x and older releases. It has been fixed when the tooling codebase was merged into ORM. Can you please try if the problem persists in version 7.4.5.Final or 8.x?
Cheers, Koen

Hi Koen,

thx for a hint, I have tried with:

<build.hibernate-tools.version>7.3.12.Final</build.hibernate-tools.version>
package dbo;
// Generated Jul 14, 2026, 10:58:20 AM by Hibernate Tools 7.3.12.Final

but to the same erroneous outcome at 6.x runtime:

Caused by: org.hibernate.MappingException: param named "property" is required for foreign id generation strategy
at org.hibernate.id.ForeignGenerator.configure(ForeignGenerator.java:84)

That said, no 7.4.5.Final has been found at Maven Central: org.hibernate.tool:hibernate-tools-maven as of today.

Since the tooling code has been merged into the ORM codebase, the coordinates of the maven plugin have been changed/aligned. For 7.4.x (and later), please use

<dependency>
    <groupId>org.hibernate.orm</groupId>
    <artifactId>hibernate-maven-plugin</artifactId>
    <version>7.4.5.Final</version>
</dependency>

Cheers, Koen

Hi Koen,

thx, I got it now, the groupId and artifactId has to be changed too. I’m getting now:

package dbo;
// Generated Jul 14, 2026, 11:36:36 AM by Hibernate Tools 7.4.5.Final

but it still generates @GenericGenerator and @GeneratedValue annotations on the PK=FK column property, resulting in the same 6.x runtime mapping exception.

Hi,
Thanks for verifying with 7.4.5. This is indeed a bug in the hibernate-orm tooling. The existing test for this scenario (OneToOne/TestCase.java#testGenerateAnnotatedClassesAndReadable) apparently only validates the schema against the database and never builds a SessionFactory, so ForeignGenerator.configure() is never called and the missing property parameter goes undetected.
Could you file a bug against https://hibernate.atlassian.net/browse/HHH for it? Ideally include your create.sql and reveng.xml so it’s easy to reproduce.
As a broader point, ForeignGenerator has been @Deprecated(since = "6", forRemoval = true). Rather than just adding the missing property parameter, the tooling should probably stop generating @GenericGenerator(strategy="foreign") altogether for PK=FK columns and use @MapsId instead as that’s the modern JPA way to express this pattern.

Thank you for fast recheck.

I’ll record it, once I get over jira login issues…

HHH-20693

Thank you for your support!