Hello Guys..
I want to map this SQL in my objects (Users, Authorities):
Code:
CREATE TABLE users
(
username character varying(50) NOT NULL,
"password" character varying(50) NOT NULL,
enabled boolean NOT NULL,
CONSTRAINT users_pkey PRIMARY KEY (username)
);
CREATE TABLE authorities
(
username character varying(50) NOT NULL,
authority character varying(50) NOT NULL,
CONSTRAINT fk_authorities_users FOREIGN KEY (username)
REFERENCES users (username) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
);
CREATE UNIQUE INDEX ix_auth_username
ON authorities
USING btree
(username, authority);
Actualy, i have 2 classes, like this:
Code:
@Entity
@Table(name = "Users")
public class Users{
@Id
@Column(name = "username", nullable = false, unique = true)
private String username;
@Column(name = "password", nullable = false)
private String password;
@Column(name = "enabled", nullable = false)
boolean enabled;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public boolean isEnabled() {
return enabled;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
}
And
Code:
@Entity
@Embeddable
@Table(name = "Authorities")
public class Authorities {
@Id @OneToOne
@JoinColumn(name = "username")
private Users username;
@Column(name = "authority")
private String authority;
public Users getUsername() {
return username;
}
public void setUsername(Users username) {
this.username = username;
}
public String getAuthority() {
return authority;
}
public void setAuthority(String authority) {
this.authority = authority;
}
}
SO, how can i produce the same with hibernate?
Regards