简体   繁体   English

如果所有属性都是密钥的一部分,为什么hibernate的getPropertyNames返回一个空列表?

[英]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.

相关问题 为什么即使表为空,Hibernate的DELETE仍返回1? - Why does Hibernate's DELETE return 1 even when table is empty? 为什么ForkJoinPool :: shutdownNow返回一个空列表? - Why does ForkJoinPool::shutdownNow return an empty list? Hibernate CreateNativeQuery返回空列表 - Hibernate CreateNativeQuery return empty list 所有实体的休眠公共主键部分 - Hibernate Common Primary Key part of All Entity 如何使用 Hibernate 仅更新所有实体属性的一部分 - How to update only a part of all entity attributes with Hibernate 为什么在 Java 中的空列表的情况下 allMatch 返回 true? - Why does allMatch return true in case of empty list in Java? 初学者休眠:为什么我的休眠查询只返回一个结果,而不是列表? - Beginner hibernate: Why does my hibernate query return only one result, instead of a list? 如果我的表中有数据,为什么 Hibernate 条件返回空列表? - why Hibernate criteria return empty list if I have data in my table? 如果关系表为空,Hibernate 是否返回 null 或空集合? - Does Hibernate return null or empty collection if table in relation is empty? Groovy:为什么用空格分割()空字符串会返回一个空字符串的列表? - Groovy: Why does split()ing an empty string by space return a list of one empty string?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM