views:

71

answers:

1

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.

+1  A: 

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.

Nelson