Khurelkhuyag M. (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
) *created* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiNDM1OTUwYTlh...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-16121?atlOrigin=eyJpIjoiNDM1OT...
) HHH-16121 (
https://hibernate.atlassian.net/browse/HHH-16121?atlOrigin=eyJpIjoiNDM1OT...
) @Embedded property not working with hibernate-enhance-maven-plugin (
https://hibernate.atlassian.net/browse/HHH-16121?atlOrigin=eyJpIjoiNDM1OT...
)
Issue Type: Bug Affects Versions: 6.1.6 Assignee: Unassigned Attachments:
proof-hibernate-embedded-not-working.zip Created: 31/Jan/2023 00:18 AM Environment:
OpenJDK 17 x64 Ubuntu Linux
Maven 3.8.6
Labels: core Priority: Major Reporter: Khurelkhuyag M. (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
)
This is my example project’s model classes. With this, If I try to load the Product with
the declared fetch graph it fails. The minimal sample project is attached. Without the
maven enhance plugin. it works.
@Embeddable
public class Picture {
private String name;
private int width;
private int height;
// constructors, getters, and setters ommited
}
@Entity
@Table(name = "productCategory" )
public class ProductCategory {
@ManyToOne(fetch = FetchType.LAZY)
private ProductCategory parent;
@Id
private Long id;
private String name;
@Embedded
private Picture picture;
@OneToMany(mappedBy = "parent" )
private List<ProductCategory> children;
// constructors, getters, and setters ommited
}
@Entity
@Table(name = "product" )
@NamedEntityGraph(
name = "Product.withAll" ,
attributeNodes = {
@NamedAttributeNode(value = "category" ),
}
)
public class Product {
@ManyToOne(fetch = FetchType.LAZY)
private ProductCategory category;
@Id
private Long id;
private String name;
@Embedded
private Picture picture;
// constructors, getters, and setters ommited
}
Stack trace:
Exception in thread "main" jakarta.persistence.PersistenceException: Converting
`org.hibernate.InstantiationException` to JPA `PersistenceException` : Could not
instantiate entity: : com.example.hibernateembedded.Picture
at
org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:165)
at org.hibernate.query.spi.AbstractSelectionQuery.list(AbstractSelectionQuery.java:374)
at org.hibernate.query.sqm.internal.QuerySqmImpl.list(QuerySqmImpl.java:1073)
at
org.hibernate.query.spi.AbstractSelectionQuery.getSingleResult(AbstractSelectionQuery.java:457)
at org.hibernate.query.sqm.internal.QuerySqmImpl.getSingleResult(QuerySqmImpl.java:1103)
at com.example.hibernateembedded.Main.fetch(Main.java:20)
at com.example.hibernateembedded.Main.main(Main.java:41)
Caused by: org.hibernate.InstantiationException: Could not instantiate entity: :
com.example.hibernateembedded.Picture
at
org.hibernate.metamodel.internal.EmbeddableInstantiatorPojoStandard.instantiate(EmbeddableInstantiatorPojoStandard.java:84)
at
org.hibernate.sql.results.graph.embeddable.AbstractEmbeddableInitializer.createCompositeInstance(AbstractEmbeddableInitializer.java:333)
at
org.hibernate.sql.results.graph.embeddable.AbstractEmbeddableInitializer.prepareCompositeInstance(AbstractEmbeddableInitializer.java:247)
at
org.hibernate.sql.results.graph.embeddable.AbstractEmbeddableInitializer.initializeInstance(AbstractEmbeddableInitializer.java:194)
at
org.hibernate.sql.results.internal.StandardRowReader.coordinateInitializers(StandardRowReader.java:152)
at
org.hibernate.sql.results.internal.StandardRowReader.readRow(StandardRowReader.java:97)
at
org.hibernate.sql.results.spi.ListResultsConsumer.consume(ListResultsConsumer.java:198)
at
org.hibernate.sql.results.spi.ListResultsConsumer.consume(ListResultsConsumer.java:33)
at
org.hibernate.sql.exec.internal.JdbcSelectExecutorStandardImpl.doExecuteQuery(JdbcSelectExecutorStandardImpl.java:443)
at
org.hibernate.sql.exec.internal.JdbcSelectExecutorStandardImpl.executeQuery(JdbcSelectExecutorStandardImpl.java:166)
at
org.hibernate.sql.exec.internal.JdbcSelectExecutorStandardImpl.list(JdbcSelectExecutorStandardImpl.java:91)
at org.hibernate.sql.exec.spi.JdbcSelectExecutor.list(JdbcSelectExecutor.java:31)
at
org.hibernate.query.sqm.internal.ConcreteSqmSelectQueryPlan.lambda$new$0(ConcreteSqmSelectQueryPlan.java:113)
at
org.hibernate.query.sqm.internal.ConcreteSqmSelectQueryPlan.withCacheableSqmInterpretation(ConcreteSqmSelectQueryPlan.java:335)
at
org.hibernate.query.sqm.internal.ConcreteSqmSelectQueryPlan.performList(ConcreteSqmSelectQueryPlan.java:276)
at org.hibernate.query.sqm.internal.QuerySqmImpl.doList(QuerySqmImpl.java:571)
at org.hibernate.query.spi.AbstractSelectionQuery.list(AbstractSelectionQuery.java:363)
... 5 more
Caused by: org.hibernate.PropertyAccessException: Could not set value of type
[org.hibernate.bytecode.enhance.spi.LazyPropertyInitializer$1] :
`com.example.hibernateembedded.Picture.height` (setter)
at org.hibernate.property.access.spi.SetterFieldImpl.set(SetterFieldImpl.java:81)
at
org.hibernate.metamodel.mapping.internal.AbstractEmbeddableMapping.lambda$setValues$1(AbstractEmbeddableMapping.java:106)
at
org.hibernate.metamodel.mapping.internal.EmbeddableMappingTypeImpl.forEachAttributeMapping(EmbeddableMappingTypeImpl.java:731)
at
org.hibernate.metamodel.mapping.internal.AbstractEmbeddableMapping.setValues(AbstractEmbeddableMapping.java:105)
at
org.hibernate.metamodel.internal.EmbeddableInstantiatorPojoStandard.instantiate(EmbeddableInstantiatorPojoStandard.java:78)
... 21 more
Caused by: java.lang.IllegalArgumentException: Can not set int field
com.example.hibernateembedded.Picture.height to
org.hibernate.bytecode.enhance.spi.LazyPropertyInitializer$1
at
java.base/jdk.internal.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:167)
at
java.base/jdk.internal.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:171)
at
java.base/jdk.internal.reflect.UnsafeIntegerFieldAccessorImpl.set(UnsafeIntegerFieldAccessorImpl.java:98)
at java.base/java.lang.reflect.Field.set(Field.java:799)
at org.hibernate.property.access.spi.SetterFieldImpl.set(SetterFieldImpl.java:53)
... 25 more
(
https://hibernate.atlassian.net/browse/HHH-16121#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-16121#add-comment?atlOrigin=ey...
)
Get Jira notifications on your phone! Download the Jira Cloud app for Android (
https://play.google.com/store/apps/details?id=com.atlassian.android.jira....
) or iOS (
https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100214- sha1:9509471 )