Sure. Here is the relevant factory setup/query code, and no, there are no associations, (as you can see from the mapping file) and I am not using LEFT JOIN FETCH.
Thanks again for taking a look.
Factory setup code (InitSessionFactory class):
Code:
private static org.hibernate.SessionFactory sessionFactory = null;
...
public static SessionFactory getInstance(String configFile)
{
if(configFile != null){
HIBERNATE_CONFIG_FILE = configFile;
}
if (sessionFactory == null) {
log.info("sessionfactory is null, initialize it!");
initSessionFactory();
return sessionFactory;
} else {
return sessionFactory;
}
}
public Session getCurrentSession()
{
return sessionFactory.openSession();
}
private static synchronized void initSessionFactory()
{
String CONFIG_FILE_LOCATION = HIBERNATE_CONFIG_FILE;
if (sessionFactory == null) {
try {
cfg.configure(CONFIG_FILE_LOCATION);
String sessionFactoryJndiName = cfg
.getProperty(Environment.SESSION_FACTORY_NAME);
log.info("SessionFactory JNDI Name: " + sessionFactoryJndiName);
if (sessionFactoryJndiName != null) {
cfg.buildSessionFactory();
log.debug("get a jndi session factory");
sessionFactory = (SessionFactory) (new InitialContext())
.lookup(sessionFactoryJndiName);
} else {
log.debug("classic factory");
sessionFactory = cfg.buildSessionFactory();
sessionFactory.openSession();
}
} catch (Exception e) {
System.err.println("%%%% Error Creating HibernateSessionFactory %%%%");
e.printStackTrace();
throw new HibernateException(
"Could not initialize the Hibernate configuration");
}
}
}
Query execution code (Takes 9 seconds for select statement to execute):
Code:
SessionFactory sessionFactory = null;
Session session = null;
Transaction tx = null;
boolean outcome = false;
int maxResults = 5;
try
{
sessionFactory = InitSessionFactory.getInstance(ConfigUtility.getDatabaseConfigFileName());
session = sessionFactory.getCurrentSession();
tx = session.beginTransaction();
Criteria crit = session.createCriteria(MyTable.class);
crit.add(Restrictions.eq("dbcolumn6", "value6"));
crit.add(Restrictions.eq("dbcolumn1", "value1"));
crit.add(Restrictions.like("dbcolumn3", "%" + "value3" + "%"));
crit.setFirstResult(0);
crit.setMaxResults(maxResults);
List<MyTable> results = crit.list();
HibernateUtil.commit(tx);
HibernateUtil.close(session);
outcome = (results != null && !(results.isEmpty()) && (results.get(0) != null));
}
catch (Exception e)
{
e.printStackTrace();
}
assertEquals(true,outcome);
}