| So, I spent some time to diagnose this issue. If a column name is defined, ORM does not take into account the fact that we might be in a component. See https://github.com/hibernate/hibernate-orm/blob/master/hibernate-core/src/main/java/org/hibernate/cfg/Ejb3Column.java#L308 . Thus, our naming strategy is completely bypassed as it only passes the column name without any prefix to the naming strategy. The second issue we have is that we end up with having the following properties in the association row:
addresses.country
postal_code
Usually, if all the columns are prefixed with the same prefix (addresses in this case), getAssociationRow removes the prefix in https://github.com/hibernate/hibernate-ogm/blob/master/mongodb/src/main/java/org/hibernate/ogm/datastore/mongodb/MongoDBDialect.java#L647 . In this case, there is no common prefix so we end up having addresses.addresses.country and addresses.postal_code once the collection role is added. That being said, I think the real problem lies in OgmImplicitNamingStrategy: we are in the case of collection elements so we should have the following properties:
because OgmImplicitNamingStrategy only gets the last part in the case of collection elements. The fact is that recent ORM versions filter .collection&&element. when building the mapping before sending the property name to the naming strategy: https://github.com/hibernate/hibernate-orm/blob/master/hibernate-core/src/main/java/org/hibernate/cfg/Ejb3Column.java#L272 (introduced in 5.0.0.Beta1 to fix https://hibernate.atlassian.net/browse/HHH-6005). So I suspect this bug was silently introduced when we upgraded to ORM 5 and we didn't have a test for that. Note that in Ejb3Column#addColumnBinding, the property name is not filtered so OgmImplicitNamingStrategy works as expected. I don't see an easy way out... Thoughts anyone? |