如何停止为 BlazeDS 和 Java 编写 Java 属性设置器我不想要 JPA?
BlazeDS 不会序列化属性,除非它同时具有 getter 和 setter。但是,我的许多 Java 属性都是只读的。因此,我现在必须添加设置器来支持解组过程。如果这些域对象的任何用户开始自己调用这些设置器,则会破坏这些事物的值对象语义,并可能导致各种系统问题。
过去我不得不做很多这样的事情来支持 JPA 的某些方面,但我从来不喜欢它。这是因为我们将 JPA 注释放在属性上而不是私有字段上(以避免另一个问题)。
除了使用Javadoc来警告自己和他人之外,程序员还能做什么?
编辑:我应该补充一点,这些额外的设置器不是这些对象实现的公共接口的一部分......但它们仍然存在。
BlazeDS will not serialize a property unless it has both a getter and a setter. However, many of my Java properties are read-only. Therefore I am now having to add setters to support the Unmarshalling process. If any of the users of these domain objects start calling these setters themselves it'll break the value-object semantics of these things and likely cause all sorts of system problems.
I've had to do this a lot on the past to support certain aspects of JPA and never liked it. This was because we put our JPA annotations on the properties rather than the private fields (to avoid another problem).
Other than use Javadoc to warn myself and others, what's a programmer to do?
Edit: I should add that these extra setters are NOT part of the public interface these objects implement....but they are still there nonetheless.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以尝试使用
@Access
注释。这用于逐列覆盖用于该类的访问类型。它还可以让您在访问数据库时搞乱内容,如下所示:此示例不仅覆盖用于该类的“FIELD”访问权限,而且还导致数据库在值上添加前缀“Mr.”每次。这还可以允许您声明满足您其他要求的“虚拟”getter/setter,而不会搞乱 JPA 提交和检索。尝试一下,看看是否可以用来为您的问题制定解决方案。
You could try using the
@Access
annotation. This is used to override the access type being used for the class on a column-by-column basis. It also lets you mess with stuff when it goes to the database, like this:This example not only overrides the 'FIELD' access being used for the class, but it also causes the database to commit with "Mr. " prefixed on the value each time. This may also allow you to declare 'dummy' getters/setters that satisfy your other requirements without screwing up the JPA commits and retrieves. Try it out and see if this can be used to craft a solution for your issue.
您有多种选择:使用您自己的序列化机制或使用 BlazeDS 版本 4。我写了一篇与此相关的小文章,也许它可以帮助您。链接是 http://cornelcreanga.com/2009/09 /blazeds-amf-and-read-only-properties/。
You have several options: use your own serialization mechanism or use BlazeDS version 4. I wrote a small article related to that, maybe it can help you. The link is http://cornelcreanga.com/2009/09/blazeds-amf-and-read-only-properties/.