Connecting Tech Pros Worldwide Forums | Help | Site Map

JUnit, JNDI, and Hibernate

Newbie
 
Join Date: Jul 2007
Posts: 15
#1: Dec 17 '07
I'm looking to use JUnit to test some code that uses Hibernate to connect to my DB (SQL Server). Although I can do this using a hibernate.cfg.xml file I want to create a super class I can extend so I won't have to rewrite code for each TestCase subclass. To make a long story short I'm trying to define some JNDI properties that will include my DB name, username, and password so hibernate can pick it up. I think I have the basics in my setUp method, but I keep getting a NoIntialContextException. My method is below:

Expand|Select|Wrap|Line Numbers
  1.  
  2. protected void setUp() throws Exception {        
  3. Properties env = new Properties();
  4.  
  5. env.put(Context.INITIAL_CONTEXT_FACTORY, "javax.naming.spi.InitialContextFactory");
  6. env.put("connection.url", "jdbc:sqlserver://localhost:1433;databaseName=DevDB;userName=u53rn@me;password=p@55w0rd;SelectMethod=cursor");
  7.         Context ctx = new InitialContext(env);
  8. }
  9.  
I can't seem to figure out what I'm doing wrong. All the tutorial I've been looking at have not helped. Any ideas?

Reply