org.hibernate.mapping.PersistentClass#getProperty does not support composite ids
Description
Activity
Show:
Details
Details
Assignee
Unassigned
UnassignedReporter
Thomas Mortagne
Thomas MortagneComponents
Affects versions
Priority
Created May 21, 2021 at 8:06 AM
Updated May 21, 2021 at 8:06 AM
I have the following mapping:
<class name="com.xpn.xwiki.doc.XWikiLink" table="xwikilinks"> <composite-id unsaved-value="undefined"> <key-property name="docId" column="XWL_DOC_ID" type="long" /> <key-property name="link" type="string"> <column name="XWL_LINK" index="XWLNK_LINK" length="766" /> </key-property> </composite-id> <property name="fullName" type="string" column="XWL_FULLNAME" length="768" /> </class>
and I was expecting the following to work
persistentClass.getProperty("link")
but it tells me my property does not exist.
When looking at getProperty implementation I can see that it does look at the identifier but only if it's a unique identifier and completely miss the Component identifiers which feels like at least an inconsistency.
I had to add the following workaround before my call to getProperty():
KeyValue identifier = persistentClass.getIdentifier(); if (identifier instanceof org.hibernate.mapping.Component) { Iterator<Property> it = ((org.hibernate.mapping.Component) identifier).getPropertyIterator(); while (it.hasNext()) { Property property = it.next(); if (property.getName().equals(propertyName)) { return getConfiguredColumnName(property); } } } return getConfiguredColumnName(persistentClass.getProperty(propertyName));