# Embeddable Inheritance Results in NPE At Application Startup

**URL:** <https://discourse.hibernate.org/t/embeddable-inheritance-results-in-npe-at-application-startup/10830>\
**Category:** Hibernate ORM\
**Created:** [December 24, 2024, 9:59pm UTC](https://discourse.hibernate.org/t/embeddable-inheritance-results-in-npe-at-application-startup/10830 "2024-12-24T21:59:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Christopher\_Gardner](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/christopher_gardner/32/3370_2.png) [@Christopher\_Gardner](https://discourse.hibernate.org/u/Christopher_Gardner)\
**Post date:** [December 24, 2024, 9:59pm UTC](https://discourse.hibernate.org/t/embeddable-inheritance-results-in-npe-at-application-startup/10830/1 "2024-12-24T21:59:24Z")

</div>

Having read about embeddable inheritance here:

> **[Hibernate ORM 6.6 - Embeddable Inheritance - In Relation To](https://in.relation.to/2024/07/12/embeddable-inheritance/)**
>
> The first release candidate for Hibernate ORM 6.6 has already been released, and a final version will be available very soon. In today’s blog post, I’m going to delve into a feature that has been requested for a long time but has never made it into...

I wanted to try in my own project, which uses the following:

- Java 21
- Spring Boot 3.4.1 (also tried with 3.4.0)
- Spring Data JPA
- Hibernate 6.6.4 (3.4.0 uses 6.6.2, I believe)
- AWS Aurora Postgres

I use orm.xml instead of annotations.

When I run a Spring DataJpaTest against an embeddable H2 database, everything works great. When I run against the real Aurora Postgres DB, however, the application fails to start as indicated by this exception:

Caused by: jakarta.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is java.lang.NullPointerException: Cannot invoke “org.hibernate.sql.model.ast.builder.ColumnValuesTableMutationBuilder.addValueColumn(org.hibernate.metamodel.mapping.SelectableMapping)” because “mutationBuilder” is null.

I tracked this down through debugging to MappingGroupBuilder (line 78)

```auto
	@Override
	public void accept(int selectionIndex, SelectableMapping selectableMapping) {
		final AbstractEntityPersister entityPersister = (AbstractEntityPersister) mutationTarget.getTargetPart()
				.getEntityPersister();
		final String tableNameForMutation = entityPersister.physicalTableNameForMutation( selectableMapping );
		final ColumnValuesTableMutationBuilder mutationBuilder = findTableDetailsBuilder( tableNameForMutation );
		mutationBuilder.addValueColumn( selectableMapping );
	}

```

The best that I could tell is that

```auto
entityPersister.physicalTableNameForMutation( selectableMapping );

```

returns a tableNameForMutation without the schema name prefix for the mapping that includes the default discriminator column. For example, if I had schema “myschema” and table “foo” and column “bar”, I would see a SelectableMapping with these values:

- tableExpression - myschema.foo
- mappedColumnExpression - bar

This would yield a tableNameForMutation value of “myschema.foo”.

However, if Foo has an embeddable hierarchy - Item as a superclass, Snack as an Item child, Diamond as another Item child, with a discriminator columnName “Item\_dtype”-- the SelectableMapping (ExplcitColumnDiscriminatorMappingImpl) tableExpression is only the table name “foo” without the schema name prefix.

This would yield a tableNameForMutation of “foo”.

findTableDetailsBuilder method (called by the accept method shown above) relies on tableNameForMutation as a key to find a ColumnValuesTableMutationBuilder in a map.

The map has the key “myschema.foo” instead of “foo”. accept() assumes it will get a mutationBuilder from findTableDetailsBuilder(). This results in an NPE.

I realize that adding Spring Boot/Spring Data JPA adds another layer of complexity. I suppose the H2 test works because there’s no schema name involved, or at least it appears that way.

I don’t have a test project to reproduce this yet. I’ve only my real project, which, of course, I can’t publish here. In the meantime, does anyone have any insights into this issue? It seems there needs to be a way to prefix the table name discriminator column mapping with the schema name.

Since this is a Spring Boot application, I’m setting the default hibernate schema with this property: spring.jpa.properties.hibernate.default\_schema.

---

<div class="post-metadata">

**Author:** ![beikov](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/beikov/32/258_2.png) [@beikov](https://discourse.hibernate.org/u/beikov)\
**Post date:** [December 27, 2024, 8:36am UTC](https://discourse.hibernate.org/t/embeddable-inheritance-results-in-npe-at-application-startup/10830/2 "2024-12-27T08:36:58Z")

</div>

This sounds like a bug to me. Please try to create a reproducer with our [test case template](https://github.com/hibernate/hibernate-test-case-templates/blob/master/orm/hibernate-orm-6/src/test/java/org/hibernate/bugs/JPAUnitTestCase.java) and if you are able to reproduce the issue, create a bug ticket in our [issue tracker](https://hibernate.atlassian.net) and attach that reproducer.

---

<div class="post-metadata">

**Author:** ![Christopher\_Gardner](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/christopher_gardner/32/3370_2.png) [@Christopher\_Gardner](https://discourse.hibernate.org/u/Christopher_Gardner)\
**Post date:** [December 27, 2024, 2:19pm UTC](https://discourse.hibernate.org/t/embeddable-inheritance-results-in-npe-at-application-startup/10830/3 "2024-12-27T14:19:38Z")

</div>

Without spring boot and spring data jpa, I was able to recreate the problem with pure hibernate with following:

- h2 jdbc URL
- h2 dialect
- schema (“GREET”) initialized in h2 jdbc URL
- hibernate.default\_schema (“GREET”) in peristence.xml

When I removed the default\_schema property, in both dialects (h2 and postgres), everything worked.

I’ll turn my new project into a reproducer and create a ticket, per your request.

---

<div class="post-metadata">

**Author:** ![Christopher\_Gardner](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/christopher_gardner/32/3370_2.png) [@Christopher\_Gardner](https://discourse.hibernate.org/u/Christopher_Gardner)\
**Post date:** [December 27, 2024, 3:21pm UTC](https://discourse.hibernate.org/t/embeddable-inheritance-results-in-npe-at-application-startup/10830/4 "2024-12-27T15:21:45Z")

</div>

I created a reproducer project, but cannot log into the issue tracker. I did what the last poster did here

> [@Trying to report a bug in Hibernate](https://discourse.hibernate.org/t/trying-to-report-a-bug-in-hibernate/5645/15):
>
> Is not working again I already had an account there, and had reported several bugs over the years, the issue is that there’s no longer an option to login. When I click the “Login” button, it just reloads the page. EDIT: Okay, I’ve found the way: Go to: [https://home.atlassian.com/](https://home.atlassian.com/) Create your account and login there Go to: [https://hibernate.atlassian.net/](https://hibernate.atlassian.net/) Click at the icon at the top-right of the page and that’s it

But that doesn’t work for me. When I try to create an issue, I get this message:

“You cannot create issues in this project.You are not authorized to perform this operation. Please log in.”

Then I go to the top left of the top bar to log in. Still doesn’t work. This time I get:

`You are not logged in, and do not have the permissions required to create an issue in this project as a guest.`

What are my options to creating a bug or sending my reproducer project?

---

<div class="post-metadata">

**Author:** ![Christopher\_Gardner](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/christopher_gardner/32/3370_2.png) [@Christopher\_Gardner](https://discourse.hibernate.org/u/Christopher_Gardner)\
**Post date:** [December 27, 2024, 6:45pm UTC](https://discourse.hibernate.org/t/embeddable-inheritance-results-in-npe-at-application-startup/10830/5 "2024-12-27T18:45:15Z")

</div>

I was finally able to get logged in to the hibernate jira. I created ticket:

[https://hibernate.atlassian.net/browse/HHH-18988](https://hibernate.atlassian.net/browse/HHH-18988)

I attached the reproducer as a tar gz file.
