質問

今のところ、私は永続性を持つ作業Springアプリケーションを持っています。しかし、今、私は自分のデータベースアクティビティのすべてを行うにはJPAを使ったHibernateを使用したいです。私は、EntityManagerを使用して、これをやりたいです。

私はこの問題について多くの文書やチュートリアルを読んでいる、私はpersistence.xmlファイルかどうかを必要とするかどうかで混乱してきました。また、私はどのようにも設定私のapplicationContext.xmlをファイルをする上で混乱しなってきました。

誰でもEntityManagerを使用した春+休止+ JPA +を学ぶために見に良いサイトを知っていますか?

役に立ちましたか?

解決

私は、プロジェクトの同じ種類を設定しようとして数週間を費やしてきました。

あなたはpersistence.xmlファイルが必要です、そして、それはMETA-INFに属します。

ここでは、永続性のための私の春の豆ファイルの例です。

<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>

また、私はspring3に引くと、私は必要な依存関係を休止状態にMavenを使用しています。

編集:学習リソースのために、私は非常にゲイリー・マック<のhref =「http://www.apress.com/book/view/9781590599792」のrel =「noreferrer」で「春のレシピA問題-ソリューションアプローチ」をお勧めします> http://www.apress.com/book/view/9781590599792 を。これは私が今まで読んだ最高の技術的な本の一つであり、それは確かにあなたが立ち上がって春/ JPA / Hibernateで実行するのに役立ちます。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top