現在、永続性を備えたSpringアプリケーションが動作しています。しかし今は、JPAでHibernateを使用してすべてのデータベースアクティビティを実行したいと考えています。entitymanagerを使用してこれを実行したいです。
私はこの問題について多くのドキュメントとチュートリアルを読んでいますが、persistence.xmlファイルが必要かどうかについて混乱しています。また、applicationContext.xmlファイルの設定方法についても混乱しています。
EntityManagerを使用してSpring + Hibernate + JPA +を学習するために参照するのに適したサイトを知っている人はいますか?
私はここ数週間、同じ種類のプロジェクトを立ち上げるのに費やしたばかりです。
あなたは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/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-3.0.xsd
http://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" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<bean id="jpaTemplate" class="org.springframework.orm.jpa.JpaTemplate">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<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" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="whatisayis" />
<property name="dataSource" ref="dataSource" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="databasePlatform" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
<property name="showSql" value="true" />
<property name="generateDdl" value="true" />
</bean>
</property>
</bean>
<bean id="leDAO" class="com.noisyair.whatisayis.dao.jpa.JpaLearningEntryDAO">
<property name="jpaTemplate" ref="jpaTemplate" />
</bean>
<bean id="sampleDAO" class="com.noisyair.whatisayis.dao.jpa.JpaSampleDAO">
<property name="jpaTemplate" ref="jpaTemplate" />
</bean>
<bean id="tagDAO" class="com.noisyair.whatisayis.dao.jpa.JpaTagDAO">
<property name="jpaTemplate" ref="jpaTemplate" />
</bean>
</beans>
また、Mavenを使用して、必要なspring3およびhibernateの依存関係を取り込みます。
編集:学習リソースとして、Gary Mac http://www.apress.com/book/view/9781590599792による「Spring Recipes A Problem-Solution Approach」を強くお勧めします。これは私が今まで読んだ中で最高の技術書であり、Spring / JPA / Hibernateを使い始めるのに役立つでしょう。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加