解决方案 »

  1.   

    直接配置成这样也不行
    <property name="hibernate.connection.datasource">java:/newProject</property>
      

  2.   

    我只用过7以后版本的,你这jboss啥版本的
      

  3.   

    我在standalone-full.xml下如此配置的
    <subsystem xmlns="urn:jboss:domain:datasources:1.1">
                <datasources>
                    <datasource jndi-name="java:jboss/datasources/jbpmDS" pool-name="jbpmDS" enabled="true" use-java-context="true">
                        <connection-url>jdbc:mysql://localhost:3306/jbpm6</connection-url>
                        <driver>mysqlh2</driver>
                        <security>
                            <user-name>root</user-name>
                            <password>root</password>
                        </security>
                    </datasource>
                    
                    <drivers>
                        <driver name="mysqlh2" module="com.mysqldatabase.mysql">
                            <xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
                        </driver>
    </drivers>
                </datasources>
            </subsystem>
    当然。驱动需要加在module文件夹中,其实不难,网上有,官方文档更是标准
    这个配置也能用在-ds.xml中
      

  4.   

    我看到有些资料说要在
    %Jboss_Home%/server/default/conf下的standardjbosscmp-jdbc.xml的如下节点做了修改:<datasource>java:/newProject</datasource>
    <datasource-mapping>MS SQLSERVER2005</datasource-mapping>将%Jboss_Home%/server/default/conf下的standardjaws.xml的如下节点做了修改:<datasource>java:/newProject</datasource>
    <type-mapping>MS SQLSERVER2005</type-mapping>
    但是没有具体怎么说明添加到哪个位置,这两个我打开后都有很多信息在,不知道如何去修改。。
      

  5.   

    资料地址:
    http://docs.jboss.org/hibernate/core/3.3/reference/en/html/session-configuration.html3.8.4. JMX deploymentThe line cfg.buildSessionFactory() still has to be executed somewhere to get a SessionFactory into JNDI. You can do this either in a static initializer block, like the one in HibernateUtil, or you can deploy Hibernate as a managed service.Hibernate is distributed with org.hibernate.jmx.HibernateService for deployment on an application server with JMX capabilities, such as JBoss AS. The actual deployment and configuration is vendor-specific. Here is an example jboss-service.xml for JBoss 4.0.x:<?xml version="1.0"?>
    <server><mbean code="org.hibernate.jmx.HibernateService"
        name="jboss.jca:service=HibernateFactory,name=HibernateFactory">    <!-- Required services -->
        <depends>jboss.jca:service=RARDeployer</depends>
        <depends>jboss.jca:service=LocalTxCM,name=HsqlDS</depends>    <!-- Bind the Hibernate service to JNDI -->
        <attribute name="JndiName">java:/hibernate/SessionFactory</attribute>    <!-- Datasource settings -->
        <attribute name="Datasource">java:HsqlDS</attribute>
        <attribute name="Dialect">org.hibernate.dialect.HSQLDialect</attribute>    <!-- Transaction integration -->
        <attribute name="TransactionStrategy">
            org.hibernate.transaction.JTATransactionFactory</attribute>
        <attribute name="TransactionManagerLookupStrategy">
            org.hibernate.transaction.JBossTransactionManagerLookup</attribute>
        <attribute name="FlushBeforeCompletionEnabled">true</attribute>
        <attribute name="AutoCloseSessionEnabled">true</attribute>    <!-- Fetching options -->
        <attribute name="MaximumFetchDepth">5</attribute>    <!-- Second-level caching -->
        <attribute name="SecondLevelCacheEnabled">true</attribute>
        <attribute name="CacheProviderClass">org.hibernate.cache.EhCacheProvider</attribute>
        <attribute name="QueryCacheEnabled">true</attribute>    <!-- Logging -->
        <attribute name="ShowSqlEnabled">true</attribute>    <!-- Mapping files -->
        <attribute name="MapResources">auction/Item.hbm.xml,auction/Category.hbm.xml</attribute></mbean>
    </server>3.7. XML configuration fileAn 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.The XML configuration file is by default expected to be in the root of your CLASSPATH. Here is an example:<?xml version='1.0' encoding='utf-8'?>
    <!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD//EN"
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"><hibernate-configuration>    <!-- a SessionFactory instance listed as /jndi/name -->
        <session-factory
            name="java:hibernate/SessionFactory">        <!-- properties -->
            <property name="connection.datasource">java:/comp/env/jdbc/MyDB</property>
            <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
            <property name="show_sql">false</property>
            <property name="transaction.factory_class">
                org.hibernate.transaction.JTATransactionFactory
            </property>
            <property name="jta.UserTransaction">java:comp/UserTransaction</property>        <!-- mapping files -->
            <mapping resource="org/hibernate/auction/Item.hbm.xml"/>
            <mapping resource="org/hibernate/auction/Bid.hbm.xml"/>        <!-- cache settings -->
            <class-cache class="org.hibernate.auction.Item" usage="read-write"/>
            <class-cache class="org.hibernate.auction.Bid" usage="read-only"/>
            <collection-cache collection="org.hibernate.auction.Item.bids" usage="read-write"/>    </session-factory></hibernate-configuration>
      

  6.   

    http://stackoverflow.com/questions/4799321/hibernate-jboss-jndi-configuration
      

  7.   

    我修改了下配置现在是这样:
    server\default\deploy
    --newProject.war
    --mssqlserver-ds.xmlwar包下hibernate.cfg.xml配置信息
    <?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>
    <property name="hibernate.connection.datasource">newProject</property>
    <property name="dialect">
            org.hibernate.dialect.SQLServerDialect
        </property>
        <property name="show_sql">false</property>
        <property name="hibernate.jdbc.batch_size">10</property>
        <property name="jndi.url"></property>
     
        <mapping resource="com/zzxgy/pojo/Person.hbm.xml" />
     
    </session-factory>
     
    </hibernate-configuration>mssqlserver-ds.xml配置:
    <local-tx-datasource>
    <jndi-name>newProject</jndi-name>
    <connection-url>jdbc:sqlserver://localhost:1433;databaseName=new</connection-url>
    <driver-class>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver-class>
    <user-name>sa</user-name>
    <password>sa</password>
    <use-java-context>false</use-java-context><min-pool-size>5</min-pool-size><max-pool-size>800</max-pool-size>
    <idle-timeout-minutes>5</idle-timeout-minutes>
    <metadata>
    <type-mapping>MS SQLSERVER2005</type-mapping>
    </metadata>
    </local-tx-datasource>可以通过初始化进入登陆界面