spring-jpa(hibernate实现)环境搭建

1,下载hibernate3.3.2,http://sourceforge.net/projects/hibernate/files/hibernate3/3.3.2.GA/hibernate-distribution-3.3.2.GA-dist.zip/download
和hibernate-entitymanager-3.4.0.GA.zip,hibernate-annotations-3.4.0.GA.rar(这里有hibernate注解包和针对jpa实现的包)。

2,解压文件hibernate-distribution-3.3.2.GA-dist.zip到目录hibernate-distribution-3.3.2.GA。

3,提取hibernate实现jpa所需jar包:
--------------------------- hibernate核心包,8个
1)hibernate-distribution-3.3.2.GA\hibernate3.jar
2)hibernate-distribution-3.3.2.GA\lib\bytecode\cglib\cglib-2.2.jar
3)hibernate-distribution-3.3.2.GA\lib\required\*.jar,6个
--------------------------- hibernate注解包,3个
4)hibernate-annotations-3.4.0.GA\hibernate-annotations.jar
5)hibernate-annotations-3.4.0.GA\ejb3-persistence.jar
6)hibernate-annotations-3.4.0.GA\hibernate-commons-annotations.jar
-------------------------- hibernate针对jpa实现的包,3个
7)hibernate-entitymanager-3.4.0.GA\hibernate-entitymanager.jar
8)hibernate-entitymanager-3.4.0.GA\lib\test\log4j.jar
9)hibernate-entitymanager-3.4.0.GA\lib\test\slf4j-log4j12.jar

4,spring的所需jar包

5,spring配置文件src\config\beans.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:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

<context:annotation-config/>

<!-- 集成jpa -->
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
<property name="persistenceUnitName" value="zqm"></property>
</bean>

<bean id="txManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"></property>
</bean>

<tx:annotation-driven transaction-manager="txManager" />

<bean id="userService" class="com.zqm.jpa.service.impl.UserServiceBean" />

<bean id="hello" class="com.zqm.jpa.web.HelloAction" />

</beans>


6,jpa配置文件src\META-INF\persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<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="zqm" transaction-type="RESOURCE_LOCAL">
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"></property>
<property name="hibernate.connection.username" value="root"></property>
<property name="hibernate.connection.password" value="root"></property>
<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/zqm?useUnicode=true&characterEncoding=UTF-8"></property>
<property name="hibernate.hbm2ddl.auto" value="update"/>
</properties>
</persistence-unit>
</persistence>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值