既然用websphere的连接池,你在webspere中的配置和hibernate.properties(hibernate.cfg.xml)中的配置是否吻合?

解决方案 »

  1.   

    hibernate.cfg.xml:
    <!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="foo">
    <mapping resource="struts/advinfo/db/Advisor.hbm.xml"/>
    <mapping resource="sys/bm/Duty.hbm.xml"/>
        <mapping resource="struts/message/bo/Accessories.hbm.xml"/>
    <mapping resource="struts/message/bo/Body.hbm.xml"/>
    <mapping resource="struts/message/bo/Send.hbm.xml"/>
    <mapping resource="struts/cet/bo/Cet.hbm.xml"/>
    </session-factory>
    </hibernate-configuration>
      

  2.   

    <property name="connection.datasource">java:comp/env/jdbc/OracleXX</property>
    hibernate.cfg.xml文件中要这样配置吧!这是tomcat中这样配,不知道websphere文件中jndi目录是否是
    java:comp/env?
      

  3.   

    你是否既用了hibernate.properties文件又用了hibernate.cfg.xml文件?
    看你用哪种方式产生Configuration,如果用Configuration c=new Configuration()则默认是hibernage.properties文件,那么就在这里面配置.
    如果用其它方式产生Configuration就在hibernate.cfg.xml文件中配置!
      

  4.   

    问题有可能出在这里。我已经把propertie删了。在试一试。
    不过也怪,部署到服务器上面有时候又能连接到数据库。
      

  5.   

    时断时通我在想可能因为xml会覆盖properties文件的原因。
    An alternative approach to configuration is to specify a full configuration in a file named hibernate.cfg.xml. This file can be used as a replacement for the hibernate.properties file or, if both are present, to override properties. 
      

  6.   

    这样的话你就不用Configuration c=new Configuration();那就用Configuration c=new Configuration().configure();这样就用hibernate.cfg.xml文件作为配置文件了!