class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean"> <property name="persistenceUnitName" value="jpaspringPU" /> </bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> <property name="entityManagerFactory" ref="entityManagerFactory" /> </bean>
<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/> --和DAO中的@Transactional一起完成事务
<bean id="BookDAO" class="com.jpa.BookDAO"> <property name="entityManagerFactory" ref="entityManagerFactory" /> </bean> </beans>
POJO:
package com.jpa;
import javax.persistence.Column; 数据挖掘研究院 import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.Table;
import org.apache.lucene.analysis.standard.StandardAnalyzer; import org.hibernate.search.annotations.Analyzer; import org.hibernate.search.annotations.DocumentId; import org.hibernate.search.annotations.Field; import org.hibernate.search.annotations.Index; import org.hibernate.search.annotations.Indexed; import org.hibernate.search.annotations.Store;
@Entity @Indexed(index="汪云飞") @Analyzer(impl = StandardAnalyzer.class) @Table(name = "book", catalog = "test", uniqueConstraints = {}) public class Book implements java.io.Serializable { private static final long serialVersionUID = 1L; private Integer id; private String name;
public Book() { }
public Book(Integer id, String name) { 数据挖掘交友 this.id = id; this.name = name; }
@Id @DocumentId @GeneratedValue(strategy=GenerationType.IDENTITY) @Column(name = "id", unique = true, nullable = false, insertable = true, updatable = true) public Integer getId() { return this.id; }
public void setId(Integer id) { this.id = id; }
@Field(index=Index.TOKENIZED, store=Store.YES) @Column(name = "name", unique = false, nullable = false, insertable = true, updatable = true, length = 45)
|