JPA Static model generator not generating json fields

I have the following User entity:

@Getter
@Setter
@Accessors(chain = true)
@RequiredArgsConstructor
@Entity
public class User implements Serializable, UserDetails {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(columnDefinition = "SERIAL")
    @Setter(AccessLevel.NONE)
    private int id;

    @Column(columnDefinition = "JSONB")
    @JdbcTypeCode(SqlTypes.JSON)
    @Valid
    private Address address;
}
@Data
@Accessors(chain = true)
public class Address {
    @Size(max = 40)
    private String country;
    @Size(max = 40)
    private String city;
    @Size(max = 40)
    private String street;
    @Size(max= 6)
    private String zip;
}

The generated User_.class does not contain the ADDRESS field. And the Address_.class is not generated as well.

When I annotate the Address class with @Embeddable, the generation work but Hibernate throws a name conflict exception when running the app.

This is the exception message after annotating the Address class with @Embeddable:

HHH000099: an assertion failure occurred (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session): org.hibernate.AssertionFailure: conflicting type names

I’m using Spring boot 3.3.4 with Hibernate 6.5.3.Final

The Hibernate Processor only generates the static metamodel for mapped classes, that is mapped superclasses, entities and embeddables, so you will need to mark Address as @Embeddable (note this is also required by the JPA specification, but Hibernate still tries to make things work if you don’t but this is one of the side effects).

As for the assertion error you’re encountering, I don’t see anything specifically wrong with the mappings you pasted here, though there are other components at play which might be interfering with the mappings (you mentioned Spring, and I suppose Lombok from the annotation).

The only thing I can suggest is trying to see if you can reproduce the problem using Hibernate only, you can start from our test case templates, and if you don’t there probably is something else messing with your mappings and causing the error.

I experimented with your test case, which uses Hibernate 6.6.2.Final, I haven’t found any issues after adding the @Embeddable to the Address class.

After more internet searching, I found this Mapping a collection of embeddable with a JSON type.

I tried upgrading the Hibernate version in my spring boot app to 6.6.2.Final. Now everything worked as expected.

For the moment, I reverted the changes because Spring Boot 3.4.0 (which includes Spring Data JPA 3.4.0 and Hibernate 6.6.2.Final) will be released tomorrow. I’ll just wait and upgrade my project to solve it.