A
A
Alexey22222019-03-29 09:52:00
Java
Alexey2222, 2019-03-29 09:52:00

Why is @Id needed in Entity?

Why is the @Id field needed in Entity? What happens if I have a field with @Id, but there is no column with the field name?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
code_batya, 2019-03-29
@Alexey2222

1) Maybe in JPA?
2) Consider this example:

@Entity
@Table(name="users")
public class UsersDataSet {
    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    long user_id;
    //...
}

This means that the id field corresponding to the database will be associated with the user_id field in your class.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question