I have a database table: Admin(id, name, status_id) fields and another AdminStatus(id, code, description). I initially though of creating a one-to-one relationship by creating a unique constraint on status_code field in the Admin table as below:
CREATE TABLE admin_status
( id INT NOT NULL,
code INT NOT NULL,
description varchar2(10) NOT NULL,
CONSTRAINT admin_status_pk PRIMARY KEY (id)
);
CREATE TABLE admin_status
( id INT NOT NULL,
code INT NOT NULL,
description varchar2(10) NOT NULL,
CONSTRAINT admin_status_pk PRIMARY KEY (id)
);
JPA Mappings (I'm using EBean ORM btw):
@Entity
public class admin extends Model {
private String name;
...
@OneToOne(mappedBy = "admin", cascade = CascadeType.ALL)
private AdminStatus status;
My question is different from the one below, in my opinion base on the fact that any number Admins can be either Active - 0 or Inactive - ), hence can't be set as a unique constraint:
How to Create a real one-to-one relationship in SQL Server
How should I implement this properly so that the relationship are mapped correctly and optimally in JPA or EBean?