-->
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.  [ 1 post ] 
Author Message
 Post subject: ID Gen - Migration from Hibernate 3.2.3.GA to 4.1.1.Final
PostPosted: Mon Aug 26, 2013 8:49 am 
Newbie

Joined: Fri Jun 21, 2013 2:04 am
Posts: 4
Hi,

We are migrating an application from hibernate 3.2.3.GA to hibernate 4.1.1.Final. IN the previous application, TransactionHelper is used to generate the IDs.

I want to reuse that Id generator in Hibernate 4.1.1.Final. But TransactionHelper.java has been deleted from Hibernate 4.1.1.Final.

Can anyone please Help me in this regard?
The code snippet is below:

public class IdGenerator implements IIdGenerator
{

@Override
public Long createIdInCurrentTransaction(final String entityName)
{
return this.createIdsInCurrentTransaction(entityName, 1)[0];
}

@Override
public Long[] createIdsInCurrentTransaction(final String entityName,
final int idCount)
{
Long[] ids = null;
try
{
final Connection connection = this.getSession().connection();
ids = this.getIds(connection, entityName, idCount);
}
catch (final SQLException e)
{
throw new InfrastructureException(e);
}
return ids;
}

@Override
public Long createIdInNewTransaction(
final ISessionProvider sessionProvider, final String entityName)
{
final TransactionHelper helper = new TransactionHelper()
{
protected Serializable doWorkInCurrentTransaction(
final Connection conn, final String sql) throws SQLException
{
return IdGenerator.this.getIds(conn, entityName, 1);
}
};

final Long[] ids = (Long[]) helper
.doWorkInNewTransaction((SessionImplementor) sessionProvider
.getSession());
return ids[0];
}

@Override
public Long peekNextId(final String entityName)
{
Long id = null;
try
{
final Connection connection = this.getSession();
final IdPeekerDcb dcb = new IdPeekerDcb(entityName);
dcb.execute(connection);
id = dcb.getNextGeneratedId();
}
catch (final SQLException e)
{
throw new InfrastructureException(e);
}
return id;
}

protected Session getSession()
{
// return
// ServerHelperLocator.getContainerSessionProvider().getSession();
return HibernateUtil.getSessionFactory().getCurrentSession();
}

private Long[] getIds(final Connection conn, final String entityName,
final int idCount) throws SQLException
{
final IdGeneratorDcb dcb = new IdGeneratorDcb(entityName, idCount);
dcb.execute(conn);
return dcb.getDecoratedIds();
}

}

Thanks in advance.

Giriraj.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.