-->
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: Oracle Sequence mit auto_increment
PostPosted: Tue May 24, 2005 7:34 am 
Beginner
Beginner

Joined: Fri May 21, 2004 3:49 pm
Posts: 21
Location: Germany, Mainz
Hi,
also ich habe im Prinzip ein ganz einfaches Problem, weiß jedoch nicht wo in Hibernate ich suchen muss, damit ich den vermeindlichen Fehler finden muss. Ich habe eine Sequenz für auto_increment erstellt in Oracle, diese funktioniert auch Fehlerfrei, sobald ich sie aber von Oracle ausführen lassen, erstellt er die ID falsch, sprich die ID, in sparePart.getSPID() = 47 in der Datenbank diejenige aber 48. Also immer +1.
Jemand eine Ahnung woran das liegt?

Hibernate version: 3

Mapping file: <?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<!--
Auto-generated mapping file from
the hibernate.org cfg2hbm engine
-->
<class name="itecon.bo.model.Sparepart" table="SPAREPART" schema="DELL">
<id name="Spid" type="java.lang.Long">
<column name="SPID" scale="22" precision="0" not-null="true" unique="true" sql-type="NUMBER" />
<generator class="sequence">
<param name="sequence">AINCREMENT</param>
</generator>
</id>
<property name="Spname" type="java.lang.String">
<column name="SPNAME" scale="100" precision="0" not-null="true" sql-type="VARCHAR2" />
</property>
<property name="Spinventory" type="java.lang.Integer">
<column name="SPINVENTORY" scale="22" precision="0" not-null="true" sql-type="NUMBER" />
</property>
</class>
</hibernate-mapping>


Databaseversion: Oracle 10g

The generated SQL (show_sql=true):
select AINCREMENT.nextval from dual
Hibernate: select AINCREMENT.nextval from dua

insert into DELL.SPAREPART (SPNAME, SPINVENTORY, SPID) values (?, ?, ?)
Hibernate: insert into DELL.SPAREPART (SPNAME, SPINVENTORY, SPID) values (?, ?, ?)l



Sequence:
Create sequence aincrement start with 1 increment by 1 nomaxvalue;

CREATE OR REPLACE TRIGGER "DELL"."INCREMENT_SPID" BEFORE
INSERT ON "DELL"."SPAREPART" REFERENCING OLD AS OLD NEW AS NEW FOR EACH ROW Begin
select AINCREMENT.nextval into :NEW.SPID from DUAL;
End;


DAOTest:
Code:
/**
*   17.05.2005
*   16:46:00
*    johannes.hiemer
*     SparepartDAOTest.java
*/
package itecon.dao.hibernate.test;

import java.util.List;

import itecon.bo.dao.ISparepartDAO;
import itecon.bo.model.Sparepart;
import junit.awtui.TestRunner;

import org.apache.log4j.Logger;

/**
* @author johannes.hiemer
*
* ITecon Dell Call System
*/
public class SparepartDAOTest extends BaseDAOTestCase {

    private ISparepartDAO sparePartDAO = null;
    private Sparepart sparePart = null;
   
    protected void setUp() throws Exception {
        log = Logger.getLogger(SparepartDAOTest.class.getName());
        sparePartDAO = (ISparepartDAO) ctx.getBean("sparepartDAO");
    }
   
    protected void tearDown() throws Exception {
        sparePartDAO = null;
    }
   
    public static void main(String args []) {
        TestRunner.run(SparepartDAOTest.class);
    }
   
    public Sparepart createSparepart() {
        sparePart = new Sparepart();
        sparePart.setSpinventory(new Integer(2));
        sparePart.setSpname("TX-45359A34");
       
        return sparePart;
    }
   
    public void testAddAndRemoveSparepart() throws Exception {
        createSparepart();
        log.info(sparePart.getSpid());

        sparePartDAO.saveSparepart(sparePart);
       
        List spareList = sparePartDAO.getSpareparts();
        log.info(spareList.get(0).toString());
       
       
        assertTrue("primary key assigned", sparePart.getSpid() != null);
        log.info(sparePart.getSpid());
        assertTrue(sparePart.getSpname() != null);
       
        sparePartDAO.removeSparepart(sparePart.getSpid()+1);
       
        assertTrue("primary key not assigned", sparePart.getSpid() != null);
    }

    /**
     * @return Returns the sparePart.
     */
    public Sparepart getSparePart() {
        return sparePart;
    }
   
   

}


Gruß Valentin-


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 24, 2005 8:57 am 
Beginner
Beginner

Joined: Fri May 21, 2004 3:49 pm
Posts: 21
Location: Germany, Mainz
Thema kann geschlossen werden habe das Problem gelöst.

Wer eine Problembeschreibung und Lösung sucht dem wird hier geholfen:
http://forum.hibernate.org/viewtopic.ph ... ice+oracle

Ich hatte zwar schon zuvor die Suchfunktion benutzt aber leider scheinbar nicht genau hingeschaut.
Deswegen entschuldige ich mich in aller Form.

Gruß Valentin-


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.