spring + jpa
来源:互联网 发布:淘宝店主客户端 编辑:程序博客网 时间:2024/05/22 17:14
applicationContext.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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd" xmlns:tx="http://www.springframework.org/schema/tx">
<bean
class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
<property name="persistenceUnitName" value="people"/>
</bean>
<bean id="transactionManager"
class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
<bean id="cmservice" class="com..cms.service.CmsServiceImpl" />
</beans>
persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" 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">
<persistence-unit name="people">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect" />
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />
<property name="hibernate.connection.username" value="root" />
<property name="hibernate.connection.password" value="root" />
<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/testjpa" />
<property name="hibernate.max_fetch_depth" value="5" />
<property name="hibernate.jdbc.fetch_size" value="20" />
<property name="hibernate.jdbc.batch_size" value="10" />
<property name="hibernate.hbm2ddl.auto" value="update" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="false" />
</properties>
</persistence-unit>
</persistence>
对象:
package com.cms.domain;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name = "person")
public class Person implements Serializable{
@Id
@GeneratedValue
private Integer id;
@Column(name = "NAME")
private String name;
public Person() {
// TODO Auto-generated constructor stub
}
public Person(Integer id) {
this.id = id;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
Service:
public interface ICmsService {
public void save(Person o);
}
@Transactional
public class CmsServiceImpl implements ICmsService {
private EntityManager em;
@PersistenceContext
public void setEntityManager(EntityManager em){
this.em = em;
}
public void save(Person entity) {
Assert.notNull(entity);
em.persist(entity);
return entity;
}
}
需要的lib包http://download.csdn.net/source/2560951
- spring + jpa
- spring+jpa
- Spring JPA
- spring jpa
- spring+jpa
- JPA+Spring
- spring-jpa
- spring JPA
- Jpa到Spring data jpa
- SPRING JPA 与 Hibernate JPA
- struts2+spring+jpa+ajax
- spring + compass+JPA整合
- struts2+spring+jpa(hibernate)
- spring集成jpa
- JPA + Spring + struts2 配置
- Spring 集成JPA
- jpa+spring+hibernate
- 整合Spring和JPA
- [windows] Netstate命令状态解析
- TNS/ORA-12500:TNS:监听未能启动一个专用服务器进程
- TNS/ORA-12500:TNS:监听未能启动一个专用服务器进程
- 查看windows的端口被哪个程序占用了
- if not to say it's different,
- spring + jpa
- java分页查询 Criteria
- 忘忧草
- 《数据结构》递归算法
- 只能输入数字JS方法
- mfc中显示opencv单通道视频
- js 判断浏览器类型
- 关于项目管理的观点
- [windows] 半开连接数