Doubt object orientation + java ORM

Asked

Viewed 117 times

4

I am wanting to store the data of my program via ORM and am separating cute each object.

My User object, for example, has its basic attributes and is also composed of other objects such as Address, Contact and Access.

Each object has an ID attribute, for identification and association...

My doubt is the following, in the constructor method of each class(User, Address, Contact and Access) Should I pass the corresponding id or only the other attributes? Because I think, suddenly Hibernate can assign the correct ID.

Public Class Cliente
   private long Id;
   private String Nome;

   Public Cliente(Long id,String Nome){} 
   'ou
   Public Cliente(String Nome){}  
   '?

2 answers

2


Endereço, Contato and Acesso are classes? Because if yes, very likely we have a small problem here. Yes, small, ironless.

That information is aggregated à um user - they belong to it and are compiled conceptually as (meta) data - in other words, without the need to design them from classes to objects; just define them as variables of a user.

About the inheritance, the id is associative. A user is one thing, a customer is another. A user can be a customer as well as a representative or administrator. The id(entificador) shared between the entities (usuario and cliente) should contextually be the even - a customer is a user, but not necessarily the other way around.

Finally, turning this into a technical language:

+-------+---------+---------+
| #     | Usuário | Cliente |
+-------+---------+---------+
| Id    | 1       | 1       |
+-------+---------+---------+

That one id will always belong to the user, no exceptions. Remember: customers are users; administrators are users; banned are users. Regardless of circumstance, living organisms are users.

To finish, you must define the common characteristics of all users in the said class; in the children (administrator, client, representative, etc.) you add their particularities BUT "borrow" the id of the father.

0

Hibernate Treats relational ids as Object so you must declare with The Addressed Object ,Contact and Access within the Client class if your client table has the idenderecho, idcontact and idaccess fields and they must be indexed with foreign keys.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.