<property name="hibernate.transaction.factory_class" value="org.hibernate.transaction.JTATransactionFactory"/>
<property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.WeblogicTransactionManagerLookup"/>
<property name="hibernate.transaction.flush_before_completion" value="true"/>
<property name="hibernate.transaction.auto_close_session" value="true"/>最后,使用Hibernate進行端到端的測試
現在,我們專為Weblogic Server的JTA事務配置了Hibernate。這時運行測試沒有出現錯誤,表明使用了正確的提供者,并為消息給定了一個正確的標識符。
$ ant -q -Dprovider=hibernate
[echo] =====================================================
[echo] Build Configuration for hibernate
[echo] =====================================================
[echo] Base directory : D:\project\switch
[echo] Deployed Target : D:\project\switch/JPAService.ear
[echo] EJB Module : D:\project\switch/tmp/hibernate-ejb.jar
[echo] Configuration : D:\project\switch/META-INF/hibernate/persistence.xml
[echo] Packaging EJB Module for hibernate at D:\project\switch/tmp/hibernate-ejb.jar
[echo] Packaging EAR Module for hibernate at D:\project\switch/JPAService.ear
[echo] Packaging D:\project\switch/tmp/test-JPAService.jar for running the tests
[echo] Undeploying JPAService from t3://localhost:7001 ...
[echo] Deploying JPAService to t3://localhost:7001 ...
[echo] Running JUnit Test: junit.TestJPAService ...
[junit] Logical Persistence Provider is [hibernate]
[junit] Actual Persistence Provider is [org.hibernate.impl.SessionImpl]
[junit] Persisted Message [id:1 timestamp:1182755464176 body:A message sent for logging on 1182755464166]
[junit] Time elapsed between the message to send and persisted is 10ms
重復測試表明已經用ID:2創建了新的消息。
我檢查了MySQL數據庫,發現當它的值配置為自動生成的時候,主鍵列標記為自動增加。
mysql> show create table message;
mysql>| message | CREATE TABLE `message` (
`id` bigint(20) NOT NULL auto_increment,
`body` varchar(255) default NULL,
`createdOn` datetime default NULL,
PRIMARY KEY (`id`)
The configuration that create the table definition for us is <property name="hibernate.hbm2ddl.auto" value="create"/>關于Hibernate部署的摘要
總結起來,在Weblogic Server 10.0環境中安裝和運行使用Hibernate的JPA應用程序步驟如下。
1. 在Weblogic Server 域中的共享庫里添加Hibernate庫
2. 配置JTA事務和自動的表定義屬性
3. 封裝、部署和運行測試進行驗證
現在來看一下要采用Kodo運行完全相同的應用程序,我們需要做些什么。
文章來源于領測軟件測試網 http://www.kjueaiud.com/