Announcement Announcement Module
Collapse
No announcement yet.
Problem saving Objects using Hibernate and PostgreSQL Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem saving Objects using Hibernate and PostgreSQL

    hello togehter,

    i've got a problem saving objects via Hibernate in a PostgreSQL database. The problem is located in the sequence-generation for the object-id.

    saving the customer-object gives following exception:
    nested exception is net.sf.hibernate.HibernateException: identifier of an instance of Customer altered from 1 to 1

    the mapping-file defines the following:
    Code:
    <class 
        name="com.mbee.ivs.business.Customer" 
        table="CUSTOMER">
    	
        <id
            name="customerID"
            type="java.lang.Integer"
            column="CUSTOMER_ID">
            	<generator class="sequence">
    				<param name="sequence">customer_id_seq</param>
    			</generator>
        </id>
    </class>
    the save-procedure is called by:
    Code:
    getHibernateTemplate&#40;&#41;.save&#40;customer&#41;;
    the same thing worked well with HSQLDB and hibernate-generator from type native... switching to postgreSQL and sequence-generator makes problems...

    i tried out implizit and explizit seqences in postgreSQL but the problem stays...

    any suggestions?
    greetz, sebastian

  • #2
    I would begin by setting Hibernate to show SQL. Set the hibernate.show_sql property to true.

    Does it look like the PostgreSQL sequence is correctly invoked? Try selecting the next value using SQL...

    Comment


    • #3
      yes, it looks quite right, what postgresql does...

      hibernate gives the message:
      Hibernate: select nextval ('customer_id_seq')

      followed by the error-message mentioned above...

      the values delivered by postgres are right, too... each time i try to save a object postgres increments right, telling me that e.g. the value 6 has been altered to 6... funny, isen't it... 6 is 6 and thats okay for me, so why hibernate tells me, that the value has been altered to the same value?

      Comment

      Working...
      X