They ask me to do this mapping with JPA (what is marked in red is for a plus question) :D :
So I did this:
CENTRAL MANAGEMENT
@Entity
@Table(name = "gerencia_central")
public class GerenciaCentral implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name = "id_gerencia_c")
private int gerenciaCenId;
@Column(name = "codigo_gerencia_c_propio")
private String codigoPropio;
@Column(name = "descripcion_gerencia_c")
private String descripcion;
@Column(name = "descripcion_corta_gerencia_c")
private String descripcionCorta;
@Column(name = "estado_gerencia_c")
private String estado;
@OneToMany(mappedBy = "gerenciaCen", cascade = { CascadeType.ALL }, fetch = FetchType.LAZY, orphanRemoval = true)
private List<Gerencia> listaGerencia;
MANAGEMENT
@Entity
@Table(name = "gerencia")
public class Gerencia implements Serializable {
private static final long serialVersionUID = 1L;
@EmbeddedId
private GerenciaPK pk;
@ManyToOne
@JoinColumn(name = "id_gerencia_c", referencedColumnName = "id_gerencia_c", nullable = false, insertable = false, updatable = false)
private GerenciaCentral gerenciaCen;
@Column(name = "codigo_gerencia_propio", length = 4)
private String codigoPropio;
@Column(name = "descripcion_gerencia", length = 80)
private String descripcion;
@Column(name = "descripcion_corta_gerencia", length = 40)
private String descripcionCorta;
@Column(name = "estado_gerencia", length = 1)
private String estado;
@OneToMany(mappedBy = "gerencia", cascade = { CascadeType.ALL }, fetch = FetchType.LAZY, orphanRemoval = true)
private List<AreaFuncional> listaAreafunc;
And the MANAGEMENT key
@Embeddable
public class GerenciaPK implements Serializable {
private static final long serialVersionUID = 1L;
@Column(name = "id_gerencia_c")
private int gerenciaCenId;
@Column(name = "id_gerencia")
private int gerenciaId;
Needless to say, everyone has their Get and Set and Equals and Hash Code. Although for the case I think none of that matters. Continuing...
When executing the project, it creates the tables but not the relationships.
Very well. It is possible that I did something wrong when generating the schema. That's why I also checked by other means.
And even generating the Script of the DB
CREATE TABLE `gerencia` (
`id_gerencia_c` int(11) NOT NULL,
`id_gerencia` int(11) NOT NULL,
`codigo_gerencia_propio` varchar(4) DEFAULT NULL,
`descripcion_gerencia` varchar(80) DEFAULT NULL,
`descripcion_corta_gerencia` varchar(40) DEFAULT NULL,
`estado_gerencia` varchar(1) DEFAULT NULL,
PRIMARY KEY (`id_gerencia_c`,`id_gerencia`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
I would like to know what is wrong. I do not necessarily ask what I have done wrong but anything else that is wrong. Until what they gave me to do.
QUESTION PLUS In the first image you see that I highlight a box in red. There they tell me to be an integer but 4 digits. Since the first ID must be "0001" I changed the integer to a string. And the autoincrement is already on my own. But I would like to know if there is a way to indicate all this to Hibernate so that it saves a number with leading zeros. Thanks.
This might help you, add
In CENTRAL MANAGEMENT:
in MANAGEMENT