I'm using Hibernate 2.1.1 with a J2EE application using a PointBase database.
Because the application work is done within a CMT, I'm trying to implement a Session Bean Hi/Lo Generator.
I have the EJB coded based on other posts I've seen in this forum, but am getting an exception when trying to configure the TableHiLoGenerator instance.
The code that is having the problem is here:
Code:
gen = new TableHiLoGenerator();
gen.configure(Hibernate.LONG, null, Dialect.getDialect());
When this runs, I get an error that the Dialect is not set. However,
the application includes, on its classpath, the hibernate.cfg.xml
file, which includes the following element in the <session-factory> element:
Code:
<property name="dialect">
net.sf.hibernate.dialect.PointbaseDialect
</property>
I tried creating a Properties object with the following entry:
key: "hibernate.dialect"
value: "net.sf.hibernate.dialect.PointbaseDialect"
and passed it to getDialect(), but I then got a NullPointerExcception when the configure method tried to look up the table name in the properties.
I stopped at this point, as I think the dialect and table names, etc. should already be available to the application, so something must not be configured properly.
Here is the code used in my Session Bean Hi/Lo Generator. Can someone please tell me what I'm doing wrong? Note: I am not showing my IdentifierGenerator implementation class here. If you need to see that as well, I can post it.
Thanks,
Code:
public Long next (
) throws HibernateException
{
if ( gen == null )
{
gen = new TableHiLoGenerator();
// java.util.Properties props = new java.util.Properties();
// props.put("hibernate.dialect", "net.sf.hibernate.dialect.PointbaseDialect");
// gen.configure(Hibernate.LONG, null, Dialect.getDialect(props));
gen.configure(Hibernate.LONG, null, Dialect.getDialect());
}
try
{
Session session = getSession();
if (session instanceof SessionImplementor)
{
Long retval = (Long)gen.generate((SessionImplementor)session, null);
return retval;
}
else
{
throw new HibernateException (
"getSession() did not deliver a SessionImplementor"
);
}
}
catch ( SQLException sqlEx)
{
throw new HibernateException(sqlEx);
}
} // next()
private SessionFactory getSessionFactory (
) throws HibernateException
{
if (sessionFactory == null)
{
sessionFactory = new Configuration().configure().buildSessionFactory();
}
return sessionFactory;
} // getSessionFactory()
private Session getSession (
) throws HibernateException
{
return getSessionFactory().openSession();
} // getSession()