首先在SpringSource EBR上可以找到以下的jar 檔,
org.hibernate.ejb-library-3.3.1.ga.libd com.springsource.org.hibernate.annotations-3.4.0.GA-A.jar com.springsource.org.hibernate.annotations.common-3.3.0.ga.jar com.springsource.org.hibernate.ejb-3.4.0.GA-A.jar com.springsource.org.hibernate-3.3.2.GA.jar
這邊要注意版本的問題,org.hibernate.ejb-library-3.3.1.ga.libd裡面import的 bundle version可能跟下載的版本有些差異,如果碰到exception 可能要手動修改bundle裡面 Import-Package,Require-bundle 的版本資訊,這邊我有手動修改。 然後下面的是上面所需要的其他bundle
com.springsource.antlr-2.7.7.jar com.springsource.org.apache.commons.collections-3.2.0.jarz com.springsource.org.apache.commons.logging-1.1.1.jar com.springsource.org.dom4j-1.6.1.jar com.springsource.org.jgroups-2.5.1.jar com.springsource.javassist-3.9.0.GA.jar com.springsource.org.objectweb.asm-1.5.3.jar com.springsource.net.sf.ehcache-1.5.0.jar com.springsource.net.sf.jsr107cache-1.0.0.jar
然後將這些放到$EclipseVirgoHome/repository/usr 下,再來就能直接編寫測試用的bundle
先看看project結構
com.gfactor.service.iface 定義了service 的interface ,
com.gfactor.service.internal.dao 定義了dao interface & implements
com.gfactor.service.jpa 定義jpa 的pojo object
下面列出來的的檔案相同也用在JPA 2.0 + EclipseLink 的例子上,
Bndpageinfo entity
package com.gfactor.service.jpa; import java.io.Serializable; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.Table; @Entity @Table(name="bndpageinfo") public class Bndpageinfo implements Serializable{ @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private long id; @Column(name="bundle_name") private String bundle_name; @Column(name="bundle_version") private String bundle_version; @Column(name="entry_point") private String entry_point; @Column(name="class_name") private String class_name; public long getId() { return id; } public void setId(long id) { this.id = id; } public String getBundle_name() { return bundle_name; } public void setBundle_name(String bundle_name) { this.bundle_name = bundle_name; } public String getBundle_version() { return bundle_version; } public void setBundle_version(String bundle_version) { this.bundle_version = bundle_version; } public String getEntry_point() { return entry_point; } public void setEntry_point(String entry_point) { this.entry_point = entry_point; } public String getClass_name() { return class_name; } public void setClass_name(String class_name) { this.class_name = class_name; } @Override public String toString() { StringBuffer sb = new StringBuffer(); sb.append("print Bndpageinfo object : \n"); sb.append("id : " id "\n"); sb.append("bnudle_name : " bundle_name "\n"); sb.append("bundle_version : " bundle_version "\n"); sb.append("entry_point : " entry_point "\n"); sb.append("class_name : " class_name "\n"); return sb.toString(); } }
Providing the JPA metadata
<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_1_0.xsd" version="1.0"> <persistence-unit name="plugin-web-domain" transaction-type="RESOURCE_LOCAL"> <provider>org.hibernate.ejb.HibernatePersistence</provider> <class> com.gfactor.service.jpa.Bndpageinfo</class> <properties> <property name="hibernate.show_sql" value="true" /> <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect" /> <property name="hibernate.jdbc.batch_size" value="100" /> </properties> </persistence-unit> </persistence>
Service Layer
IRegisterWicketPageBndIdentify.java
package com.gfactor.service.iface; import com.gfactor.service.jpa.Bndpageinfo; public interface IRegisterWicketPageBndIdentify { public boolean registerPageInfo(Bndpageinfo bnd); public boolean unregisterPageInfo(Bndpageinfo bnd); }
RegisterWicketPageBndIdentifyImpl.java
package com.gfactor.service.iface.internal.impl; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.annotation.Transactional; import com.gfactor.service.iface.IRegisterWicketPageBndIdentify; import com.gfactor.service.internal.dao.RegWicketPageBndDao; import com.gfactor.service.jpa.Bndpageinfo; /** * @author momo * */ public class RegisterWicketPageBndIdentifyImpl implements IRegisterWicketPageBndIdentify { @Autowired private RegWicketPageBndDao regWicketPageBndDao; /* (non-Javadoc) * @see com.gfactor.service.iface.IRegisterWicketPageBndIdentify#registerPageInfo() */ @Transactional public boolean registerPageInfo(Bndpageinfo bnd) { System.out.println("registerPageInfo , bnd = " bnd); Bndpageinfo bndObj = regWicketPageBndDao.getBndPageInfo(bnd.getBundle_name(), bnd.getBundle_version(), bnd.getEntry_point()); System.out.println("registerPageInfo , bndObj = " bndObj); // List<Bndpageinfo> findObj = regWicketPageBndDao.findBndPageInfoList(bnd.getBundle_name(), bnd.getBundle_version(), bnd.getEntry_point()); // System.out.println("registerPageInfo , check findObj size = " findObj.size()); if(bndObj==null){ System.out.println("register page info......."); regWicketPageBndDao.saveBndPageInfo(bnd); return true; }else{ System.out.println("page info already exists.........."); return false; } } /* (non-Javadoc) * @see com.gfactor.service.iface.IRegisterWicketPageBndIdentify#unregisterPageInfo() */ @Transactional public boolean unregisterPageInfo(Bndpageinfo bnd) { Bndpageinfo bndObj = regWicketPageBndDao.getBndPageInfo(bnd.getBundle_name(), bnd.getBundle_version(), bnd.getEntry_point()); // List<Bndpageinfo> findObj = regWicketPageBndDao.findBndPageInfoList(bnd.getBundle_name(), bnd.getBundle_version(), bnd.getEntry_point()); // System.out.println("unregisterPageInfo , check findObj size = " findObj.size()); if(bndObj!=null){ System.out.println("unregister page info...."); regWicketPageBndDao.delete(bndObj); return true; }else{ System.out.println("no page info delete , object doesn't exists."); return false; } } }
DAO
RegWicketPageBndDao.java
package com.gfactor.service.internal.dao; import java.util.List; import com.gfactor.service.jpa.Bndpageinfo; public interface RegWicketPageBndDao { public ListfindUser(String bndName,String bndVer,String entry_point); public void saveUser(Bndpageinfo bndpageinfo); public Bndpageinfo update(Bndpageinfo bndpageinfo); public void delete(Bndpageinfo bndpageinfo); }
RegWicketPageBndDaoImpl.java
package com.gfactor.service.internal.dao.impl; import java.util.List; import javax.persistence.EntityManagerFactory; import javax.persistence.PersistenceUnit; import org.springframework.orm.jpa.support.JpaDaoSupport; import org.springframework.transaction.annotation.Transactional; import com.gfactor.service.internal.dao.RegWicketPageBndDao; import com.gfactor.service.jpa.Bndpageinfo; /** * @author momo * */ public class RegWicketPageBndDaoImpl extends JpaDaoSupport implements RegWicketPageBndDao { @PersistenceUnit private EntityManagerFactory entityManagerFactory; // /** // * Constructor // */ // @Autowired // public RegWicketPageBndDaoImpl(EntityManagerFactory entityManagerFactory) { // System.out.println("to set entityManagerFactory ="+ entityManagerFactory); // super.setEntityManagerFactory(entityManagerFactory); // } // /** * get Bndpageinfo object by bndname,bndver and entry_point */ public ListfindUser(String bndName, String bndVer, String entry_point) { return getJpaTemplate() .find("select r from Bndpageinfo r where r.bundle_name = ?1 and r.bundle_version =?2 and r.entry_point = ?3", bndName, bndVer, entry_point); } /* (non-Javadoc) * @see com.gfactor.service.internal.dao.RegWicketPageBndDao#saveUser(com.gfactor.service.internal.jpa.Bndpageinfo) */ public void saveUser(Bndpageinfo bndpageinfo) { System.out.println("save user " + bndpageinfo); System.out.println("to get getEntityManager =" + getJpaTemplate().getEntityManager()); System.out.println("to get getEntityManagerFactory =" + getJpaTemplate().getEntityManagerFactory()); getJpaTemplate().persist(bndpageinfo); System.out.println("to get getEntityManager =" + getJpaTemplate().getEntityManager()); } /* (non-Javadoc) * @see com.gfactor.service.internal.dao.RegWicketPageBndDao#update(com.gfactor.service.internal.jpa.Bndpageinfo) */ public Bndpageinfo update(Bndpageinfo bndpageinfo) { return getJpaTemplate().merge(bndpageinfo); } /* (non-Javadoc) * @see com.gfactor.service.internal.dao.RegWicketPageBndDao#delete(com.gfactor.service.internal.jpa.Bndpageinfo) */ public void delete(Bndpageinfo bndpageinfo) { getJpaTemplate().remove(bndpageinfo); } }
再來是Spring的設定, 因為這邊是deploy在osgi container上, 所以datasource 來源也是osgi service , 下面是bundle-context-osgi.xml & bundle-context.xml的設定
bundle-context-osgi.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:osgi="http://www.springframework.org/schema/osgi" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi.xsd"> <!-- definitions using elements of the osgi namespace can be included in this file. There is no requirement to keep these definitions in a separate file if you do not want to. The rationale for keeping these definitions separate is to facilitate integration testing of the bundle outside of an OSGi container --> <!-- import the DataSource from OSGi --> <osgi:reference id="dataSource" interface="javax.sql.DataSource" /> </beans>
bundle-context.xml for hibernate jpa 1.0
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation=" http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"> <!-- regular spring configuration file defining the beans for this bundle. The configuration of OSGi definitions is kept in a separate configuration file so that this file can easily be used for integration testing outside of an OSGi environment --> <!-- <context:load-time-weaver weaver-class="org.eclipse.equinox.weaving.springweaver.EquinoxAspectsLoadTimeWeaver" /> --> <context:load-time-weaver aspectj-weaving="on" /> <context:annotation-config /> <!-- --> <aop:aspectj-autoproxy /> <tx:annotation-driven mode="aspectj" transaction-manager="transactionManager"/> <!-- <tx:annotation-driven mode="proxy" proxy-target-class="true"></tx:annotation-driven> --> <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" /> <bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" /> <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> <property name="entityManagerFactory" ref="entityManagerFactory" /> </bean> <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> <property name="persistenceUnitName" value="plugin-web-domain"></property> <property name="dataSource" ref="dataSource"></property> <property name="jpaVendorAdapter"> <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"> <property name="showSql" value="true" /> <property name="generateDdl" value="true"/> <property name="databasePlatform" value="org.hibernate.dialect.MySQLInnoDBDialect" /> </property> </bean> <!-- <bean id="queryUserDao" class="com.dao.impl.QueryUserDaoImpl" > <property name="entityManagerFactory" ref="entityManagerFactory"/> </bean> --> <!-- defined dao bean start --> <bean id="regWicketPageBndDao" class="com.gfactor.service.internal.dao.impl.RegWicketPageBndDaoImpl"> <property name="entityManagerFactory" ref="entityManagerFactory" /> </bean> <bean id="registerWicketPageBndIdentify" class="com.gfactor.service.iface.internal.impl.RegisterWicketPageBndIdentifyImpl"> </bean> <!-- activator bean for register page info to database at bundle start time. --> <bean id="bndActivator" class="com.gfactor.service.BndActivator" init-method="start" destroy-method="stop"></bean> </beans>
MANIFEST.mf檔透過spring bundlor plugin可以生成,缺少的class 再手動補上就行,如果這邊想要JPA 2.0 + Hibernate 3.5↑的話就比較麻煩了一點,因為hibernate 給的jar檔是不支援osgi的,所以必須自己build一版出來,有需要的話可以參考下面的連結,
Creating custom Hibernate OSGi bundles for JPA 2.0
再來就要設定最麻煩的JPA 2.0 + EclipseLink 2.3, 下面的設定是目前的版本, 除了spring的設定 跟persistence.xml 的不同外,就是manifest.mf檔的improt-package要很完整,不然會跳一堆奇奇怪怪的exception出來....
JPA 2.0 + EclipseLink 2.3 Setting
先到EclipseLink 官網下載檔案,要選擇OSGI Bundle 版本的, Latest Release Downloads
下面的檔案放到$EclipseVirgoHome/repository/usr 下面
commonj.sdo_2.1.1.v200905221342.jar eclipselink-jpa-modelgen_2.3.0.v20110604-r9504.jar javax.persistence_2.0.3.v201010191057.jar javax.resource_1.5.0.jar javax.xml.bind_2.2.0.v201005080402.jar javax.xml.ws_2.0.0.v200902170419.jar org.eclipse.persistence.antlr_2.3.0.v20110604-r9504.jar org.eclipse.persistence.asm_2.3.0.v20110604-r9504.jar org.eclipse.persistence.core_2.3.0.v20110604-r9504.jar org.eclipse.persistence.dbws.builder_2.3.0.v20110604-r9504.jar org.eclipse.persistence.dbws_2.3.0.v20110604-r9504.jar org.eclipse.persistence.jpa.equinox.weaving_2.3.0.v20110604-r9504.jar org.eclipse.persistence.jpa.equinox_2.3.0.v20110604-r9504.jar org.eclipse.persistence.jpa.jpql_1.0.0.v20110604-r9504.jar org.eclipse.persistence.jpa.modelgen_2.3.0.v20110604-r9504.jar org.eclipse.persistence.jpa.osgi_2.3.0.v20110604-r9504.jar org.eclipse.persistence.jpa_2.3.0.v20110604-r9504.jar org.eclipse.persistence.moxy_2.3.0.v20110604-r9504.jar org.eclipse.persistence.oracle_2.3.0.v20110604-r9504.jar org.eclipse.persistence.sdo_2.3.0.v20110604-r9504.jar
然後這邊是已經有的(因為我的server用很久,不確定是否後來自己多加的,記的自我確認)
javax.activation_1.1.0.v201005080500.jar javax.jms_1.1.0.jar javax.mail_1.4.0.v201005080615.jar javax.persistence_1.0.0.v200905011740.jar javax.servlet_2.4.0.v200806031604.jar javax.transaction_1.1.0.v201002051055.jar javax.xml.soap_1.3.0.jar javax.xml.stream_1.0.1.v201004272200.jar
Providing the JPA metadata for EclipseLink
<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="plugin-web-domain" transaction-type="RESOURCE_LOCAL"> <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> <!-- <provider>org.hibernate.ejb.HibernatePersistence</provider> --> <class> com.gfactor.service.jpa.Bndpageinfo</class> <properties> <property name="eclipselink.weaving" value="true" /> </properties> <!-- <properties> <property name="hibernate.show_sql" value="true" /> <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect" /> <property name="hibernate.jdbc.batch_size" value="100" /> </properties> --> </persistence-unit> </persistence>
bundle-context.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation=" http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"> <!-- regular spring configuration file defining the beans for this bundle. The configuration of OSGi definitions is kept in a separate configuration file so that this file can easily be used for integration testing outside of an OSGi environment --> <!-- <context:load-time-weaver weaver-class="org.eclipse.equinox.weaving.springweaver.EquinoxAspectsLoadTimeWeaver" /> --> <context:load-time-weaver aspectj-weaving="on" /> <context:annotation-config /> <!-- --> <aop:aspectj-autoproxy /> <tx:annotation-driven mode="aspectj" transaction-manager="transactionManager"/> <!-- <tx:annotation-driven mode="proxy" proxy-target-class="true"></tx:annotation-driven> --> <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" /> <bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" /> <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> <property name="entityManagerFactory" ref="entityManagerFactory" /> </bean> <!-- <property name="persistenceUnitName" value="SM" /> --> <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> <property name="persistenceUnitName" value="plugin-web-domain"></property> <property name="dataSource" ref="dataSource"></property> <property name="jpaVendorAdapter"> <bean id="jpaVendorAdapter" class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter" p:databasePlatform="org.eclipse.persistence.platform.database.MySQLPlatform" p:showSql="true" /> </property> <property name="loadTimeWeaver"> <bean class="org.springframework.instrument.classloading.SimpleLoadTimeWeaver " /> </property> <!-- <property name="jpaVendorAdapter"> <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"> <property name="showSql" value="true" /> <property name="generateDdl" value="true" /> <property name="databasePlatform" value="org.hibernate.dialect.MySQLInnoDBDialect" /> </bean> </property> --> </bean> <!-- <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" p:dataSource-ref="dataSource" p:persistenceUnitName="plugin-web-domain"> <property name="jpaVendorAdapter"> <bean id="jpaVendorAdapter" class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter" p:databasePlatform="org.eclipse.persistence.platform.database.MySQLPlatform" p:showSql="true" /> </property> </bean> --> <!-- <bean id="queryUserDao" class="com.dao.impl.QueryUserDaoImpl" > <property name="entityManagerFactory" ref="entityManagerFactory"/> </bean> --> <!-- defined dao bean start --> <bean id="regWicketPageBndDao" class="com.gfactor.service.internal.dao.impl.RegWicketPageBndDaoImpl"> <property name="entityManagerFactory" ref="entityManagerFactory" /> </bean> <bean id="registerWicketPageBndIdentify" class="com.gfactor.service.iface.internal.impl.RegisterWicketPageBndIdentifyImpl"> </bean> <!-- activator bean for register page info to database at bundle start time. --> <bean id="bndActivator" class="com.gfactor.service.BndActivator" init-method="start" destroy-method="stop"></bean> </beans>這邊最主要的問題是context:load-time-weaver, tx:annotation-driven的設定,如果import-package有缺少的話並不一定會有exception,但是transaction可能因此失效,
後面會提到碰到過的issue,再來是完整的MANIFEST.mf檔
Manifest-Version: 1.0 Export-Package: com.gfactor.service;version="1.0.0";uses:="org.springframework.beans.factory.annotation", com.gfactor.service.iface;version="1.0.0";uses:="com.gfactor.service.jpa", com.gfactor.service.jpa;version="1.0.0";uses:="javax.persistence" Unversioned-Imports: * Built-By: momo Tool: Bnd-1.43.0 Bundle-Name: Spring OSGi Bundle for jpa bundle service layer Created-By: Apache Maven Bundle Plugin Bundle-Version: 1.0.0 Build-Jdk: 1.6.0_26 Bnd-LastModified: 1313477275968 Bundle-ManifestVersion: 2 Import-Library: org.springframework.spring;version="[3.0.3, 3.1)" Import-Package: com.mysql.jdbc, javax.persistence, javax.persistence.criteria, javax.persistence.metamodel, javax.persistence.spi, javax.sql, org.aopalliance.aop, org.aspectj.lang, org.aspectj.runtime.reflect, org.springframework.aop, org.springframework.aop.config, org.springframework.aop.aspectj, org.springframework.aop.aspectj.annotation, org.springframework.aop.aspectj.autoproxy, org.springframework.aop.framework, org.springframework.stereotype, org.springframework.core, org.springframework.context, org.springframework.context.config, org.springframework.context.weaving, org.springframework.beans, org.springframework.beans.factory, org.springframework.beans.factory.wiring, org.springframework.beans.factory.aspectj, org.springframework.beans.factory.support, org.springframework.beans.factory.config, org.springframework.beans.factory.annotation, org.springframework.dao.annotation, org.springframework.dao.support, org.springframework.orm.jpa, org.springframework.orm.jpa.support, org.springframework.orm.jpa.vendor, org.springframework.transaction, org.springframework.transaction.interceptor, org.springframework.transaction.support, org.springframework.transaction.annotation, org.springframework.transaction.aspectj, org.springframework.instrument.classloading, org.eclipse.persistence.jpa, org.eclipse.persistence.expressions, org.eclipse.persistence.internal.weaving, org.eclipse.persistence.internal.descriptors, org.eclipse.persistence.queries, org.eclipse.persistence.sessions, org.eclipse.persistence.descriptors.changetracking, net.sf.cglib.proxy, net.sf.cglib.core, net.sf.cglib.reflect Bundle-SymbolicName: plugin-webdomain-service.jpa-eplk
然後在BndActivator.java裡面做測試,在bundle start,如下
package com.gfactor.service; import org.springframework.beans.factory.annotation.Autowired; import com.gfactor.service.iface.IRegisterWicketPageBndIdentify; import com.gfactor.service.jpa.Bndpageinfo; public class BndActivator { @Autowired private IRegisterWicketPageBndIdentify registerWicketPageBndIdentify; public void start(){ System.out.println("to get registerWicketPageBndIdentify = " registerWicketPageBndIdentify); Bndpageinfo bndobj = new Bndpageinfo(); // bndobj.setId(10); bndobj.setBundle_name("test"); bndobj.setBundle_version("1.0.0"); bndobj.setClass_name("testPage"); bndobj.setEntry_point("test-main"); // registerWicketPageBndIdentify.registerPageInfo(bndobj); registerWicketPageBndIdentify.unregisterPageInfo(bndobj); // regWicketPageBndDao.update(bndobj); // List<Bndpageinfo> getobj = regWicketPageBndDao.findUser("test2", "1.0.1", "mains") ; // System.out.println("getobj = " getobj); } public void stop(){ } }沒問題的話可以在log看到transaction相關的log information,
to get registerWicketPageBndIdentify = com.gfactor.service.iface.internal.impl.RegisterWicketPageBndIdentifyImpl@158adc7 [2011-08-18 16:21:56.625] DEBUG region-dm-8 o.s.transaction.annotation.AnnotationTransactionAttributeSource Adding transactional method 'unregisterPageInfo' with attribute: PROPAGATION_REQUIRED,ISOLATION_DEFAULT; '' [2011-08-18 16:21:56.625] DEBUG region-dm-8 o.s.beans.factory.support.DefaultListableBeanFactory Returning cached instance of singleton bean 'transactionManager' [2011-08-18 16:21:56.625] DEBUG region-dm-8 org.springframework.orm.jpa.JpaTransactionManager Creating new transaction with name [com.gfactor.service.iface.internal.impl.RegisterWicketPageBndIdentifyImpl.unregisterPageInfo]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT; '' [2011-08-18 16:21:56.625] INFO region-dm-8 System.out [EL Info]: 2011-08-18 16:21:56.625--ServerSession(21139682)--Thread(Thread[region-dm-8,5,main])--EclipseLink, version: Eclipse Persistence Services - 2.3.0.v20110604-r9504 [2011-08-18 16:21:56.625] INFO region-dm-8 System.out [EL Config]: 2011-08-18 16:21:56.625--ServerSession(21139682)--Connection(30247146)--Thread(Thread[region-dm-8,5,main])--connecting(DatabaseLogin( [2011-08-18 16:21:56.625] INFO region-dm-8 System.out platform=>MySQLPlatform [2011-08-18 16:21:56.625] INFO region-dm-8 System.out user name=> "" [2011-08-18 16:21:56.625] INFO region-dm-8 System.out connector=>JNDIConnector datasource name=>null [2011-08-18 16:21:56.625] INFO region-dm-8 System.out )) [2011-08-18 16:21:56.625] INFO region-dm-8 System.out [EL Config]: 2011-08-18 16:21:56.625--ServerSession(21139682)--Connection(9801033)--Thread(Thread[region-dm-8,5,main])--Connected: jdbc:mysql://127.0.0.1:3306/test [2011-08-18 16:21:56.625] INFO region-dm-8 System.out User: root@localhost [2011-08-18 16:21:56.625] INFO region-dm-8 System.out Database: MySQL Version: 5.5.10 [2011-08-18 16:21:56.625] INFO region-dm-8 System.out Driver: MySQL-AB JDBC Driver Version: mysql-connector-java-5.1.15 ( Revision: ${bzr.revision-id} ) [2011-08-18 16:21:56.625] INFO region-dm-8 System.out [EL Config]: 2011-08-18 16:21:56.625--ServerSession(21139682)--Connection(7085189)--Thread(Thread[region-dm-8,5,main])--connecting(DatabaseLogin( [2011-08-18 16:21:56.625] INFO region-dm-8 System.out platform=>MySQLPlatform [2011-08-18 16:21:56.625] INFO region-dm-8 System.out user name=> "" [2011-08-18 16:21:56.625] INFO region-dm-8 System.out connector=>JNDIConnector datasource name=>null [2011-08-18 16:21:56.625] INFO region-dm-8 System.out )) [2011-08-18 16:21:56.625] INFO region-dm-8 System.out [EL Config]: 2011-08-18 16:21:56.625--ServerSession(21139682)--Connection(30977512)--Thread(Thread[region-dm-8,5,main])--Connected: jdbc:mysql://127.0.0.1:3306/test [2011-08-18 16:21:56.625] INFO region-dm-8 System.out User: root@localhost [2011-08-18 16:21:56.625] INFO region-dm-8 System.out Database: MySQL Version: 5.5.10 [2011-08-18 16:21:56.625] INFO region-dm-8 System.out Driver: MySQL-AB JDBC Driver Version: mysql-connector-java-5.1.15 ( Revision: ${bzr.revision-id} ) [2011-08-18 16:21:56.625] INFO region-dm-8 System.out [EL Info]: 2011-08-18 16:21:56.625--ServerSession(21139682)--Thread(Thread[region-dm-8,5,main])--file:/C:/Eclipse-Virgo-Tomcat-3.0/work/org.eclipse.virgo.kernel.deployer_3.0.0.RC1/staging/global/bundle/plugin-webdomain-service.jpa-eplk/1.0.0/plugin-webdomain-service.jpa-eplk.jar/_plugin-web-domain login successful [2011-08-18 16:21:56.625] DEBUG region-dm-8 org.springframework.orm.jpa.JpaTransactionManager Opened new EntityManager [org.eclipse.persistence.internal.jpa.EntityManagerImpl@33d742] for JPA transaction [2011-08-18 16:21:56.625] DEBUG region-dm-8 org.springframework.orm.jpa.JpaTransactionManager Exposing JPA transaction as JDBC transaction [SimpleConnectionHandle: jdbc:mysql://127.0.0.1:3306/test, UserName=root@localhost, MySQL-AB JDBC Driver] [2011-08-18 16:21:56.625] INFO region-dm-8 System.out [EL Fine]: 2011-08-18 16:21:56.625--ClientSession(33415531)--Connection(14317413)--Thread(Thread[region-dm-8,5,main])--SELECT ID, bundle_name, bundle_version, class_name, entry_point FROM bndpageinfo WHERE (((bundle_name = ?) AND (bundle_version = ?)) AND (entry_point = ?)) [2011-08-18 16:21:56.625] INFO region-dm-8 System.out bind => [test, 1.0.0, test-main] [2011-08-18 16:21:56.625] INFO region-dm-8 System.out unregisterPageInfo , check findObj size = 0 [2011-08-18 16:21:56.625] INFO region-dm-8 System.out no page info delete , object doesn't exists. [2011-08-18 16:21:56.625] DEBUG region-dm-8 org.springframework.orm.jpa.JpaTransactionManager Initiating transaction commit [2011-08-18 16:21:56.625] DEBUG region-dm-8 org.springframework.orm.jpa.JpaTransactionManager Committing JPA transaction on EntityManager [org.eclipse.persistence.internal.jpa.EntityManagerImpl@33d742] [2011-08-18 16:21:56.625] DEBUG region-dm-8 org.springframework.orm.jpa.JpaTransactionManager Closing JPA EntityManager [org.eclipse.persistence.internal.jpa.EntityManagerImpl@33d742] after transaction [2011-08-18 16:21:56.625] DEBUG region-dm-8 org.springframework.orm.jpa.EntityManagerFactoryUtils Closing JPA EntityManager
issue resolve :
整合中碰到的一個exception,
org.aspectj.weaver.tools.jdk14trace error : cannot register non aspect...,然後指向一個class , annotationasyncexecutionaspect,後來找到的問題出在Manifest.mf檔的package,從 Spring transactions with aspectj on Virgo這邊看到相關的問題,這種狀況在Transaction 為jdk proxy 時不會出問題,換成aspectj 後就會找不到transaction,當然最常出現的都是dependency 的問題:xD
Reference:
Wicket, Spring 3, JPA2 & Hibernate OSGi Application on Apache Karaf
Creating custom Hibernate OSGi bundles for JPA 2.0
WCreating an application with EclipseRT Virgo Web Server
EclipseLink with Spring - Can't persist into Db
在Eclise Virgo 上运行Struts2+Spring3+hibernate3.5
沒有留言:
張貼留言