I used the Spring2.0M3 and Hibernate EntityManager3.1.6 beta
Here is my configuration:
persistence.xml,(NO hibernate.cfg.xml)
And then my mapping file:Code:<?xml version="1.0" encoding="UTF-8"?> <persistence> <persistence-unit name="ebEntityManager" transaction-type="RESOURCE_LOCAL"> <provider>org.hibernate.ejb.HibernatePersistence</provider> <class>com.jl.eb.dao.Category</class> <class>com.jl.eb.dao.CategoryItem</class> <properties> <property name="hibernate.dialect" value="org.hibernate.dialect.DB2Dialect" /> <property name="hibernate.connection.driver_class" value="com.ibm.db2.jcc.DB2Driver" /> <property name="hibernate.connection.password" value="db2admin" /> <property name="hibernate.connection.url" value="jdbc:db2://10.1.1.10:50000/dbjl" /> <property name="hibernate.connection.username" value="db2admin" /> <property name="hibernate.ejb.autodetection" value="class" /> <property name="hibernate.max_fetch_depth" value="3"/> </properties> </persistence-unit> </persistence>
and then,I have two spring config fileCode:package com.jl.eb.dao; import java.math.*; import java.util.*; import javax.persistence.*; import java.text.*; @Entity @Table(name = "category", schema = "eb", uniqueConstraints = {}) public class Category implements java.io.Serializable { private String id; private String compId; private String name; private String no; private Integer level; private String desc; private String parentId; private String sysEmp; private Date sysDate; private Set<CategoryItem> categoryItem = new HashSet<CategoryItem>(); @Id @Column(name = "id", length = 32) public String getId() { return this.id; } public void setId(String id) { this.id = id;} @Column(name = "comp_Id", length = 20) public String getCompId() {return this.compId;} public void setCompId(String compId) {this.compId = compId;} @Column(name = "name", length = 60) public String getName() {return this.name;} public void setName(String name) {this.name = name;} @Column(name = "no", length = 13) public String getNo() {return this.no;} public void setNo(String no) {this.no = no;} @Column(name = "level") public Integer getLevel() {return this.level;} public void setLevel(Integer level) {this.level = level;} public void setLevel(String value) {this.level = Integer.parseInt(value);} @Column(name = "desc", length = 60) public String getDesc() {return this.desc;} public void setDesc(String desc) {this.desc = desc;} @Column(name = "parent_id", length = 32) public String getParentId() {return this.parentId;} public void setParentId(String parentId) {this.parentId = parentId;} @Column(name = "sys_emp", length = 20) public String getSysEmp() {return this.sysEmp;} public void setSysEmp(String sysEmp) {this.sysEmp = sysEmp;} @Column(name = "sys_date", length = 10) public Date getSysDate() {return this.sysDate;} public void setSysDate(Date sysDate) {this.sysDate = sysDate;} public void setSysDate(String value) throws ParseException { value = value.replace("-", ""); value = value.replace("/", ""); this.sysDate = new SimpleDateFormat("yyyyMMdd").parse(value); } @OneToMany(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY, mappedBy = "category") public Set<CategoryItem> getCategoryItem() {return this.categoryItem;} public void setCategoryItem(Set<CategoryItem> categoryItem) {this.categoryItem = categoryItem;} } package com.jl.eb.dao; import java.math.*; import java.util.*; import javax.persistence.*; import java.text.*; @Entity @Table(name = "category_item", schema = "eb", uniqueConstraints = {}) public class CategoryItem implements java.io.Serializable { private String id; private String no; private String desc; private String sysEmp; private Date sysDate; private Category category; @Id @Column(name = "id", length = 32) public String getId() { return this.id; } public void setId(String id) {this.id = id;} @Column(name = "no", length = 3) public String getNo() { return this.no;} public void setNo(String no) {this.no = no;} @Column(name = "desc", length = 100) public String getDesc() {return this.desc;} public void setDesc(String desc) {this.desc = desc;} @Column(name = "sys_emp", length = 20) public String getSysEmp() {return this.sysEmp;} public void setSysEmp(String sysEmp) {this.sysEmp = sysEmp;} @Column(name = "sys_date", length = 10) public Date getSysDate() {return this.sysDate;} public void setSysDate(Date sysDate) {this.sysDate = sysDate;} public void setSysDate(String value) throws ParseException { value = value.replace("-", ""); value = value.replace("/", ""); this.sysDate = new SimpleDateFormat("yyyyMMdd").parse(value); } @ManyToOne(cascade = {}, fetch = FetchType.LAZY) @JoinColumn(name = "category_id", unique = false, nullable = true, insertable = true, updatable = true) public Category getCategory() { return this.category;} public void setCategory(Category category) {this.category = category;} }
spring_dao.xml
spring_logic.xmlCode:<?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:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation= "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd"> <bean id="ebEntityManagerFactory" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean"> <property name="entityManagerName" value="ebEntityManager"/> <property name="jpaProperties"><props></props></property> </bean> <bean id="ebTransactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> <property name="entityManagerFactory" ref="ebEntityManagerFactory" /> </bean> <bean id="ebTransactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor"> <property name="transactionManager" ref="ebTransactionManager" /> <property name="transactionAttributeSource"> <bean class="org.springframework.transaction.annotation.AnnotationTransactionAttributeSource" /> </property> </bean> <bean id="ebTransactionAttributeSourceAdvisor" class="org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor"> <property name="transactionInterceptor" ref="ebTransactionInterceptor"/> </bean> <bean id="ebOpenEMinView" class="org.springframework.orm.jpa.support.OpenEntityManagerInViewInterceptor"> <property name="entityManagerFactory" ref="ebEntityManagerFactory"/> </bean> <!-- DAO start --> <bean id="eb_CategoryDAO" class="com.jl.eb.dao.CategoryDAO"> <property name="entityManagerFactory" ref="ebEntityManagerFactory" /> </bean> <bean id="eb_CategoryItemDAO" class="com.jl.eb.dao.CategoryItemDAO"> <property name="entityManagerFactory" ref="ebEntityManagerFactory" /> </bean> </beans>
Code:<?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:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation= "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd"> <bean id="EbCategoryMainLogic" class="com.jl.eb.logic.EbCategoryMainLogic"> <property name="dao"> <ref bean="eb_CategoryDAO"/> </property> </bean> <bean id="EbCategoryItemLogic" class="com.jl.eb.logic.EbCategoryItemLogic"> <property name="dao"> <ref bean="eb_CategoryItemDAO"/> </property> <property name="cateDao"> <ref bean="eb_CategoryDAO"/> </property> </bean> <bean id="EbjcClass_Tree" class="com.jl.eb.tree.EbjcClass_Tree"> <property name="dao"> <ref bean="eb_CategoryDAO"/> </property> </bean> </beans>


Reply With Quote