-->
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.  [ 3 posts ] 
Author Message
 Post subject: assigned primary key with the sequence generator
PostPosted: Mon Nov 01, 2004 10:36 am 
Beginner
Beginner

Joined: Thu Aug 26, 2004 5:53 am
Posts: 37
I am using the sequence generator class.

I need to import data from an old database, during a migration phase, and I need to keep the primary keys the same on some tables.

I would like to not have to change the mappings from

generator class="sequence"
to
generator class="assigned"

to perform the migration.

I have tried setting the primary key column to the value that I wish to assign, and calling Session.save(), though the sequence generator is still used.

Is there an out of the box soloution for this ?

Could I use modified sequence generator that checks for an assigned pk ?

Thanks.

Cameron


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 01, 2004 10:38 am 
Beginner
Beginner

Joined: Thu Aug 26, 2004 5:53 am
Posts: 37
just to clarif, when I said

Quote:
I have tried setting the primary key column to the value that I wish to assign


I meant

Quote:
I have tried setting the primary key property to the value that I wish to assign


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 01, 2004 10:58 am 
Beginner
Beginner

Joined: Thu Aug 26, 2004 5:53 am
Posts: 37
I thikn I created a soloution.

I subclassed net.sf.hibernate.id.SequenceGenerator and overwrote :

Code:
    public Serializable generate(SessionImplementor session, Object object) throws SQLException, HibernateException {
        Serializable identifier = session.getSessionFactory().getClassMetadata(object.getClass()).getIdentifier(object);
        if (identifier != null) {
            return identifier;
        } else {
            return super.generate(session, object);
        }
    }


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