Why you need the @Id in the Entity?

Why you need a field with the @Id in the Entity? What if I have a field with @Id, and column name of the field not?
March 19th 20 at 09:07
1 answer
March 19th 20 at 09:09
Solution
1)May, in JPA?
2)let's discuss one example:
@Entity
@Table(name="users")
public class UsersDataSet {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
 long user_id;
//...
}


So the id field of the corresponding database will be associated with a field user_id in your class.
Yes, I understand, why do we need primary keys in the database? - Krystina_Gleichner commented on March 19th 20 at 09:12
@Krystina_Gleichner, Use Google. - Imogene15 commented on March 19th 20 at 09:15
It is used for relationships between tables? Or why at all? And physically(in the database) occur relationships between tables, for example when I'm in one entity is the object of another entity. Or when there is a sheet with simple objects - Krystina_Gleichner commented on March 19th 20 at 09:18
@Imogene15, I do not work Google does not know why - Krystina_Gleichner commented on March 19th 20 at 09:21
It serves exactly for what I wrote.
On one table, you create one class of dataset and mark its @Entity, which means that objects of this class contains the fields specified in the database table.
If one entity do you have a link to another entity, but in the table there is no column 'another_entity', then nothing will. Here's the code:
@Entity
@Table(name="users")
public class UsersDataSet {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
 long user_id;

 UsersDataSet anotherSet;
}

Will work just fine. - monserra commented on March 19th 20 at 09:24
@Krystina_Gleichner, uh-uh... You can be at the beginning of the study RMD. Learn what normalization is and how to do it. Then this issue will not be. :-) - terrill.Rodriguez commented on March 19th 20 at 09:27

Find more questions by tags Java EEJava