我刚刚花了最后几个星期尝试建立相同类型的项目。
您确实需要一个persistence.xml文件,它属于meta-INF
这是我的持久性Spring bean文件的示例:
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.0.xsdhttp://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"><context:property-placeholder location="/WEB-INF/config.properties" /> <tx:annotation-driven /><bean id="transactionManager" > <property name="entityManagerFactory" ref="entityManagerFactory" /></bean><bean id="jpaTemplate" > <property name="entityManagerFactory" ref="entityManagerFactory" /></bean><bean id="dataSource" > <property name="driverClassName" value="${db.driver}" /> <property name="url" value="${db.url}" /> <property name="username" value="${db.user}" /> <property name="password" value="${db.password}" /></bean><bean id="entityManagerFactory" > <property name="persistenceUnitName" value="whatisayis" /> <property name="dataSource" ref="dataSource" /> <property name="jpaVendorAdapter"> <bean > <property name="databasePlatform" value="org.hibernate.dialect.MySQL5InnoDBDialect" /> <property name="showSql" value="true" /> <property name="generateDdl" value="true" /> </bean> </property></bean><bean id="leDAO" > <property name="jpaTemplate" ref="jpaTemplate" /></bean> <bean id="sampleDAO" > <property name="jpaTemplate" ref="jpaTemplate" /></bean> <bean id="tagDAO" > <property name="jpaTemplate" ref="jpaTemplate" /></bean></beans>另外,我正在使用Maven拉入我需要的spring3和hibernate依赖关系。
编辑:对于学习资源,我强烈推荐Gary Mac撰写的“ Spring Recipes A Problem-Solution
Approach”(http://www.apress.com/book/view/9781590599792)。这是我读过的最好的技术书籍之一,它肯定会帮助您使用Spring
/ JPA / Hibernate入门和运行。


![Spring + Hibernate + JPA [关闭] Spring + Hibernate + JPA [关闭]](http://www.mshxw.com/aiimages/31/393164.png)
