I'm trying to create an entity with the following mapping:
@Entity
@IdClass(AutenticacaoPK.class)
public class Autenticacao {
@Id
@OneToOne(cascade = CascadeType.REFRESH)
@JoinColumn(name = "codUsuario", unique = false)
private Usuario usuario;
@Id
@OneToOne(cascade = CascadeType.REFRESH)
@JoinColumn(name = "codEmpresa", unique = false)
private Empresa empresa;
@Id
@Column(nullable = false, length = 1000)
private String token;
}
And in the database the table looks like this:
CREATE TABLE autenticacao(
token character varying(1000) NOT NULL,
codusuario bigint NOT NULL,
codempresa bigint NOT NULL,
CONSTRAINT autenticacao_pkey PRIMARY KEY (codempresa, token, codusuario),
CONSTRAINT fk_92assff1b6x84mm97rlb7jl7m FOREIGN KEY (codusuario)
REFERENCES usuario (codusuario) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT fk_hb45dbp517t2eyghrwfo4ktqh FOREIGN KEY (codempresa)
REFERENCES empresa (codempresa) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT uk_92assff1b6x84mm97rlb7jl7m UNIQUE (codusuario),// NAO CRIAR
CONSTRAINT uk_hb45dbp517t2eyghrwfo4ktqh UNIQUE (codempresa))// NAO CRIAR
Problem is that the constraints UNIQUE (codusuario) and UNIQUE (codempresa) are being created. The constraint I wanted to create was only so that the three columns would not repeat themselves and the Foreign. Even putting "unique = false" the mentioned constraints were created.
Update
The PK Authentication class:
public class AutenticacaoPK implements Serializable {
private static final long serialVersionUID = 6769917015564615074L;
protected Usuario usuario;
protected Empresa empresa;
protected String token;
public AutenticacaoPK(Usuario usuario, Empresa empresa, String token) {
this.empresa = empresa;
this.token = token;
this.usuario = usuario;
}
AutenticacaoPK() {}
}