-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: problem with inserting records into DB
PostPosted: Mon Jun 03, 2013 7:30 am 
Newbie

Joined: Mon Jun 03, 2013 7:11 am
Posts: 2
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.


Top
 Profile  
 
 Post subject: Re: problem with inserting records into DB
PostPosted: Tue Jun 04, 2013 4:10 am 
Newbie

Joined: Mon Jun 03, 2013 7:11 am
Posts: 2
i just solved it by changing to "@GeneratedValue(strategy=GenerationType.IDENTITY) " in kunde.java


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.