ORMLite ManyToOne 的好友 JoinColumn 注解未处理
我一直在Android上摆弄ormlite。现在还处于早期阶段,到目前为止我真的很喜欢我所看到的。
在阅读手册时,我注意到可以使用 javax.persistence 注释而不是默认注释。当尝试定义 @ManyToOne 关系时,我有点困惑。通常我使用 @JoinColumn(name="xxx")
来用 @ManyToOne
定义列名,即。不是@Column(name="xxx")
。我是对的吗,或者我应该以不同的方式看待这个问题。
我快速浏览了一下,认为对 com.j256.ormlite.misc.JavaxPersistence.java 进行一些小的添加就可以解决这个问题。基本上是复制处理 @Column
的代码来代替处理 @JoinColumn
(可能没有“长度”)。
这也让我想知道使用标准 ormlite 注释和 javax.persistence 注释是否存在任何问题。诸如以下问题:
- 标准注释是否优先?以及
- 是否可以禁用 javax.persistence 注释的处理?
I have been fiddling with ormlite on android. It's early days and so far I really like what I have seen.
While reading the manual I noticed the ability to use javax.persistence
annotation instead of the default. When trying to define a @ManyToOne
relationship I cam a little unstuck. Normally I use a @JoinColumn(name="xxx")
to defined the column name with a @ManyToOne
, ie. not the @Column(name="xxx")
. Am I right, or should I be looking at this a different way.
I had a quick look and thought a few small additions to com.j256.ormlite.misc.JavaxPersistence.java
would resolve this issue. Basically the duplicating the code to handle the @Column
to instead handle the @JoinColumn
(maybe without the "length").
This also left me wondering is there were any issues with using both the standard ormlite annotations as well as the javax.persistence
ones. Questions like:
- do the standard annotations take precedence?, and
- can the processing of
javax.persistence
annotations be disabled?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不幸的是@user928550,ORMLite并不完全支持
javax.persistence
注释。手册中定义了对它们的有限支持:我很乐意改善对他们的支持,如果您想就如何进行提出建议。请使用 ORMLite 开发人员邮件列表来建议您添加内容:
回复您具体问题,
@DatabaseField
注释的存在将覆盖任何javax.persistence
注释处理,并且您无法禁用javax.persistence
的处理(除非你指定一个@DatabaseField
)。Unfortunately @user928550, the
javax.persistence
annotations are not completely supported by ORMLite. The limited support for them is defined in the manual:I'd be happy to improve the support for them if you want to make suggestions about how to proceed. Please use the ORMLite developers mailing list to suggest your additions:
In answer to you specific questions, existence of the
@DatabaseField
annotation will override anyjavax.persistence
annotation processing and you cannot disable the processing ofjavax.persistence
(unless you specify a@DatabaseField
).