Embedded class with @CurrentTimestamp annotated property issue

Hi everyone! and thanks in advance for the help. I am a newbie in Hibernate ORM just trying to understand the basics.
I am receiving a CompositeValueGenerationException error when running Spring Boot 3.3.4 with Hibernate Core 6.5.3.Final.
Just embedding one little class in another one:

First scenario:
Composed Class:

package com.springboot.app.entity;

import jakarta.persistence.Column;

import jakarta.persistence.Embedded;

import jakarta.persistence.Entity;

import jakarta.persistence.Id;

import lombok.Getter;

import lombok.NoArgsConstructor;

import lombok.Setter;

@Entity

@Getter

@Setter

@NoArgsConstructor

public class ComposedEntity {

@Id

private Long composedEntityId;

@Column(name="composedentity_name")

private String name;

@Embedded

private Audit audit;

}

Embbedable Class:

package com.springboot.app.entity;

import java.sql.Date;

import org.hibernate.annotations.CurrentTimestamp;

import org.hibernate.annotations.SourceType;

import jakarta.persistence.Column;

import jakarta.persistence.Embeddable;

import lombok.AllArgsConstructor;

import lombok.Getter;

import lombok.Setter;

@Getter

@Setter

@Embeddable

@AllArgsConstructor

public class Audit {

@CurrentTimestamp(source = SourceType.DB)

private Date validSince;

@Column(name="user_name")

private String userName;

public Audit() {}

}

When starting the Spring Boot App this results in a CompositeValueGenerationException:
Unable to build Hibernate SessionFactory; nested exception is org.hibernate.tuple.entity.CompositeValueGenerationException: Property of on-execution generated embeddable is not generated: audit.userName

But with just a minor change that is moving the “validSince” property from the Embbedable class to the composed one and the exception is no longer thrown:

Second scenario:
ComposedEntity Class:

package com.springboot.app.entity;

import java.sql.Date;

import org.hibernate.annotations.CurrentTimestamp;

import org.hibernate.annotations.SourceType;

import jakarta.persistence.Column;

import jakarta.persistence.Embedded;

import jakarta.persistence.Entity;

import jakarta.persistence.Id;

import lombok.Getter;

import lombok.NoArgsConstructor;

import lombok.Setter;

@Entity

@Getter

@Setter

@NoArgsConstructor

public class ComposedEntity {

@Id

private Long composedEntityId;

@Column(name="composedentity_name")

private String name;

@CurrentTimestamp(source = SourceType.DB)

private Date validSince;

@Embedded

private Audit audit;

}

Embedable Class:

package com.springboot.app.entity;

import jakarta.persistence.Column;

import jakarta.persistence.Embeddable;

import lombok.AllArgsConstructor;

import lombok.Getter;

import lombok.Setter;

@Getter

@Setter

@Embeddable

@AllArgsConstructor

public class Audit {

@Column(name="user_name")

private String userName;

public Audit() {}

}

And the Exception is gone and the application starts-up perfectly.
For me both scenarios should run seamlessly without any issues.

Am I missing to configure/code something important?
Am I missing to configure/code something not as important?
Could this be a bug?
Really appreciate any help!

I believe that this is a limitation/bug of the current implementation. Support for generated properties inside of embeddables is new AFAIK.
Please try to create a reproducer with our test case template and if you are able to reproduce the issue, create a bug ticket in our issue tracker and attach that reproducer.

This is a bug:
https://hibernate.atlassian.net/browse/HHH-16957

I created a ticket because I did not found the previous one.
https://hibernate.atlassian.net/browse/HHH-18756

1 Like