Skip to content
This repository was archived by the owner on Feb 23, 2023. It is now read-only.

Using java.time.Year in a JPA domain model needs serialization hint #827

Closed
odrotbohm opened this issue Jun 16, 2021 · 1 comment
Closed
Labels
status: declined A suggestion or change that we don't feel we should currently apply

Comments

@odrotbohm
Copy link

odrotbohm commented Jun 16, 2021

Assume a JPA domain model:

@Entity
class MyEntity {
  javax.time.Year year;
}

With that, running the native image fails with:

Caused by: com.oracle.svm.core.jdk.UnsupportedFeatureError: SerializationConstructorAccessor class not found for declaringClass: java.time.Year (targetConstructorClass: java.lang.Object). Usually adding java.time.Year to serialization-config.json fixes the problem.
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jun 16, 2021
@odrotbohm
Copy link
Author

odrotbohm commented Jun 16, 2021

This should be solvable outside Spring Native. The reason for the error is that Hibernate doesn't actually have a custom type definition for Year and falls back on its support for Serializable types (which Year implements). It then tries to create copies of Year instances by serializing and deserializing them.

OOTB support for Year is requested in this ticket. As a workaround, you can declare a custom JPA AttributeConverter:

@Immutable
@Converter(autoApply = true)
public class YearAttributeConverter implements AttributeConverter<Year, Integer> {

	@Override
	public Integer convertToDatabaseColumn(Year attribute) {
		return attribute == null ? null : attribute.getValue();
	}

	@Override
	public Year convertToEntityAttribute(Integer dbData) {
		return dbData == null ? null : Year.of(dbData.intValue());
	}
}

@odrotbohm odrotbohm changed the title When processing a JPA domain model, automatically register type hints for concrete enum types Using java.time.Year in a JPA domain model needs serialization hint Jun 16, 2021
@sdeleuze sdeleuze added status: declined A suggestion or change that we don't feel we should currently apply and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Jun 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: declined A suggestion or change that we don't feel we should currently apply
Development

No branches or pull requests

3 participants