感谢robbin详尽的分析。我参考Weblogic下的代码:
private static void doBind( ) throws Exception
{
Properties environment = null;
InitialContext context = null;
try
{
//Properties for storing JNDI configuration information
environment = new Properties( );
//Add initial context factory
environment.put( Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
environment.put( Context.PROVIDER_URL, URL );
log( "Constructing an Initial Directory Context object" );
context = new InitialContext( environment );
Configuration conf = new Configuration().addClass(Cat.class);
SessionFactory factory = conf.buildSessionFactory();
if (factory == null)
throw new Exception("SessionFactory cannot be built?!");
try
{
if( context.lookup(SESSION_FACTORY_JNDI ) != null )
context.rebind(SESSION_FACTORY_JNDI, factory );
else
context.bind(SESSION_FACTORY_JNDI, factory );
}
catch ( NamingException nameEx )
{
context.bind(SESSION_FACTORY_JNDI, factory );
}
}
可是我跟踪发现,程序执行到SessionFactory factory = ds.buildSessionFactory(); 就已经抛出上述的异常。即找不到数据源quickstart。在Hibernate的站点上Govin提供的例子里
Datastore ds = Hibernate.createDatastore();
的Datastore是否是老版本的实现?2.01版本里没有该类。