-->
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.  [ 7 posts ] 
Author Message
 Post subject: Hibernate and Oracle sequence
PostPosted: Mon Jan 31, 2005 7:42 pm 
Regular
Regular

Joined: Sat May 15, 2004 4:27 am
Posts: 79
Hi all,

i was working with a MySQL Server, and finally we have to use Oracle 9i. After some searches on
google, i noticed Oracle doesn't support the 'auto_increment' of MySQL. Instead of that, i need to use
sequence ? Who know how using Oracle sequence with Hibernate ? Do i have to create trigger for
generating the number on my oracle server or hibernate can do that ? I have no idea about that issue !


Top
 Profile  
 
 Post subject: using oracle sequence
PostPosted: Mon Jan 31, 2005 7:49 pm 
Newbie

Joined: Thu Dec 30, 2004 6:58 pm
Posts: 6
Its really easy to use an oracle sequence with Hibernate. Just create the sequence and use the "sequence" generator type/class in your mapping. For example, we've created a sequence called ENTERPRISE_SEQ. We then use it like this:
Code:
<!-- id property. -->
<id name="itemId"
      type="long"
      column="ITEM_ID">
            <generator class="sequence">
                <param name="sequence">ENTERPRISE_SEQ</param>
            </generator>
</id>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 31, 2005 10:20 pm 
Newbie

Joined: Wed Dec 08, 2004 8:56 am
Posts: 12
Location: China ChengDu
Hi smayemba:
You could create a sequence named"HIBERNATE_SEQUENCE" on your Oracle.

Code:
      <id
         column="ID"
         name="Id"
         type="integer"
      >
         <generator class="native" />
      </id>


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 01, 2005 2:19 am 
Regular
Regular

Joined: Sat May 15, 2004 4:27 am
Posts: 79
I am going to try your solutions. Thank you Guys


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 01, 2005 7:50 am 
Contributor
Contributor

Joined: Thu Nov 06, 2003 9:49 pm
Posts: 104
Location: New York, NY
If you still want to retain compatibility with 'auto-increment' databases such as HSQLDB, SQLServer and MySQL, the "native" id generator is best. This also accepts the 'sequence' parameter if you want to name a specific ORACLE sequence. This is ignored when using a database that supports 'auto-increment' columns.

Code:
            <generator class="native">
                <param name="sequence">MY_SPECIAL_SEQUENCE</param>
            </generator>


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 04, 2005 5:27 pm 
Regular
Regular

Joined: Tue Jan 11, 2005 8:55 pm
Posts: 53
joshua wrote:
If you still want to retain compatibility with 'auto-increment' databases such as HSQLDB, SQLServer and MySQL, the "native" id generator is best. This also accepts the 'sequence' parameter if you want to name a specific ORACLE sequence. This is ignored when using a database that supports 'auto-increment' columns.

Code:
            <generator class="native">
                <param name="sequence">MY_SPECIAL_SEQUENCE</param>
            </generator>


Hi Joshua, and others,

I've been searching around on the forum for solution to a similar problem, but this is the only related post I have found. I am hoping you can help me out.

I am attempting to use generator-class = sequence with Oracle 9 DB, and I continue to obtain errors:

Code:
     [java] net.sf.hibernate.MappingException: could not instantiate id generator
     [java] at net.sf.hibernate.id.IdentifierGeneratorFactory.create(IdentifierGeneratorFactory.java:82)
     [java] at net.sf.hibernate.mapping.SimpleValue.createIdentifierGenerator(SimpleValue.java:82)
     [java] at net.sf.hibernate.cfg.Configuration.iterateGenerators(Configuration.java:434)
     [java] at net.sf.hibernate.cfg.Configuration.generateDropSchemaScript(Configuration.java:493)
     [java] at net.sf.hibernate.tool.hbm2ddl.SchemaExport.<init>(SchemaExport.java:58)
     [java] at net.sf.hibernate.tool.hbm2ddl.SchemaExport.<init>(SchemaExport.java:48)
     [java] at net.sf.hibernate.tool.hbm2ddl.SchemaExport.main(SchemaExport.java:303)
     [java] Caused by: java.lang.ClassNotFoundException:
     [java] at java.lang.Class.forName0(Native Method)
     [java] at java.lang.Class.forName(Unknown Source)
     [java] at net.sf.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:102)
     [java] at net.sf.hibernate.id.IdentifierGeneratorFactory.create(IdentifierGeneratorFactory.java:76)


I've tried various parameter settings, but I continue to get this error. Any guidance would be appreciated.

Thanks..!


Top
 Profile  
 
 Post subject: Re: Hibernate and Oracle sequence
PostPosted: Mon Jul 13, 2009 6:40 am 
Newbie

Joined: Sun Feb 25, 2007 5:02 am
Posts: 5
I have a question, should the trigger that gets and puts next value from sequence to "auto increment field" be compatible with hibernate, the trigger also checks if it was inserted as null or with value.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.