-->
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.  [ 3 posts ] 
Author Message
 Post subject: Configuring Hibernate to work with JUnit - JNDI problem
PostPosted: Fri Feb 20, 2009 4:56 am 
Beginner
Beginner

Joined: Tue Oct 28, 2008 6:41 pm
Posts: 20
I've been trying all day to get JUnit to recognize Hibernate and it just isn't happening.

It seems like integrating JUnit and Hibernate in Eclipses should be straight forward .

I'm using Eclipse , Hibernate 3.x ,JUnit 4.

There were a couple articles about how to do it with Spring and Maven .
I am not using Spring or Maven for this project .

It is web app that is finished and it works fine but I am trying to get JUnit to test it .Apparently JUnit was not designed for testing anything that uses a database or JNDI settings created by the app it is testing. All the examples I see are extremely trivial tests for getters and setters of stand alone POJO's.

The full code is below. Basically, it seems to be saying that it doesn't recognize any of Hibernate's JNDI settings.


Feb 20, 2009 12:12:23 AM org.hibernate.cfg.Environment <clinit>
INFO: Hibernate 3.2.3
Feb 20, 2009 12:12:23 AM org.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
Feb 20, 2009 12:12:23 AM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: Bytecode provider name : cglib
Feb 20, 2009 12:12:23 AM org.hibernate.cfg.Environment <clinit>
INFO: using JDK 1.4 java.sql.Timestamp handling
Feb 20, 2009 12:12:23 AM org.hibernate.cfg.Configuration configure
INFO: configuring from resource: /hibernate.cfg.xml
Feb 20, 2009 12:12:23 AM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: Configuration resource: /hibernate.cfg.xml
Feb 20, 2009 12:12:23 AM org.hibernate.cfg.Configuration addResource
INFO: Reading mappings from resource : fb/pojo/Pw.hbm.xml
Feb 20, 2009 12:12:23 AM org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: fb.pojo.Pw -> pw
Feb 20, 2009 12:12:23 AM org.hibernate.cfg.Configuration addResource
INFO: Reading mappings from resource : fb/pojo/Team.hbm.xml
Feb 20, 2009 12:12:23 AM org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: fb.pojo.Team -> team
Feb 20, 2009 12:12:23 AM org.hibernate.cfg.Configuration addResource
INFO: Reading mappings from resource : fb/pojo/Members.hbm.xml
Feb 20, 2009 12:12:23 AM org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: fb.pojo.Members -> members
Feb 20, 2009 12:12:24 AM org.hibernate.cfg.Configuration addResource
INFO: Reading mappings from resource : fb/pojo/Positions.hbm.xml
Feb 20, 2009 12:12:24 AM org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: fb.pojo.Positions -> positions
Feb 20, 2009 12:12:24 AM org.hibernate.cfg.Configuration addResource
INFO: Reading mappings from resource : fb/pojo/Person.hbm.xml
Feb 20, 2009 12:12:24 AM org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: fb.pojo.Person -> person
Feb 20, 2009 12:12:24 AM org.hibernate.cfg.Configuration addResource
INFO: Reading mappings from resource : fb/pojo/Pad.hbm.xml
Feb 20, 2009 12:12:24 AM org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: fb.pojo.Pad -> pad
Feb 20, 2009 12:12:24 AM org.hibernate.cfg.Configuration addResource
INFO: Reading mappings from resource : fb/pojo/Address.hbm.xml
Feb 20, 2009 12:12:24 AM org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: fb.pojo.Address -> address
Feb 20, 2009 12:12:24 AM org.hibernate.cfg.Configuration addResource
INFO: Reading mappings from resource : fb/pojo/Statistics.hbm.xml
Feb 20, 2009 12:12:24 AM org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: fb.pojo.Statistics -> statistics
Feb 20, 2009 12:12:24 AM org.hibernate.cfg.Configuration doConfigure
INFO: Configured SessionFactory: java:hibernate/SessionFactory
Feb 20, 2009 12:12:24 AM org.hibernate.cfg.HbmBinder bindCollectionSecondPass
INFO: Mapping collection: fb.pojo.Team.members -> members
Feb 20, 2009 12:12:24 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Using Hibernate built-in connection pool (not for production use!)
Feb 20, 2009 12:12:24 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Hibernate connection pool size: 20
Feb 20, 2009 12:12:24 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: autocommit mode: false
Feb 20, 2009 12:12:24 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost:3307/pnisbett?autoReconnect=true
Feb 20, 2009 12:12:24 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: connection properties: {user=pnisbett, password=****}
Feb 20, 2009 12:12:24 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: RDBMS: MySQL, version: 5.0.67-community-nt
Feb 20, 2009 12:12:24 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-5.1.6 ( Revision: ${svn.Revision} )
Feb 20, 2009 12:12:24 AM org.hibernate.dialect.Dialect <init>
INFO: Using dialect: org.hibernate.dialect.MySQL5Dialect
Feb 20, 2009 12:12:24 AM org.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory
INFO: Using default transaction strategy (direct JDBC transactions)
Feb 20, 2009 12:12:24 AM org.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
INFO: No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
Feb 20, 2009 12:12:24 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic flush during beforeCompletion(): disabled
Feb 20, 2009 12:12:24 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic session close at end of transaction: disabled
Feb 20, 2009 12:12:24 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch size: 15
Feb 20, 2009 12:12:24 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch updates for versioned data: disabled
Feb 20, 2009 12:12:24 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Scrollable result sets: enabled
Feb 20, 2009 12:12:24 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC3 getGeneratedKeys(): enabled
Feb 20, 2009 12:12:24 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Connection release mode: auto
Feb 20, 2009 12:12:24 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Maximum outer join fetch depth: 2
Feb 20, 2009 12:12:24 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default batch fetch size: 1
Feb 20, 2009 12:12:24 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Generate SQL with comments: disabled
Feb 20, 2009 12:12:24 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL updates by primary key: disabled
Feb 20, 2009 12:12:24 AM org.hibernate.cfg.SettingsFactory createQueryTranslatorFactory
INFO: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
Feb 20, 2009 12:12:24 AM org.hibernate.hql.ast.ASTQueryTranslatorFactory <init>
INFO: Using ASTQueryTranslatorFactory
Feb 20, 2009 12:12:24 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query language substitutions: {}
Feb 20, 2009 12:12:24 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JPA-QL strict compliance: disabled
Feb 20, 2009 12:12:24 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Second-level cache: enabled
Feb 20, 2009 12:12:24 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query cache: disabled
Feb 20, 2009 12:12:24 AM org.hibernate.cfg.SettingsFactory createCacheProvider
INFO: Cache provider: org.hibernate.cache.NoCacheProvider
Feb 20, 2009 12:12:24 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Optimize cache for minimal puts: disabled
Feb 20, 2009 12:12:24 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Structured second-level cache entries: disabled
Feb 20, 2009 12:12:24 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Echoing all SQL to stdout
Feb 20, 2009 12:12:24 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Statistics: disabled
Feb 20, 2009 12:12:24 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Deleted entity synthetic identifier rollback: disabled
Feb 20, 2009 12:12:24 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default entity-mode: pojo
Feb 20, 2009 12:12:24 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Named query checking : enabled
Feb 20, 2009 12:12:24 AM org.hibernate.impl.SessionFactoryImpl <init>
INFO: building session factory
positions initializing
Feb 20, 2009 12:12:24 AM org.hibernate.impl.SessionFactoryObjectFactory addInstance
INFO: Factory name: SessionFactory
Feb 20, 2009 12:12:24 AM org.hibernate.util.NamingHelper getInitialContext
INFO: JNDI InitialContext properties:{}
Feb 20, 2009 12:12:24 AM org.hibernate.impl.SessionFactoryObjectFactory addInstance
WARNING: Could not bind factory to JNDI
javax.naming.NoInitialContextException: 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
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)
at javax.naming.InitialContext.getNameParser(InitialContext.java:480)
at org.hibernate.util.NamingHelper.bind(NamingHelper.java:52)
at org.hibernate.impl.SessionFactoryObjectFactory.addInstance(SessionFactoryObjectFactory.java:90)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:306)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1294)
at Servlets.HibernateUtil.<clinit>(HibernateUtil.java:14)
at TeamHomeTest4.getSessionFactory(TeamHomeTest4.java:33)
at fb.pojo.TeamHome.<init>(TeamHome.java:32)
at TeamHomeTest4.<init>(TeamHomeTest4.java:23)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at org.junit.internal.runners.TestClassMethodsRunner.createTest(TestClassMethodsRunner.java:52)
at org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod(TestClassMethodsRunner.java:58)
at org.junit.internal.runners.TestClassMethodsRunner.run(TestClassMethodsRunner.java:35)
at org.junit.internal.runners.TestClassRunner$1.runUnprotected(TestClassRunner.java:42)
at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Feb 20, 2009 12:12:24 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: Running hbm2ddl schema update
Feb 20, 2009 12:12:24 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: fetching database metadata
Feb 20, 2009 12:12:24 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: updating schema
Feb 20, 2009 12:12:24 AM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: table found: pnisbett.address
Feb 20, 2009 12:12:24 AM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: columns: [region, id, email, address1, address2, phone2, postcode, phone1, country, city]
Feb 20, 2009 12:12:24 AM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: foreign keys: []
Feb 20, 2009 12:12:24 AM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: indexes: [primary]
Feb 20, 2009 12:12:24 AM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: table found: pnisbett.members
Feb 20, 2009 12:12:24 AM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: columns: [id, positionid, teamid, personid, joinedteam]
Feb 20, 2009 12:12:24 AM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: foreign keys: [fk388ec91957628a1d, fk388ec91951373c2d, fk388ec919b2387dd6]
Feb 20, 2009 12:12:24 AM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: indexes: [fk388ec91957628a1d, primary, fk388ec91951373c2d, fk388ec919b2387dd6]
Feb 20, 2009 12:12:25 AM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: table found: pnisbett.pad
Feb 20, 2009 12:12:25 AM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: columns: [id, adid, updated, pid]
Feb 20, 2009 12:12:25 AM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: foreign keys: [fk_pad_1]
Feb 20, 2009 12:12:25 AM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: indexes: [primary, fk_pad_1]
Feb 20, 2009 12:12:25 AM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: table found: pnisbett.person
Feb 20, 2009 12:12:25 AM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: columns: [id, weight, hometown, dob, lastname, firstname]
Feb 20, 2009 12:12:25 AM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: foreign keys: []
Feb 20, 2009 12:12:25 AM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: indexes: [primary]
Feb 20, 2009 12:12:25 AM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: table found: pnisbett.positions
Feb 20, 2009 12:12:25 AM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: columns: [position, id]
Feb 20, 2009 12:12:25 AM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: foreign keys: []
Feb 20, 2009 12:12:25 AM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: indexes: [primary]
Feb 20, 2009 12:12:25 AM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: table found: pnisbett.pw
Feb 20, 2009 12:12:25 AM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: columns: [id, uid, email, uname, password]
Feb 20, 2009 12:12:25 AM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: foreign keys: []
Feb 20, 2009 12:12:25 AM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: indexes: [primary]
Feb 20, 2009 12:12:25 AM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: table found: pnisbett.statistics
Feb 20, 2009 12:12:25 AM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: columns: [id, single, statvalue, upddate, sequence, description, personid, name, statdate]
Feb 20, 2009 12:12:25 AM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: foreign keys: []
Feb 20, 2009 12:12:25 AM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: indexes: [primary]
Feb 20, 2009 12:12:25 AM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: table found: pnisbett.team
Feb 20, 2009 12:12:25 AM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: columns: [id, location, name, userid, owner, ownerid]
Feb 20, 2009 12:12:25 AM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: foreign keys: []
Feb 20, 2009 12:12:25 AM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: indexes: [primary]
Feb 20, 2009 12:12:25 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: schema update complete
Feb 20, 2009 12:12:25 AM fb.pojo.TeamHome getSessionFactory
SEVERE: Could not locate SessionFactory in JNDI
javax.naming.NoInitialContextException: 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
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at fb.pojo.TeamHome.getSessionFactory(TeamHome.java:42)
at fb.pojo.TeamHome.<init>(TeamHome.java:32)
at TeamHomeTest4.setUp(TeamHomeTest4.java:107)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.internal.runners.BeforeAndAfterRunner.invokeMethod(BeforeAndAfterRunner.java:74)
at org.junit.internal.runners.BeforeAndAfterRunner.runBefores(BeforeAndAfterRunner.java:50)
at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:33)
at org.junit.internal.runners.TestMethodRunner.runMethod(TestMethodRunner.java:75)
at org.junit.internal.runners.TestMethodRunner.run(TestMethodRunner.java:45)
at org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod(TestClassMethodsRunner.java:66)
at org.junit.internal.runners.TestClassMethodsRunner.run(TestClassMethodsRunner.java:35)
at org.junit.internal.runners.TestClassRunner$1.runUnprotected(TestClassRunner.java:42)
at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Feb 20, 2009 12:12:25 AM fb.pojo.TeamHome getSessionFactory
SEVERE: Could not locate SessionFactory in JNDI
javax.naming.NoInitialContextException: 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
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at fb.pojo.TeamHome.getSessionFactory(TeamHome.java:42)
at fb.pojo.TeamHome.<init>(TeamHome.java:32)
at TeamHomeTest4.setUp(TeamHomeTest4.java:107)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.internal.runners.BeforeAndAfterRunner.invokeMethod(BeforeAndAfterRunner.java:74)
at org.junit.internal.runners.BeforeAndAfterRunner.runBefores(BeforeAndAfterRunner.java:50)
at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:33)
at org.junit.internal.runners.TestMethodRunner.runMethod(TestMethodRunner.java:75)
at org.junit.internal.runners.TestMethodRunner.run(TestMethodRunner.java:45)
at org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod(TestClassMethodsRunner.java:66)
at org.junit.internal.runners.TestClassMethodsRunner.run(TestClassMethodsRunner.java:35)
at org.junit.internal.runners.TestClassRunner$1.runUnprotected(TestClassRunner.java:42)
at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Feb 20, 2009 12:12:25 AM fb.pojo.TeamHome getSessionFactory
SEVERE: Could not locate SessionFactory in JNDI
javax.naming.NoInitialContextException: 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
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at fb.pojo.TeamHome.getSessionFactory(TeamHome.java:42)
at fb.pojo.TeamHome.<init>(TeamHome.java:32)
at TeamHomeTest4.setUp(TeamHomeTest4.java:107)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.internal.runners.BeforeAndAfterRunner.invokeMethod(BeforeAndAfterRunner.java:74)
at org.junit.internal.runners.BeforeAndAfterRunner.runBefores(BeforeAndAfterRunner.java:50)
at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:33)
at org.junit.internal.runners.TestMethodRunner.runMethod(TestMethodRunner.java:75)
at org.junit.internal.runners.TestMethodRunner.run(TestMethodRunner.java:45)
at org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod(TestClassMethodsRunner.java:66)
at org.junit.internal.runners.TestClassMethodsRunner.run(TestClassMethodsRunner.java:35)
at org.junit.internal.runners.TestClassRunner$1.runUnprotected(TestClassRunner.java:42)
at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Feb 20, 2009 12:12:25 AM fb.pojo.TeamHome getSessionFactory
SEVERE: Could not locate SessionFactory in JNDI
javax.naming.NoInitialContextException: 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
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at fb.pojo.TeamHome.getSessionFactory(TeamHome.java:42)
at fb.pojo.TeamHome.<init>(TeamHome.java:32)
at TeamHomeTest4.setUp(TeamHomeTest4.java:107)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.internal.runners.BeforeAndAfterRunner.invokeMethod(BeforeAndAfterRunner.java:74)
at org.junit.internal.runners.BeforeAndAfterRunner.runBefores(BeforeAndAfterRunner.java:50)
at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:33)
at org.junit.internal.runners.TestMethodRunner.runMethod(TestMethodRunner.java:75)
at org.junit.internal.runners.TestMethodRunner.run(TestMethodRunner.java:45)
at org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod(TestClassMethodsRunner.java:66)
at org.junit.internal.runners.TestClassMethodsRunner.run(TestClassMethodsRunner.java:35)
at org.junit.internal.runners.TestClassRunner$1.runUnprotected(TestClassRunner.java:42)
at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Feb 20, 2009 12:12:25 AM fb.pojo.TeamHome getSessionFactory
SEVERE: Could not locate SessionFactory in JNDI
javax.naming.NoInitialContextException: 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
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at fb.pojo.TeamHome.getSessionFactory(TeamHome.java:42)
at fb.pojo.TeamHome.<init>(TeamHome.java:32)
at TeamHomeTest4.setUp(TeamHomeTest4.java:107)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.internal.runners.BeforeAndAfterRunner.invokeMethod(BeforeAndAfterRunner.java:74)
at org.junit.internal.runners.BeforeAndAfterRunner.runBefores(BeforeAndAfterRunner.java:50)
at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:33)
at org.junit.internal.runners.TestMethodRunner.runMethod(TestMethodRunner.java:75)
at org.junit.internal.runners.TestMethodRunner.run(TestMethodRunner.java:45)
at org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod(TestClassMethodsRunner.java:66)
at org.junit.internal.runners.TestClassMethodsRunner.run(TestClassMethodsRunner.java:35)
at org.junit.internal.runners.TestClassRunner$1.runUnprotected(TestClassRunner.java:42)
at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Feb 20, 2009 12:12:25 AM fb.pojo.TeamHome getSessionFactory
SEVERE: Could not locate SessionFactory in JNDI
javax.naming.NoInitialContextException: 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
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at fb.pojo.TeamHome.getSessionFactory(TeamHome.java:42)
at fb.pojo.TeamHome.<init>(TeamHome.java:32)
at TeamHomeTest4.setUp(TeamHomeTest4.java:107)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.internal.runners.BeforeAndAfterRunner.invokeMethod(BeforeAndAfterRunner.java:74)
at org.junit.internal.runners.BeforeAndAfterRunner.runBefores(BeforeAndAfterRunner.java:50)
at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:33)
at org.junit.internal.runners.TestMethodRunner.runMethod(TestMethodRunner.java:75)
at org.junit.internal.runners.TestMethodRunner.run(TestMethodRunner.java:45)
at org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod(TestClassMethodsRunner.java:66)
at org.junit.internal.runners.TestClassMethodsRunner.run(TestClassMethodsRunner.java:35)
at org.junit.internal.runners.TestClassRunner$1.runUnprotected(TestClassRunner.java:42)
at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Feb 20, 2009 12:12:25 AM fb.pojo.TeamHome getSessionFactory
SEVERE: Could not locate SessionFactory in JNDI
javax.naming.NoInitialContextException: 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
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at fb.pojo.TeamHome.getSessionFactory(TeamHome.java:42)
at fb.pojo.TeamHome.<init>(TeamHome.java:32)
at TeamHomeTest4.setUp(TeamHomeTest4.java:107)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.internal.runners.BeforeAndAfterRunner.invokeMethod(BeforeAndAfterRunner.java:74)
at org.junit.internal.runners.BeforeAndAfterRunner.runBefores(BeforeAndAfterRunner.java:50)
at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:33)
at org.junit.internal.runners.TestMethodRunner.runMethod(TestMethodRunner.java:75)
at org.junit.internal.runners.TestMethodRunner.run(TestMethodRunner.java:45)
at org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod(TestClassMethodsRunner.java:66)
at org.junit.internal.runners.TestClassMethodsRunner.run(TestClassMethodsRunner.java:35)
at org.junit.internal.runners.TestClassRunner$1.runUnprotected(TestClassRunner.java:42)
at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Feb 20, 2009 12:12:25 AM fb.pojo.TeamHome getSessionFactory
SEVERE: Could not locate SessionFactory in JNDI
javax.naming.NoInitialContextException: 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
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at fb.pojo.TeamHome.getSessionFactory(TeamHome.java:42)
at fb.pojo.TeamHome.<init>(TeamHome.java:32)
at TeamHomeTest4.setUp(TeamHomeTest4.java:107)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.internal.runners.BeforeAndAfterRunner.invokeMethod(BeforeAndAfterRunner.java:74)
at org.junit.internal.runners.BeforeAndAfterRunner.runBefores(BeforeAndAfterRunner.java:50)
at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:33)
at org.junit.internal.runners.TestMethodRunner.runMethod(TestMethodRunner.java:75)
at org.junit.internal.runners.TestMethodRunner.run(TestMethodRunner.java:45)
at org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod(TestClassMethodsRunner.java:66)
at org.junit.internal.runners.TestClassMethodsRunner.run(TestClassMethodsRunner.java:35)
at org.junit.internal.runners.TestClassRunner$1.runUnprotected(TestClassRunner.java:42)
at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)


Top
 Profile  
 
 Post subject: RE:Configuring Hibernate to work with JUnit - JNDI problem
PostPosted: Fri Feb 20, 2009 8:20 am 
Newbie

Joined: Fri Feb 20, 2009 8:03 am
Posts: 3
Location: India
Hi,

Have spring-mock.jar and spring.jar.
Create a xml file in which u specify you database configurations, transaction manager, mapping files,session factory. rest is same. You can check spring site for getting the XML format for JUNIT.

_________________
Jansi.P


Top
 Profile  
 
 Post subject: Configuring Hibernate to work with JUnit - JNDI problem
PostPosted: Sun Feb 22, 2009 9:39 pm 
Beginner
Beginner

Joined: Tue Oct 28, 2008 6:41 pm
Posts: 20
Hi,
Thanks for replying back to me.

I'm not sure I understand . I have all the database configurations ,etc mapped in my hibernate.cfg.xml file .The problem is JUnit is not recognizing the session factory name I specified in it.

It produces the error stated below when the unit gets tested. When I run the app in Tomcat ,it runs fine.

Are you saying I need to is add the 2 Spring jars and it will work or do I have to create a different xml file ?

hibernate.cfg.xml is below:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
<session-factory name="java:hibernate/SessionFactory">


<property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>

<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3307/pnisbett?autoReconnect=true</property>

<property name="hibernate.connection.username">dbuser</property>
<property name="hibernate.connection.password">apassword</property>

<property name="show_sql">true</property>

<property name="hibernate.hbm2ddl.auto">update</property>
<property name="hibernate.session_factory_name">SessionFactory</property>
<property name="current_session_context_class">thread</property>

<mapping resource="fb/pojo/Pw.hbm.xml"/>

<mapping resource="fb/pojo/Team.hbm.xml"/>
<mapping resource="fb/pojo/Members.hbm.xml"/>
<mapping resource="fb/pojo/Positions.hbm.xml"/>
<mapping resource="fb/pojo/Person.hbm.xml"/>
<mapping resource="fb/pojo/Pad.hbm.xml"/>
<mapping resource="fb/pojo/Address.hbm.xml"/>

<mapping resource="fb/pojo/Statistics.hbm.xml"/>
<!--

-->
</session-factory>
</hibernate-configuration>


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

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.