I am working on a new project with postgreSQL 13 and the auto generation of the data schema does not work. My approach is to use annotations on my entities as I always did before.
Here is one of my entities and my persistence.xml file:
@Entity
public class User implements Serializable {
@OneToOne
private Agent agent;
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long idUser;
private ProfilUser profilUser;
private LocalDate dateCreation;
private LocalDate dateActivation;
private LocalDate date_desactivation;
private LocalDate date_premiereConnexion;
@ManyToMany
private List <ProfilUser> userProfils;
public Long getId() {
return idUser;
}
public void setId(Long id) {
this.idUser = id;
}
@Override
public int hashCode() {
int hash = 0;
hash += (idUser != null ? idUser.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the idUser fields are not set
if (!(object instanceof User)) {
return false;
}
User other = (User) object;
if ((this.idUser == null && other.idUser != null) || (this.idUser != null && !this.idUser.equals(other.idUser))) {
return false;
}
return true;
}
@Override
public String toString() {
return "com.weyetech.gestionstock.entities.User[ id=" + idUser + " ]";
}
public LocalDate getDateCreation() {
return dateCreation;
}
public void setDateCreation(LocalDate dateCreation) {
this.dateCreation = dateCreation;
}
public LocalDate getDateActivation() {
return dateActivation;
}
public void setDateActivation(LocalDate dateActivation) {
this.dateActivation = dateActivation;
}
public LocalDate getDate_desactivation() {
return date_desactivation;
}
public void setDate_desactivation(LocalDate date_desactivation) {
this.date_desactivation = date_desactivation;
}
public LocalDate getDate_premiereConnexion() {
return date_premiereConnexion;
}
public void setDate_premiereConnexion(LocalDate date_premiereConnexion) {
this.date_premiereConnexion = date_premiereConnexion;
}
public Long getIdUser() {
return idUser;
}
public void setIdUser(Long idUser) {
this.idUser = idUser;
}
public ProfilUser getProfilUser() {
return profilUser;
}
public void setProfilUser(ProfilUser profilUser) {
this.profilUser = profilUser;
}
public List<ProfilUser> getUserProfils() {
return userProfils;
}
public void setUserProfils(List<ProfilUser> userProfils) {
this.userProfils = userProfils;
}
}
My persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.2" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_2.xsd">
<!-- Define Persistence Unit -->
<persistence-unit name="g_stock" transaction-type="JTA">
... <!-- Entities -->
<properties>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.format_sql" value="true"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
<property name="javax.persistence.schema-generation.database.action" value="create"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQL95Dialect"/>
</properties>
</persistence-unit>
</persistence>
I tried to change the dialect of postgre to 10 (since it is the dialect of version 10 and later) but without success.