| We have an entity BlocRecord with InheritanceType.JOINED having a composite primary key BlocRecordId
@Column(name = "source_")
String source ;
@Column(name = "messageType_")
String messageType ;
We have an entity FlowIn and we have a relation Map OneToMany from FlowIn to BlocRecord
@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<>();
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
Property mapProperty = BinderHelper.findPropertyByName( associatedClass, mapKeyPropertyName );
PersistentClass targetPropertyPersistentClass = InheritanceType.JOINED.equals( inheritanceState.getType() ) ?
mapProperty.getPersistentClass() : associatedClass;
mapProperty.getPersistentClass() returns null because the field id defined in an embedded class ==> The following exception is thrown :
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)
We didn't have this issue with Hibernate 5.1.14 A shortly test case is attached (please execute the class Main) |