Hello, I wanted to make a foreign key, but I do not understand the syntax.
In the Address class:
@Embeddable
@Table(name = "tab_endereco")
public class Endereco {
@Column(length = 40, nullable = false)
private String logradouro;
@Column(length = 40, nullable = false)
private String bairro;
@JoinColumn(columnDefinition = "char(3)", nullable = false, foreignKey = @ForeignKey(name="fk_cidade"))
private Cidade cidade;
In the City class, where you paste the acronym:
@Entity
@Table(name = "tab_cidade")
public class Cidade {
@Id
@JoinColumn(columnDefinition = "char(3)", nullable = false, referencedColumnName = "fk_cidade")
private String sigla;
@Column(length = 40, nullable = false)
private String nome;
@Column(columnDefinition = "char(2)", nullable = false)
private Estado estado;