Hi,
I m working on an application that inserts, display, edit and delete records("kunden"). Now i m trying to get it work with hibernate JPA, displaying, editing and deleting records works well but i have problem with inserting. I am getting following error when i use insert function:
...org.postgresql.util.PSQLException: ERROR: relation "hibernate_sequences" does not exist
Position: 36....
... javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: error performing isolated work...
my source files:
kunde.java:
Code:
package tutorial;
import javax.persistence.*;
@Entity
@Table(name = "kunden")
public class Kunde {
@Id
@GeneratedValue(strategy=GenerationType.TABLE)
private int id;
@Column(name = "kunden_name")
private String name;
@Column(name = "kunden_nr")
private Integer number;
@Column(name = "aktiv")
private Boolean aktiv;
public Kunde(){
}
public Kunde(int id, Integer number, String name, boolean aktiv){
this.id = id;
this.name = name;
this.number = number;
this.aktiv=aktiv;
}
public Kunde( Integer number, String name, boolean aktiv){
this.name = name;
this.number = number;
this.aktiv=aktiv;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getNumber() {
return number;
}
public void setNumber(Integer number) {
this.number = number;
}
public boolean getAktiv(){
return aktiv;
}
public void setAktiv(boolean aktiv) {
this.aktiv = aktiv;
}
}
persistence.xml
Code:
<persistence 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"
version="1.0">
<persistence-unit name="kunden">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.connection.driver_class"
value="org.postgresql.Driver" />
<property name="hibernate.connection.url"
value="***" />
<property name="hibernate.connection.username"
value="****" />
<property name="hibernate.connection.password"
value="****" />
<property name="show_sql" value="true"/>
<property name="hbm2ddl.auto" value="create"/>
</properties>
</persistence-unit>
</persistence>
function to insert new record:
Code:
public void addKunde(Integer number, String name){
EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("kunden");
EntityManager entityManager = entityManagerFactory.createEntityManager();
entityManager.getTransaction().begin();
Kunde kundeInsert = new Kunde(number, name, true);
entityManager.persist(kundeInsert);
entityManager.getTransaction().commit();
entityManager.close();
kundeList.add(kundeInsert);}
Any1 knows where could be a problem? Thx for answers.