[英]Why does hibernate's getPropertyNames return an empty list if all attributes are part of the key?
Here's a fun head-scratcher to start the month of May off! 这是五月开始的一个有趣的头脑!
I have a hibernate mapping like so: 我有一个像这样的hibernate映射:
<hibernate-mapping default-lazy="false">
<class name="my.class.name" table="MY_CLASS_TABLE">
<composite-id>
<key-property name="prop1" column="PROP_1" />
<key-property name="prop2" column="PROP_2" />
<key-property name="prop3" column="PROP_3" />
</composite-id>
</class>
</hibernate-mapping>
And a function that goes through and builds a "dictionary" of class names and properties. 并且是一个贯穿并构建类名和属性“字典”的函数。 I have no problems until I get to this class, and for some reason, my call to getPropertyNames()
returns an empty list. 在我上课之前我没有问题,出于某种原因,我对getPropertyNames()
调用返回一个空列表。 If there is at least one property outside the composite-id
, I don't have any problems. 如果在composite-id
之外至少有一个属性,我没有任何问题。 The kludgy work-around I have is to add a dummy field outside the id (yuck!) and suddenly everything works. 我所拥有的kludgy解决方法是在id之外添加一个虚拟字段(yuck!)然后突然一切正常。
Any idea why this is happening and what I can do to solve it? 知道为什么会这样,我能做些什么来解决它?
Thanks in advance for your help! 在此先感谢您的帮助!
After further digging, I found getIdentifierType()
and getIdentifierPropertyName()
do the job. 在进一步挖掘之后,我发现getIdentifierType()
和getIdentifierPropertyName()
完成了这项工作。 For a composite key like this one, I check the type to see if it's an instance of CompositeCustomType or ComponentType, and if it is, throw it into a temporary var, and call getPropertyNames()
on that temporary var. 对于像这样的复合键,我检查类型以查看它是否是CompositeCustomType或ComponentType的实例,如果是,则将其抛入临时var,并在该临时var上调用getPropertyNames()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.