# Hbm2java for PK=FK generates invalid sources

**URL:** https://discourse.hibernate.org/t/hbm2java-for-pk-fk-generates-invalid-sources/12367
**Category:** Hibernate Tools
**Created:** [July 13, 2026, 4:04pm UTC](https://discourse.hibernate.org/t/hbm2java-for-pk-fk-generates-invalid-sources/12367 "2026-07-13T16:04:15Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![pekuz](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/pekuz/32/4349_2.png) [@pekuz](https://discourse.hibernate.org/u/pekuz)
#### Post date: [July 13, 2026, 4:04pm UTC](https://discourse.hibernate.org/t/hbm2java-for-pk-fk-generates-invalid-sources/12367/1 "2026-07-13T16:04:15Z")

</div>

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:

```auto
<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

```auto
<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.

---

<div class="post-metadata">

### Author: ![pekuz](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/pekuz/32/4349_2.png) [@pekuz](https://discourse.hibernate.org/u/pekuz)
#### Post date: [July 14, 2026, 8:34am UTC](https://discourse.hibernate.org/t/hbm2java-for-pk-fk-generates-invalid-sources/12367/2 "2026-07-14T08:34:55Z")

</div>

Hi all,

With more experiments, patching the hbm2java generated code with:

```auto
<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?

---

<div class="post-metadata">

### Author: ![Koen\_Aers](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/koen_aers/32/27_2.png) [@Koen\_Aers](https://discourse.hibernate.org/u/Koen_Aers)
#### Post date: [July 14, 2026, 8:45am UTC](https://discourse.hibernate.org/t/hbm2java-for-pk-fk-generates-invalid-sources/12367/3 "2026-07-14T08:45:47Z")

</div>

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

---

<div class="post-metadata">

### Author: ![pekuz](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/pekuz/32/4349_2.png) [@pekuz](https://discourse.hibernate.org/u/pekuz)
#### Post date: [July 14, 2026, 9:09am UTC](https://discourse.hibernate.org/t/hbm2java-for-pk-fk-generates-invalid-sources/12367/4 "2026-07-14T09:09:17Z")

</div>

Hi Koen,

thx for a hint, I have tried with:

```auto
<build.hibernate-tools.version>7.3.12.Final</build.hibernate-tools.version>

```

```auto
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](https://central.sonatype.com/artifact/org.hibernate.tool/hibernate-tools-maven) as of today.

---

<div class="post-metadata">

### Author: ![Koen\_Aers](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/koen_aers/32/27_2.png) [@Koen\_Aers](https://discourse.hibernate.org/u/Koen_Aers)
#### Post date: [July 14, 2026, 9:18am UTC](https://discourse.hibernate.org/t/hbm2java-for-pk-fk-generates-invalid-sources/12367/5 "2026-07-14T09:18:03Z")

</div>

Since the [tooling code has been merged into the ORM codebase](https://in.relation.to/2026/05/04/hibernate-tools-moves-to-orm/), the coordinates of the maven plugin have been changed/aligned. For 7.4.x (and later), please use

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

```

Cheers, Koen

---

<div class="post-metadata">

### Author: ![pekuz](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/pekuz/32/4349_2.png) [@pekuz](https://discourse.hibernate.org/u/pekuz)
#### Post date: [July 14, 2026, 9:46am UTC](https://discourse.hibernate.org/t/hbm2java-for-pk-fk-generates-invalid-sources/12367/6 "2026-07-14T09:46:01Z")

</div>

Hi Koen,

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

```auto
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.

---

<div class="post-metadata">

### Author: ![Koen\_Aers](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/koen_aers/32/27_2.png) [@Koen\_Aers](https://discourse.hibernate.org/u/Koen_Aers)
#### Post date: [July 14, 2026, 12:15pm UTC](https://discourse.hibernate.org/t/hbm2java-for-pk-fk-generates-invalid-sources/12367/7 "2026-07-14T12:15:55Z")

</div>

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](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.

---

<div class="post-metadata">

### Author: ![pekuz](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/pekuz/32/4349_2.png) [@pekuz](https://discourse.hibernate.org/u/pekuz)
#### Post date: [July 14, 2026, 3:16pm UTC](https://discourse.hibernate.org/t/hbm2java-for-pk-fk-generates-invalid-sources/12367/8 "2026-07-14T15:16:35Z")

</div>

Thank you for fast recheck.

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

---

<div class="post-metadata">

### Author: ![pekuz](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/pekuz/32/4349_2.png) [@pekuz](https://discourse.hibernate.org/u/pekuz)
#### Post date: [July 15, 2026, 1:20pm UTC](https://discourse.hibernate.org/t/hbm2java-for-pk-fk-generates-invalid-sources/12367/9 "2026-07-15T13:20:32Z")

</div>

HHH-20693

Thank you for your support!
