簡體   English   中英

如何使用JNDI在Hibernate中連接數據庫

[英]How to connect to DB in hibernate using JNDI

我正在使用jndi / db別名來連接數據庫。 它的工作正常。。但是,我需要使用Hibernate完成相同的工作。

當我使用以下屬性時,我無法連接,

<property name="hibernate.connection.datasource">jdbc/ASPTADMINDEV</property> 

在resurce.xml文件中,我正在使用它,

(
 <factories xmi:type="resources.jdbc:DataSource" xmi:id="DataSource_1233129165895" name="Oracle JDBC Driver DataSource" jndiName="jdbc/ASPTADMINDEV" description="New JDBC Datasource" providerType="Oracle JDBC Driver" authMechanismPreference="BASIC_PASSWORD" authDataAlias="ccixdmgr-nprd1-01-nodeMgr/GITPTDEV-ASPTADMIN-ASPTI" manageCachedHandles="false" logMissingTransactionContext="true" diagnoseConnectionUsage="false" relationalResourceAdapter="builtin_rra" statementCacheSize="10" datasourceHelperClassname="com.ibm.websphere.rsadapter.Oracle10gDataStoreHelper">
      <propertySet xmi:id="J2EEResourcePropertySet_1233129165915">
        <resourceProperties xmi:id="J2EEResourceProperty_1233129165915" name="driverType" type="java.lang.String" value="oci8" description="The type of the driver. The possible values are: thin, oci8." required="false"/>
        <resourceProperties xmi:id="J2EEResourceProperty_1233129165916" name="oracleLogFileSizeLimit" type="java.lang.Integer" value="0" description="Oracle10g and beyond: The oracleLogFileSizeLimit specifies the maximum number of bytes to be written to any one file. Property is relevant only if trace file is specified. Default is unlimited" required="false"/>
        <resourceProperties xmi:id="J2EEResourceProperty_1233129165917" name="oracleLogFileCount" type="java.lang.Integer" value="1" description="Oracle10g and beyond: The oracleLogFileCount specifies the number of files to use. Property is relevant only if trace file is specified. Default is 1." required="false"/>
        <resourceProperties xmi:id="J2EEResourceProperty_1233129165918" name="oracleLogFileName" type="java.lang.String" value="" description="Oracle10g and beyond: The oracleLogFileName indicates which file to write the traces to" required="false"/>
        <resourceProperties xmi:id="J2EEResourceProperty_1233129165919" name="oracleLogTraceLevel" type="java.lang.String" value="INFO" description="Oracle10g and beyond: The oracleLogTraceLevel specifies which message "> 
......... and so

}

請讓我知道我在這里做錯了..

忘記粘貼錯誤;)..下面是錯誤,我正在

INFO: JNDI InitialContext properties:{}
Apr 9, 2014 4:17:19 PM org.hibernate.connection.DatasourceConnectionProvider configure
SEVERE: Could not find datasource: java:comp/env/jdbc/ASPTADMINDEV
javax.naming.NameNotFoundException: Name jdbc is not bound in this Context
Initial SessionFactory creation failed.org.hibernate.HibernateException: Could not find datasource
    at org.apache.naming.NamingContext.lookup(NamingContext.java:770)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:140) 

我需要更改任何東西嗎? 我正在使用以下屬性

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

我認為您需要為數據源提供正確的JNDI名稱,請嘗試使用此名稱。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM