-->
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.  [ 8 posts ] 
Author Message
 Post subject: Where to define the sequence to be used on generator class?
PostPosted: Tue Oct 11, 2005 10:46 am 
Beginner
Beginner

Joined: Thu Aug 04, 2005 2:24 pm
Posts: 45
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Before Hibernate, i was used to having a PK attached to a sequence by a trigger (Oracle). This way i never had to deal with my PKs generation.

But now Hibernate has this "generator" thing. I understand that if i use "assigned" i will have to deal with the PK generation on the application end.

Now there's this "sequence" as the generator, but i can't find the tag to define the sequence's name (<seqname>somesequence</seqname>). Is it automatically created by Hibernate on the database?

Thanks

_________________
Eduardo Mylonas


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 11, 2005 10:53 am 
Regular
Regular

Joined: Fri Sep 17, 2004 10:51 am
Posts: 61
Location: Rimini, Italy
No, the sequence must be created on the db. I suggest to disable the trigger then, or the id generated by hibernate will be replaced by the one from the trigger

_________________
--
Marco


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 11, 2005 12:45 pm 
Beginner
Beginner

Joined: Thu Aug 04, 2005 2:24 pm
Posts: 45
But if the sequence has to be created on the db, which i thought it had to, how does hibernate know the sequence to be used if i don't have the tag?

This is what i have:
<id name="assemblyNum" type="long">
<column name="ASSEMBLY_NUM" precision="10" scale="0"/>
<generator class="sequence"/>
</id>

I couldn't find a way to place the sequence name yet...

Thanks a lot

_________________
Eduardo Mylonas


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 11, 2005 1:58 pm 
Newbie

Joined: Wed Sep 14, 2005 9:15 am
Posts: 12
Location: St. Louis
In Oracle, can you set the Primary Key field to auto-incrment? I use this option in MySQL and then use the following in my hbm doc:

Code:
<generator class="select"/>


Hibernate then automatically receives the next ID from the database upon record insert.

You might be able to keep your trigger in place and simply use the "select" option... Haven't tried this yet in Oracle, so I can't be sure...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 11, 2005 2:33 pm 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
Code:
    <id
        name="intSeqNo"
        type="java.lang.Integer"
        column="int_seq_no"
    >
        <generator class="native">
            <param name="sequence">name_of_db_sequence_goes_here</param>
        </generator>
    </id>


I think this is what you're looking for

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 11, 2005 2:46 pm 
Beginner
Beginner

Joined: Thu Aug 04, 2005 2:24 pm
Posts: 45
matthewramella wrote:
In Oracle, can you set the Primary Key field to auto-incrment? I use this option in MySQL and then use the following in my hbm doc:

Code:
<generator class="select"/>


Hibernate then automatically receives the next ID from the database upon record insert.

You might be able to keep your trigger in place and simply use the "select" option... Haven't tried this yet in Oracle, so I can't be sure...


Well, Oracle doesn't support auto-increment, which sucks...

But thanks for the tip...

_________________
Eduardo Mylonas


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 11, 2005 2:48 pm 
Beginner
Beginner

Joined: Thu Aug 04, 2005 2:24 pm
Posts: 45
kochcp wrote:
Code:
    <id
        name="intSeqNo"
        type="java.lang.Integer"
        column="int_seq_no"
    >
        <generator class="native">
            <param name="sequence">name_of_db_sequence_goes_here</param>
        </generator>
    </id>


I think this is what you're looking for


Hummm... this looks good!!!

I understand 'native' uses 'identity', 'sequence' or 'hilo' depending on the underlying database... so i figure that if i have this setting, but instead of Oracle i try to connect to SQL Server, for example, it hibernate will pick up the identity fields automatically...?

Thanks a whole lot (Y)

_________________
Eduardo Mylonas


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 11, 2005 2:58 pm 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
Quote:
but instead of Oracle i try to connect to SQL Server, for example, it hibernate will pick up the identity fields automatically


yep. this works on all three of my test databses: sql server, oracle, and for some reason we are still testing on db2

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


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