2011-08-17 72 views
2

我將一個打包爲HAR Hibernate歸檔文件的應用程序從JBoss AS5遷移到AS7。我有很多問題,並且我知道爲了成功遷移我的應用程序,我必須面對許多障礙。我不介意研究自己的事情 - 但在這一點上我不太確定什麼是可能的,或者我應該採取的方向,並會欣賞任何指針或評論。將HAR休眠歸檔文件遷移到JBoss 7

我知道JBoss AS7不支持HAR hibernate存檔 - 所以我必須進行某種更改才能使其工作。我的應用程序需要hibernate3,我將其作爲依賴項包含在內。我HAR的結構類似於

HAR 
| 
|-com 
| |-business classes 
|  |-*class files and *hbm.xml files 
| 
|-META-INF 
    |-hibernate.xml 

我hibernate.xml文件看起來像

<hibernate-configuration xmlns="urn:jboss:hibernate-deployer:1.0"> 

    <session-factory name="java:/hibernate/SessionFactory" bean="jboss.har:service=Hibernate"> 
     <property name="datasourceName">java:/MySqlDS</property> 
     <property name="dialect">org.hibernate.dialect.MySQLDialect</property> 

<!-- <property name="sessionFactoryInterceptor">org.jboss.test.hibernate.SimpleInterceptor</property> --> 
<!-- <property name="hbm2ddlAuto">create</property> --> 
     <depends>jboss:service=Naming</depends> 
     <depends>jboss:service=TransactionManager</depends> 
    </session-factory> 

</hibernate-configuration> 

我們使用* hbm.xml文件中我們HAR定義實體,而不是休眠註釋的新風格。我有幾個問題是:

- 有沒有一種方法可以將我的HAR打包爲JAR並在AS7中使用它,而不必經歷重寫我的業務類以使用註釋來定義實體的麻煩而不是使用* hbm.xml文件?
- 如果沒有關於將代碼轉換爲使用hibernate annotations和persistence.xml的指南嗎?我不介意做研究,但現在我不確定我應該研究什麼。

+0

>我知道的JBoss AS7不支持HAR休眠檔案我能問你,你知道從哪裏呢? – sheidaei

+0

你有沒有解決過這個問題?我現在遇到同樣的問題 –

回答

1

HAR檔案在JBoss 7中不再存在。事實上,即使ServiceMBeanSupport也不存在了。一種可能性是使用某種機制來創建SessionFactory並將其注入到JNDI中。另一種可能性是「使用和不使用」新的JPA API。通過「使用」,我的意思是在persistence.xml文件中定義Hibernate配置並使用可用的映射檢測功能。這將允許使用添加的META-INF/persistence.xml文件將.har簡單重命名爲.jar,而無需將長列表中的所有映射和類硬編碼到某處。通過「不使用」,我的意思是讓JPA初始化,但使用舊的SessionFactory,因爲當舊的API運行良好時,沒有理由更改爲新的API。 但是,另一個問題是JBoss 7與Hibernate 4捆綁在一起,遷移可能並不簡單。然而,在你的應用程序中,仍然有可能將Hibernate捆綁到3.5以下。下面是persistence.xml中:

<persistence xmlns="http://java.sun.com/xml/ns/persistence" 
 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 
     xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" 
 
     version="2.0"> 
 
    <persistence-unit name="X"> 
 
    <description>X</description> 
 
    <jta-data-source>java:/XOracleDS</jta-data-source> 
 
    <properties> 
 
    \t <!-- This tells JBoss to use Hibernate 3 (as low as 3.5) bundled into the application --> 
 
     <property name="jboss.as.jpa.providerModule" value="hibernate3-bundled" /> 
 
     <!--<property name="jboss.as.jpa.managed" value="false"/>--> 
 
     <!-- This will bind the session factory to JNDI as we require --> 
 
     <property name="hibernate.session_factory_name" value="java:/hibernate/XOracleSessionFactory"/> 
 
     <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/> 
 
     <!-- This is one of the trickiest parts as Hibernate 3.5 does not has a RegionFactory and we must use the one from ehcache to bridge the gap --> 
 
     <property name="hibernate.cache.region.factory_class" value="net.sf.ehcache.hibernate.EhCacheRegionFactory"/> 
 
     <!-- very important to allow same names as in JBoss 4 --> 
 
     <property name="hibernate.cache.region_prefix" value=""/> 
 
     <property name="hibernate.cache.provider_class" value="net.sf.ehcache.hibernate.SingletonEhCacheProvider"/> 
 
     <!-- This will make use of JBoss managed transactions. The factory is already present in JNDI --> 
 
     <property name="hibernate.transaction.factory_class" value="org.hibernate.transaction.JTATransactionFactory"/> 
 
     <property name="hibernate.jdbc.batch_size" value="20"/> 
 
     <property name="hibernate.show_sql" value="false"/> 
 
     \t <property name="hibernate.format_sql" value="false"/> 
 
     \t <property name="hibernate.cache.use_query_cache" value="true"/> 
 
     \t <property name="hibernate.cache.use_second_level_cache" value="true"/> 
 
    </properties> 
 
    </persistence-unit> 
 
</persistence>