English 中文(简体)
春季+春季数据 配置
原标题:Spring + Spring Data JPA Configuration

目前,我用春天套 around。 我的目标是利用日本宇宙开发公司获得使用日本宇宙开发公司名称的网上数据来源。 Im利用春天数据会使我的生活更加容易,并通过一些辅导来获得基本想法。

Bad thing: none of those is talking about the Spring configuration for my JPA szenario + I never worked with JPA / JDBC before. So I hope you can help me out here. I got 2 configuration files:

applicationContext.xml

<bean id="txManager"
    class="org.springframework.orm.jpa.JpaTransactionManager">
    <property name="sessionFactory" ref="sessionFactory" />
</bean>
<tx:annotation-driven transaction-manager="txManager" />

<bean id="eManager" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean"></bean>

由于在我的代码中使用了@Transactual annotion,在txManager使用由通知驱动的标签。 我不真的确定究竟应该怎样为txManager集思广益,以及会议工具正做些什么。 是否有所有得到支持的XML标签的文件? 我的一位公民没有进口标签?

了解电子管理,但不能确定这样做是否正确。

持久性。

<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="spring-jpa">
        <jta-data-source>jdbc/myJNDI</jta-data-source>
    </persistence-unit>
</persistence>

Same thing here: don t really know what i m doing. I know i need a persistence unit / provider. I know that many are using hibernate for this, but i would like to stay native and use pure JavaEE / Spring if possible. I m just not sure how to configure that. Currently my project is crashing, telling me: "JPA PersistenceProvider returned null"

最佳回答

获取<代码>的最佳途径 OrganagerFactory from the JNDI through Spring s JNDI support:

<jee:jndi-lookup id="entityManagerFactory" jndi-name="persistence/myPersistenceUnit" />

<jpa:repositories base-package="com.acme.repositories" />

<tx:jta-transactionManager />

这将使交易经理也从应用程序服务器上使用。 您还可以尝试建立从日本国际投资研究所获得的<条码>Jpa TransactionManager<>和<条码>。 如果你只通过<代码><jee:jndi-lookup /> 航天元件,并遵循春数据JPA参考文件中的进一步配置指示,你就可以将更多的配置输入你的春季会议卷宗。 然而,如果你决定完全使用集装箱资源,通常会更好使用你能够实际获得的集装箱资源。

问题回答

I just started working with Spring, jpa mysql etc... and I might be able to help you out. I ll show you the way that I have my configuration right know.

在我数据库连接的道路上使用秘密的电米,我从未这样做,我在那里没有帮助:

我的组合:

页: 1

<context:component-scan base-package="com.MYPACKAGE"/> 
<!-- To find all your controllers -->

<tx:annotation-driven/> 
<!-- This will pickup all your @Transactional annotations-->

<import resource="../database/DataSource.xml"/>
<import resource="../database/Hibernate.xml"/>
<!-- These are my database config files-->

数据来源:xml

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
    <property name="url" value="jdbc:mysql://localhost:3306/DATABASENAME"/>
    <property name="username" value="USERNAME"/>
    <property name="password" value="PASSWORD"/>
</bean>

Hibernate.xml:

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="dataSource" ref="dataSource"/>
    <property name="jpaVendorAdapter">
        <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
            <property name="showSql" value="false"/>
            <property name="generateDdl" value="true"/>
            <property name="databasePlatform" value="org.hibernate.dialect.MySQL5Dialect"/>
        </bean>
    </property>
</bean>

我删除了你需要列入您的xml档案顶端的标准Xml文本,但我相信你会去做;

This setup works for me and I hope it can help you out! If you have any question regarding this post please let me know!

Good luck!

对于那些使用“JBoss”的人,可以确定“jndi”名称。

    <persistence-unit name="punit" transaction-type="JTA">

      <provider>org.hibernate.ejb.HibernatePersistence</provider>
      <jta-data-source>java:/myDS/jta-data-source>

      <class>com.company.model.Document</class>
      <class>com.company.model.DocumentIndividual</class>

      <properties>
        <property name="hibernate.hbm2ddl.auto" value="create" />
        <!-- <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect"/> -->
        <property name="javax.persistence.logging.level" value="INFO" />
        <property name="hibernate.show_sql" value="true" />
        <property name="jboss.entity.manager.jndi.name" value="java:/my_em"/>
        <property name="jboss.entity.manager.factory.jndi.name" value="java:/my_emf"/>
    </properties>

</persistence-unit>





相关问题
Recommended way to develop using Jetty and Eclipse

I am currently developing a J2EE application and I would like to use Jetty. I would like to have iot integrated with Eclipse, so I could debug the appliaction. I ve tried out couple of plugins (...

Call function periodically in Java

we need run one function periodically in Java web application . How to call function of some class periodically ? Is there any way that call function when some event occured like high load in server ...

Why make an EJB rather than a Web Service?

I would have thought that there is a lot of information out there on this, but I haven t found anything that really answers my question. What are the advantages of making an EJB rather than a web ...

Where should I put this configuration setting?

I m designing a fairly small web application which will run on a Sun application server (v9.1). It only has a few pages, no database of its own, and will retrieve/update data via web services. There s ...

JNDI Names -- Is Prefix "jdbc/" needed?

What s up with JNDI names? I m trying to get a javax.sql.DataSource using the new annotations feature of Java 5. It s not working for me, so I want to ask... I have a in my web.xml, inside of it is ...

hibernate interceptors : afterTransactionCompletion

I wrote a Hibernate interceptor : public class MyInterceptor extends EmptyInterceptor { private boolean isCanal=false; public boolean onSave(Object entity, Serializable arg1, Object[] arg2, String[]...

热门标签