Reputation: 3805
I have well working Spring Security app which is using Oracle DB. And now I'm having 2 tables (according to this tutorial): users
and user_roles
.
SQL> DESCRIBE user_roles;
----------------------------------------- -------- ----------------------------
USER_ROLE_ID NOT NULL NUMBER
USERNAME NOT NULL VARCHAR2(100)
ROLE NOT NULL VARCHAR2(100)
SQL> DESCRIBE users;
----------------------------------------- -------- ----------------------------
USERNAME NOT NULL VARCHAR2(100)
PASSWORD NOT NULL VARCHAR2(100)
ENABLED NOT NULL NUMBER(1)
As you can see there is no ID
field in users
table. Two tables binded with username
.
Also Hibernate entity requires field with @Id
annotation. And now the main question:
Is it ok to mark not integer variable as an @Id
?
This is my entity:
@Entity
@Table(name = "Users")
public class Users {
@Id
@Column(name = "username")
private String username;
@Column(name = "password")
private String password;
@Column(name = "enabled")
private int enabled;
//getters and setters
}
Upvotes: 0
Views: 81
Reputation: 8434
As mentioned, yes it is possible.
More importantly the tutorial you are using is rather bad (having attempted it myself a few times long time ago) in comparison to others available.
A good code example that you will learn a lot from (as did I) can be found here:
http://fruzenshtein.com/spring-mvc-security-mysql-hibernate/
Upvotes: 1