JPA:我应该使用orm.xml清理实体类吗? [英] JPA: Should I clean up my entity classes using orm.xml?

查看:100
本文介绍了JPA:我应该使用orm.xml清理实体类吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前仅使用JPA批注,但我真的不喜欢我用太多的ORM详细信息污染了我的实体类,这些细节与它们的行为无关(例如,表名,id生成策略,联接列) ...).

I currently use JPA annotations only, but I really don't like that I'm polluting my entity classes with so many ORM details which really aren't relevant to their behavior (e.g. table name, id generation strategies, join columns...).

我看到 DataNucleus建议将XML格式的ORM相关注释改为(那些颜色是粉红色的),但是我还没有看到其他实现建议这样做,并且JPA似乎没有将批注分为这两类(我认为JDO确实如此).

I see that DataNucleus recommends putting ORM-related annotations in XML instead (those colored in pink), but I haven't seen any other implementations recommend this and JPA doesn't seem to separate annotations into these two groups (I think JDO does).

有人用这种方式使用批注+ orm.xml吗?您的经历是什么?

Is anyone using annotations+orm.xml in this way, and what are your experiences?

它会消除实体类别中的一些污染吗?还是会遇到问题?

Will it remove some of the pollution from my entity classes, or will I run into problems?

推荐答案

半定期我们面临的最大问题是,如果您想以 any 方式更改持久性映射仅使用注释就需要重新编译和重新部署.

The biggest issue we've faced on a semi-regular basis is that if you want to change your persistence mapping in any way using annotations alone you need to recompile and redeploy.

使用orm.xml为您提供一定程度的抽象性,这可以使重新配置更加直接,并且可以在技术上相同的代码库中实现(例如,您可以确保一行代码没有被隐藏在您的代码中)重新编译/重新部署).

Using orm.xml affords you a degree of abstraction which can make reconfiguration a little more straight forward, and achievable with technically the same code base (eg you're sure that a line of code hasn't snuck into what you're recompiling/redeploying).

您可以同时使用注释配置-这是我现在正在使用的环境-类使用功能类型的持久性元数据(即外键,联接等)进行注释-具有代码级表示形式),而无关的信息(例如表/列名称)存储在配置文件中.

You can use both annotations and configuration - which is the environment I'm now working with - classes are annotated with functional type persistence metadata (i.e. foreign keys, joins, etc - things which have a code level representation) while irrelevant information (i.e. table/column names) are stored in configuration files.

当我们使用一种配置机制而不是另一种配置机制时,我们仍在尝试开发一些清晰的启发式方法,但是我们正在实现这一点.

We're still trying to develop some clear heuristics around when we use one configuration mechanism over another, but we're getting there.

这篇关于JPA:我应该使用orm.xml清理实体类吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆