Doubts object orientation + java ORM

4

I want to store the data of my program via ORM and I'm separating each object nicely.

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 question is as follows, in the constructor method of each class (User, Address, Contact and Access) Should I pass the corresponding id or just the other attributes? Because I think, all of a sudden, 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){}  
   '?
    
asked by anonymous 24.04.2014 / 15:30

2 answers

2

Endereço , Contato and Acesso are classes? Because if so, we most likely have a small problem here. Yes, small , no ironies.

This information is aggregated to a user - they belong to it and are compiled conceptually as (meta) data - in other words, without designing them classes for objects; just set them as variables for a user .

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

Finally, turning this into a technical idiom:

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

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

Finally, you must set the common characteristics of all users in the said class whose class; in the children (administrator, client, representative, etc.) you add their peculiarities BUT "borrow" the id from the parent.

    
24.04.2014 / 15:41
0

Hibernate Treats relational ids as Object so you must declare with Object Address, Contact, and Access within the Client class if your client table has the idender, id, and idaccess fields, and they must be indexed with foreign keys. p>     

30.04.2014 / 20:22