Trying to Unit Test A Class That Makes DB Queries Using Hibernate And Can't Get Session Created...
- by Jared Michaels
I am trying to implement JUnit tests for a class that performs DB queries using Hibernate. When I create the class under test, I get access to the session through the factory by doing the following:
InitialContext context = new InitialContext();
sessionFactory = (SessionFactory) context.lookup(hibernateContext);
This works fine when I deploy this to JBoss 5.1. I am trying to figure out how to get this to work with my JUnit test. I keep getting an exception stating that I "Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial". I've searched high and low but haven't been able to find any information about what specifically I need to do to get this to work. I am not using Spring or any frameworks, just plain old Java and JUnit.