The issue is that hibernate for some reason is considering entity2 and entity3 (which are marked as DEFAULT NULL in table creation and nullable=true in RelatedEntities) as PrimaryKey. Hence it marks those columns as non-nullable internally and it also prints following statements: DEBUG PrimaryKey: Forcing column [entity2__id] to be non-null as it is part of the primary key for table [related_entities] and DEBUG PrimaryKey: Forcing column [entity3__id] to be non-null as it is part of the primary key for table [related_entities] There were unique keys and indexes on columns entity1, entity2 & entity3 on table related_entities, but even after removing those unique keys & indexes and re-creating the related_entities table, its still failing. As said before, this works correctly with hibernate version 4.3.8.Final. |