高手请教:JNDI和SessionFactory怎么绑定?

05-07-12 lvyg
你好banq,我是问当用下面的代码创建SessionFactory时,JNDI和SessionFactory如何绑定? 谢谢

SessionFactory sf = (SessionFactory)new InitialContext().lookup(

"hibernate/session_factory");

//问题1:通过JNDI查找,但hiernate/session_factory是怎么绑定的?

Session s = sf.openSession();

haoqingshi
2005-07-14 11:43
JNDI要在hibernate.cfg.xml中配置的

<hibernate-configuration>

<session-factory >

<!--DHCPBY池,然@需要在Tomcat或者Weblogic中设定-->

<property name="connection.datasource">java:comp/env/jdbc/dbname</property>

<mapping resource=""/>

</session-factory>

</hibernate-configuration>

当然,你要添加commons-dbcp.jar

haoqingshi
2005-07-14 11:44

  <hibernate-configuration>
    <session-factory >
    <property name="connection.datasource">java:comp/env/jdbc/dbname</property>
     </session-factory>
</hibernate-configuration>
<p>

haoqingshi
2005-07-14 11:47
补充一点,前提是你在web server容器中配置了dbcp

比如在tomcat中配置好了连接池:java:comp/env/jdbc/dbname

猜你喜欢