Ich bin neu mit PostGIS, und ich benutze PostGIS mit Hibernate Spatial und Spring-Framework. Das Problem ist, dass der Primärschlüssel nicht automatisch gesetzt, und ich erhalte die folgende Fehlermeldung, wenn Daten in die DB einfügen:Hibernate Spatial und PostGIS Primärschlüssel Ausgabe
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.hibernate.exception.ConstraintViolationException: ERROR: null value in column "id" violates not-null constraint
Detail: Failing row contains (null,name , country).
Ich habe den Code auf MySQL getestet und es funktioniert einwandfrei. Wenn ich Hibernate Spatial und PostGIS benutze, bekomme ich den erwähnten Fehler. Hier ist das Modell:
@Entity
@Table(name="person")
public class Person {
@Id
@Column(name="id")
@GeneratedValue(strategy=GenerationType.IDENTITY)
private int id;
private String name;
private String country;
...
}
Hier wird der Code zum Einfügen der Daten:
public void addPerson(Person p) {
Session session = this.sessionFactory.getCurrentSession();
session.persist(p);
}
Und hier sind die Abhängigkeiten in Maven:
postgis-jdbc: 1.5.2
postgresql: 8.4-702.jdbc3
hibernate-entitymanager: 4.0.0.Final
hibernate-core: 4.0.0.Final
hibernate-spatial: 4.0
commons-dbcp: 1.4
spring version: 4.0.3.RELEASE
und Hibernate Konfigurationen:
<beans:bean id="hibernate4AnnotatedSessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<beans:property name="dataSource" ref="dataSource" />
<beans:property name="annotatedClasses">
<beans:list>
<beans:value>it.polimi.thesis.model.Person</beans:value>
</beans:list>
</beans:property>
<beans:property name="hibernateProperties">
<beans:props>
<beans:prop key="hibernate.dialect">org.hibernate.spatial.dialect.postgis.PostgisDialect
</beans:prop>
<beans:prop key="hibernate.show_sql">true</beans:prop>
<beans:prop key="hibernate.ddl-auto">update</beans:prop>
</beans:props>
</beans:property>
</beans:bean>
Ich wollte Ich schätze jede Hilfe. Bitte lassen Sie mich wissen, wenn zusätzliche Informationen benötigt werden.