[Postgres] La colonne n'existe pas
bonjour,
j'essaye d'utiliser hibernate avec PostGres sous netBeans. je rencontre ce problème au moment d'exécuter ma requete
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
| Caused by: org.postgresql.util.PSQLException: ERREUR: la colonne niveau0_.id n'existe pas
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:1592)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1327)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:192)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:451)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:350)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:254)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1787)
at org.hibernate.loader.Loader.doQuery(Loader.java:674)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.doList(Loader.java:2220)
... 20 more |
Postgres à l'air tres sensible au niveau de la casse beaucoup plus que SqlServer(j'avais fait des essai sous sqlServer ça marchait tres bien)
Ce que je ne comprend pas c'est d'où sort le niveau0_.id Qu'est ce que c'est que ce _0. Doit on spécifier quelque chose au niveau des fichiers de config pour qu'il prenne le bon nom ?
J'ai essayé de faire une autre requête sur une table différente et j'ai la même erreur.
Mon fichier cfg.hibernate.xml
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/carnet</property>
<property name="hibernate.connection.username">postgres</property>
<property name="hibernate.connection.password">XXXXXX</property>
<property name="hibernate.show_sql">true</property>
</session-factory>
</hibernate-configuration> |
mon fichier persistence.xml
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="CarnetPU" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>carnet.entities.Seance</class>
<class>carnet.entities.Niveau</class>
<class>carnet.entities.Serie</class>
<class>carnet.entities.Programme</class>
<class>carnet.entities.Exercice</class>
<class>carnet.entities.Objectif</class>
<properties>
<property name="hibernate.connection.username" value="postgres"/>
<property name="hibernate.connection.driver_class" value="org.postgresql.Driver"/>
<property name="hibernate.connection.password" value="XXXXXXX"/>
<property name="hibernate.connection.url" value="jdbc:postgresql://localhost:5432/carnet"/>
</properties>
</persistence-unit>
</persistence> |
Ma classe Niveau
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
|
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package carnet.entities;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;
/**
*
* @author seb
*/
@Entity
@Table(name = "niveau" , catalog = "carnet", schema = "carnet")
@NamedQueries({@NamedQuery(name = "Niveau.findAll", query = "SELECT n FROM Niveau n"), @NamedQuery(name = "Niveau.findById", query = "SELECT n FROM Niveau n WHERE n.id = :id"), @NamedQuery(name = "Niveau.findByDescription", query = "SELECT n FROM Niveau n WHERE n.description = :description")})
public class Niveau implements Serializable {
@Transient
private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
private static final long serialVersionUID = 1L;
@Id
@Basic(optional = false)
@Column(name = "ID")
private String id;
@Column(name = "DESCRIPTION")
private String description;
@OneToMany(mappedBy = "idNiveau", fetch = FetchType.LAZY)
private List<Seance> seanceList;
public Niveau() {
}
public Niveau(String id) {
this.id = id;
}
public String getId() {
return id;
}
public void setId(String id) {
String oldId = this.id;
this.id = id;
changeSupport.firePropertyChange("id", oldId, id);
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
String oldDescription = this.description;
this.description = description;
changeSupport.firePropertyChange("description", oldDescription, description);
}
public List<Seance> getSeanceList() {
return seanceList;
}
public void setSeanceList(List<Seance> seanceList) {
this.seanceList = seanceList;
}
@Override
public int hashCode() {
int hash = 0;
hash += (id != null ? id.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof Niveau)) {
return false;
}
Niveau other = (Niveau) object;
if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
return false;
}
return true;
}
@Override
public String toString() {
return "carnet.entities.Niveau[id=" + id + "]";
}
public void addPropertyChangeListener(PropertyChangeListener listener) {
changeSupport.addPropertyChangeListener(listener);
}
public void removePropertyChangeListener(PropertyChangeListener listener) {
changeSupport.removePropertyChangeListener(listener);
}
} |