2012-05-11 28 views
13

我們正試圖從休眠3.6.7升級到4.1.2,並使用Hibernate工具3.2.0至3.5.0Hibernate的工具:錯誤解析JNDI名稱

我們生成一個數據庫創建腳本螞蟻:

 <hibernatetool destdir="${target}"> 
     <jpaconfiguration persistenceunit="stdcmpOrderPersistenceUnit" propertyfile="@{propertyfile}"/> 
     <classpath refid="@{classpathid}"/> 
     <!-- the file name is relative to $destdir --> 
     <hbm2ddl outputfilename="@{output}" format="true" export="false" drop="false"/> 
    </hibernatetool> 

我們的持久單元是這樣的:

​​

我們得到以下錯誤升級後:

[hibernatetool] org.hibernate.service.jndi.JndiException: Error parsing JNDI name [jdbc/lakshmi_stdcmp] 
[hibernatetool] javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial 

爲什麼Hibernate嘗試解析JNDI名稱,因爲PersistenceUnit上的所有信息都可用? 我們對舊版本沒有任何問題。

在任何情況下,我們如何指定一個NamingFactory? (和哪一個?)

回答

1

問題來自您的hibernate工具,您已將hibernate工具配置爲使用持久性單元,該單元具有通過JNDI配置的jta數據源。 爲了使ant任務與JNDI對話,它需要命名工廠URL和提供者。 使用數據源配置的應用程序服務器的命名工廠類。

希望它有幫助。

48

我遇到了類似的問題,特別是導致「錯誤解析JNDI名稱」, ,它很容易通過從session-factory標籤中刪除空名稱屬性來解決。

我的hibernate.cfg.xml有

<session-factory name=""> 

這是自動生成的,所以我只是刪除了name ATTRIB。

此修復程序在這裏找到:https://forum.hibernate.org/viewtopic.php?f=1&t=1014760

好運。

+1

歡迎來到Stack Overflow!雖然這可能在理論上回答這個問題,[這將是更可取的](http://meta.stackexchange.com/q/8259)在這裏包括答案的重要部分,並提供供參考的鏈接。 – Spontifixus

+1

感謝您指出。 –

+0

任何想法爲什麼冬眠不是這樣? – webber

相關問題