We have an entity BlocRecord with InheritanceType.JOINED having a composite primary key BlocRecordId {code} @Embeddable public class BlocRecordId implements Serializable { @Column(name = "source_") String source ; @Column(name = "messageType_") String messageType ; } {code}
We have an entity FlowIn and we have a relation Map OneToMany from FlowIn to BlocRecord {code} @OneToMany(targetEntity = BlocRecord.class, cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "flowIn", orphanRemoval = true) @MapKey(name = "blocRecordId.messageType") private Map<java.lang.String, BlocRecord> blocRecord = new java.util.HashMap<>(); {code}
As the inheritanceType is JOINED, the system will try to fetch the PersistentClass of the key speicified in the annotation @KeyName by invoking the following code {code} Property mapProperty = BinderHelper.findPropertyByName( associatedClass, mapKeyPropertyName ); PersistentClass targetPropertyPersistentClass = InheritanceType.JOINED.equals( inheritanceState.getType() ) ? mapProperty.getPersistentClass() : associatedClass; {code} mapProperty.getPersistentClass() returns null because the field is defined in an embedded class ==> The following exception is thrown : {panel} java.lang.NullPointerException at org.hibernate.cfg.annotations.MapBinder.createFormulatedValue(MapBinder.java:448) at org.hibernate.cfg.annotations.MapBinder.bindKeyFromAssociationTable(MapBinder.java:181) at org.hibernate.cfg.annotations.MapBinder.access$000(MapBinder.java:66) at org.hibernate.cfg.annotations.MapBinder$1.secondPass(MapBinder.java:101) at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:54) at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processSecondPasses(InFlightMetadataCollectorImpl.java:1635) at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processSecondPasses(InFlightMetadataCollectorImpl.java:1603) at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:278) at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.build(MetadataBuildingProcess.java:83) at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:418) at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:87) at org.hibernate.boot.MetadataSources.buildMetadata(MetadataSources.java:179) at net.codejava.hibernate.Main.main(Main.java:15) {panel}
We didn't have this issue with Hibernate 5.1.14 A shortly test case is attached ( please execute the class Main HHH13353_TestCase ) |
|