private static boolean isOneToOneMatching(OgmEntityPersister mainSidePersister, String mainSideProperty, OneToOneType inversePropertyType) { SessionFactoryImplementor factory = mainSidePersister.getFactory(); String associatedProperty = inversePropertyType.getRHSUniqueKeyPropertyName(); // If that's a OneToOne check the associated property name and see if it matches where we come from return mainSidePersister == inversePropertyType.getAssociatedJoinable( factory ) && mainSideProperty.equals( associatedProperty ); }
@Override public boolean isForeignJoinColumn(EntityType<?> ownerType, String attributeName) { AbstractEntityPersister persister = getEntityPersister(ownerType); Type propertyType = persister.getPropertyType(attributeName); if (propertyType instanceof OneToOneType) { OneToOneType oneToOneType = (OneToOneType) propertyType; // It is foreign if there is a mapped by attribute // But as of Hibernate 5.4 we noticed that we have to treat nullable one-to-ones as "foreign" as well return (oneToOneType).getRHSUniqueKeyPropertyName() != null || isNullable(oneToOneType); } // Every entity persister has "owned" properties on table number 0, others have higher numbers int tableNumber = persister.getSubclassPropertyTableNumber(attributeName); return tableNumber >= persister.getEntityMetamodel().getSubclassEntityNames().size(); }
@Override public String getMappedBy(EntityType<?> ownerType, String attributeName) { CollectionPersister persister = getCollectionPersister(ownerType, attributeName); if (persister != null) { if (persister.isInverse()) { return getMappedBy(persister); } else if (persister instanceof OneToManyPersister) { // A one-to-many association without a join table is like an inverse association return ""; } } else { EntityPersister entityPersister = getEntityPersister(ownerType); Type propertyType = entityPersister.getPropertyType(attributeName); if (propertyType instanceof OneToOneType) { return ((OneToOneType) propertyType).getRHSUniqueKeyPropertyName(); } } return null; }