Announcement Announcement Module
Collapse
No announcement yet.
Not saving in an Oracle Data Base Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Not saving in an Oracle Data Base

    Hi,
    i have a Spring application with Hibernate data access configuration.
    Everything works well with my spring-hibernate configuration i can read objects execute querys, but the problem is when i try to persist an object.
    If i use the persist() method of HibernateTemplate i get the following exception:
    javax.faces.el.EvaluationException: org.springframework.dao.InvalidDataAccessApiUsageE xception: detached entity passed to persist: null; nested exception is org.hibernate.PersistentObjectException: detached entity passed to persist: null

    and if i use the save() method of HibernateTemplate i get:
    javax.faces.el.EvaluationException: org.springframework.jdbc.BadSqlGrammarException: Hibernate operation: could not get next sequence value; bad SQL grammar [select hibernate_sequence.nextval from dual]; nested exception is java.sql.SQLException: ORA-02289: sequence does not exist

    This is my mapped-class configuration:
    <hibernate-mapping package="springBeans">
    <class name="StudentImpl" table="Student" optimistic-lock="none">
    <id name="id" type="integer" unsaved-value="null" column="id">
    <generator class="native"/>
    </id>
    <property name="name" type="string" column="name"/>
    <property name="direccion" type="string" column="direccion"/>
    <property name="edad" type="integer" column="edad"/>
    </class>
    </hibernate-mapping>

    This is the StudentImpl class:
    package springBeans;

    public class StudentImpl implements Student {

    private int id;
    private String name;
    private String direccion;
    private int edad;

    public StudentImpl() {
    }

    public void setName(String aname) {
    this.name = aname;
    }
    public String getName() {
    return this.name;
    }
    public void setDireccion(String adireccion) {
    this.direccion = adireccion;
    }
    public String getDireccion() {
    return this.direccion;
    }
    public void setEdad(int aedad) {
    this.edad = aedad;
    }
    public int getEdad() {
    return this.edad;
    }
    public int getId() {
    return id;
    }
    public void setId(int id) {
    this.id = id;
    }

    }

    Please help me.

  • #2
    Well the errormessage says all I guess.

    javax.faces.el.EvaluationException: org.springframework.jdbc.BadSqlGrammarException: Hibernate operation: could not get next sequence value; bad SQL grammar [select hibernate_sequence.nextval from dual]; nested exception is java.sql.SQLException: ORA-02289: sequence does not exist
    Code:
    <id name="id" type="integer" unsaved-value="null" column="id">
        <generator class="native"/>
    </id>
    That comes from your mapping file. The native generator class maps to a sequence in Oracle. Either create the sequence (don't know the base name which it used but I guess it is in the hibernate docs) or switch to another generator.

    Comment


    • #3
      I change from native to assigned, and now it don't get any exception but , the object is not persisted in the data base.

      What is it happening?

      Comment


      • #4
        Is there a commit being send to the database? If not make sure you have your transaction management setup right.

        Comment


        • #5
          Did you also assign a value to the id attribute prior to saving?

          Regards,
          Andreas

          Comment


          • #6
            HibernateTemplate don't have a conmit() method i can use, and yes, i set the id attr beford save the object.

            I don't know what i'm missing...

            Comment


            • #7
              Well you need to start a transaction and commit or rollback when an error occurs.

              Code:
                  public void storeFoo(Foo foo) {
                      Transaction transaction = getSessionFactory().getCurrentSession().beginTransaction();
                      getHibernateTemplate().saveOrUpdate(foo);
                      transaction.commit();
                  }
              However it is possible to manage transactions manually (as seen above) I would suggest you look into declarative transaction management. Check the Spring reference guide for information about this.

              Comment


              • #8
                Oh, everything works ok, the problem was that i was missing one jar, the
                commons-pool.jar, i include it and everything works well.

                Thank you very much.

                Comment

                Working...
                X