2
Using the class:
@Entity
public class Pessoa{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long idPessoa;
@Column(nullable=false, unique = true)
private String nome;
@OneToOne
@JoinColumn(name = "idPais", nullable = true)
private Pais pais;
public Pessoa(){}
// Getters and Setters
}
In the bank is generated
CONSTRAINT fk_8pxwdacx0r81ra9d59m6erkri FOREIGN KEY (idpais)
CONSTRAINT uk_4tdehxj7dh8ghfc68kbwbsbll UNIQUE (nome)
How to name, rather than come fk_8pxwdacx0r81ra9d59m6erkri
, name as Pais_Pessoa
and uk_4tdehxj7dh8ghfc68kbwbsbll
, name as unique_nome
.
Is this possible in JPA/Hibernate? If so, how?
Just to finish(an extra question), in case I want to assign a different name to each uniqueConstraint can do so
@Table(uniqueConstraints = @UniqueConstraint(columnNames = {"nome", "email"}, name = {"unique_nome", "unique_email"}))
? Or do I have to create another Annotation? And how do I also put conditions?– Tiago Ferezin
In case you can create an array of uniqueConstraints, it would look like this:
@Table(name="table", uniqueConstraints={
 @UniqueConstraint(columnNames="nome," name="unique_nome", ),
 @UniqueConstraint(columnNames="email", name="unique_email")
})
– Jhonny Roger Virgilio da Silva
Thank you was very helpful
– Tiago Ferezin