Hibernate属性名称大写问题
我对 hibernate/JavaBeans 如何构造属性名称有疑问。
这是我的财产。
private boolean aNumberFl;
@Column( name = "aNumberFl", nullable = false )
@Type( type = "yes_no" )
public boolean getANumberFl()
{
return aNumberFl;
}
public void setANumberFl( boolean var )
{
this.aNumberFl = var;
}
一切都很好,除了休眠内部认为我的属性名称是 ANumberFl 而不是 aNumberFl 之外。 JavaBean 约定检查属性 getter 的前两个字符(在 get 之后),以及它们是否都是大写并且不会无法获取属性名称。但这与我的小写字段名称不一致。这在 JavaBean 世界中都是允许的,但是有一个名为 aNumberFl
或 ANumberFl
的字段将产生相同的 getter 名称。这意味着当 get 方法是源时,它必须选择其中之一,并且选择后者。
我尝试将注释移到字段上,但这导致了其他问题,我现在不会讨论这些问题,而且我不确定这是否是一个好主意。
是否有办法覆盖 hibernate 从 getter 方法名称推断出的默认属性名称?
谢谢。
I have a problem with how hibernate/JavaBeans constructs property names.
Here's my property.
private boolean aNumberFl;
@Column( name = "aNumberFl", nullable = false )
@Type( type = "yes_no" )
public boolean getANumberFl()
{
return aNumberFl;
}
public void setANumberFl( boolean var )
{
this.aNumberFl = var;
}
Everything is fine except for fact the hibernate internally thinks my property names is ANumberFl rather than aNumberFl. The JavaBean conventions checks the first two chars of the property getter (after the get) and if they are both capitals and does not uncapatilise to get the property name. However this is inconsistent with my field name which has a lower case. This is all permissible in JavaBean world but having a field called aNumberFl
OR ANumberFl
would yield the same getter name. This means when the get method is the source it has to pick one of the other, and is picking the latter.
I tried moving the annotations onto the field but that caused other issues which I won't go into now, and am not sure that's a good idea anyway.
Is there anyway of overriding the default property name that hibernate infers from the getter method name?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议重命名该属性并为其指定一个更有意义的名称,
a
- 如果它是“A-Number”,并且您有一个“B-Number”,请将属性设为大写 -丑陋,但可能有用。Fl
没有任何意义 - 扩展该缩写,一切都会好起来的。I'll advice to rename the property and give it a more meaningful name
a
- if it is "A-Number", and you have a "B-Number", make the property uppercase - ugly, but might work.Fl
doesn't mean anything - expand that abbreviation and all will be fine.