(N)Hibernate:具有关系的核心/主映射

发布于 2024-07-10 06:46:03 字数 763 浏览 7 评论 0原文

我正在一家中型公司开始工作,主要工作是编写与其 ERP 系统交互的自定义​​应用程序。 这是我第一次做这种工作,所以ERP的概念对我来说是新的,我正在零碎学习。

到目前为止,我只编写了两个应用程序,并且学习了数据库模型,并且只学习了完成工作所需的知识,但即使数量有限,我也可以开始看到一个大图景的形成。 我的想法是编写一个库,其中存储了所有映射/模型对象,以便新应用程序可以引用该库。 之后,每个应用程序将创建自己的存储库,限制仅访问他们需要的内容和有意义的观点。

我遇到的问题是如何处理 (N)Hibernate 映射内部的关系。 如果我有一个在这个基础库中映射了完整关系的订单对象,那么没有什么可以阻止某人永远遍历这些关系(假设我是唯一的程序员......)。 因此,使用存储库作为某种范围限制在这个意义上根本不起作用。

相反,如果我限制此订单对象的 (N)Hibernate 映射中的关系,则存储库将返回一个订单对象,该对象仅与其范围所需的关系绑定。 缺点是我现在必须为每个项目创建映射,而不是拥有单个“映射存储”。

其他人如何处理这个问题?

有点不相关,但我也一直在将可能包含多种关系的 (N)Hibernate 持久对象转换为更适合特定应用程序的单一非持久对象(通常更受 UI 影响)。 这是常见的事情,还是我通过获取返回的对象并将它们转换为其他东西而放弃了 (N)Hibernate 的一些好处?

附注 关于 DDD 标签...我不知道这是否是 DDD 详细讨论的内容,但我确实订购了这本书。 不过,我不确定在这本书到达之前有什么好的资源可以看。

I am starting a job with a mid size company working mostly on writing custom apps that interact with their ERP system. This is my first time doing this sort of work, so the ERP concept is new to me and I am learning it piece meal.

I have only written two apps so far and have learned the database model as I went and only as much as I need to get the job done, but even with that limited amount I can start to see a big picture forming. My idea was then to write a library with all of the mappings/model objects stored there so that a new application can just reference this library. After that, each application would then create their own repository limiting access to only what they need and the perspective that makes sense.

The problem/question I have is how to deal with relationships inside the (N)Hibernate mappings. If I have an order object with full relationships mapped in this base library, there is nothing stopping someone from traveling those relationships forever (granted I'm the only programmer...). So using the repository as a sort of confinement of scope doesn't work at all in this sense.

If instead I limit the relationships in the (N)Hibernate mapping for this order object, the Repository returns an order object that is bound with only the relationships that it requires for its scope. The downside is that I now have to create mappings for each project instead of having a single 'mappings store'.

How do other people deal with this?

Kind of unrelated, but I've also been translating the (N)Hibernate persisted objects which may consist of several relationships into a sort of single-non-persisted object more suited to the specific application (usually much more influenced by the UI). Is this a common thing, or am I throwing some of the benefit of (N)Hibernate away by taking the returned objects and translating them into something else?

ps. About the DDD tag... I don't know if this is stuff that DDD addresses in detail, but I do have the book on order. I'm not sure of a good resource to look before the book arrives though.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

抱着落日 2024-07-17 06:46:03

很老的问题。 我想您已经找到了答案,但以防万一...

我看到有两种方法可以解决您的问题。

  1. 通过数据库中的用户帐户限制表访问。 例如在mysql中,你可以这样做。 缺点是,如果所有域类都在 nh dll 中映射和编译,程序员仍然可以看到这些实体。 如果他/她尝试访问它,就会触发异常(nh 尝试访问数据库表,数据库拒绝)。

  2. 为每种情况创建一个 dll。 但我想您可能还必须创建多个帐户。

Pretty old question. I guess you already found an answer, but in case...

I see two ways of resolving your problem.

  1. Restrict table access via user account in your database. For example in mysql, you can do this. The drawback is that if all your domain classes are mapped and compiled in your nh dll, the programmer can still see these entities. If he/she tries to access it, it will trigger an exception (nh tries to access a database table, the database refuse).

  2. Create a dll for each case. But I guess you also might have to create several accounts.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文