-->
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: Transfer entities between to database. Id generator problem.
PostPosted: Wed Mar 09, 2011 9:25 am 
Newbie

Joined: Thu Oct 28, 2010 8:38 am
Posts: 4
Location: Ukraine
Bonjour,

I have DBF database.
I have Hibernate database model with xml-files of mapping, with identity generators.
And now i need to transfer data from dbf-table using Hibernate.
But the problem is that I don't need auto-generated ID's. they should be the same as in DBF records.

I think about 2 solutions:
1. Create complex id-generator, that can generate id or can use preset id.
2. Create record in database with generated ID, and than update ID field to needed.

What do you think????

Merci beaucoup.


Top
 Profile  
 
 Post subject: Re: Transfer entities between to database. Id generator problem.
PostPosted: Wed Mar 09, 2011 10:33 am 
Newbie

Joined: Thu Oct 28, 2010 8:38 am
Posts: 4
Location: Ukraine
I find solution by modifying IdentityGenerator generator:

public class Generator extends IdentityGenerator
{

@Override
public Serializable generate(SessionImplementor sessionImplemetor, Object object) throws HibernateException
{
Serializable id = sessionImplemetor.getEntityPersister( EmployeeCategory.class.getName(), object ).getIdentifier( object, sessionImplemetor );

if(id==null)
return IdentifierGeneratorHelper.POST_INSERT_INDICATOR;

return id;
}

}

For entities, that have id not null it return id-value, installed by user,
For entities, that have id==null it generate id-value.


Top
 Profile  
 
 Post subject: Re: Transfer entities between to database. Id generator problem.
PostPosted: Tue May 15, 2012 9:59 am 
Newbie

Joined: Tue May 15, 2012 9:43 am
Posts: 3
Hi,

I am facing the same problem.and tried your solution.
But dint get the desired output.

Code:
public class CustomIdGenerator implements IdentifierGenerator
{

   @Override
   public Serializable generate(SessionImplementor sessionImplementor, Object object) throws HibernateException
   {
      try
      {
      System.out.println("in custom generator..."+object.getClass().getCanonicalName());
      EntityPersister entityPersister = sessionImplementor.getEntityPersister("restaurantId", object);
      
      Serializable id = entityPersister.getIdentifierGenerator().generate(sessionImplementor, "restaurantId");
      
      System.out.println("id is "+id);
      if(id == null)
      {
         
         return IdentifierGeneratorFactory.POST_INSERT_INDICATOR;
      }
      
      
      return id;
      }
      catch (Exception e)
      {
         System.out.println("in exception ");
         System.out.println(e.getMessage());
         return null;
      }
   }

}


please view the following link: viewtopic.php?f=1&t=1015440
Please help.
Regards,

Annuk


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.