Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: JPA and Spring

  1. #1
    Join Date
    May 2007
    Posts
    16

    Default JPA and Spring

    Hi,
    Im using JPA with spring 2.0. Im not able to persist the object into the database though im able to select the same. Alos, when i try to insert in the database using the primary key already existing it gives me an integrity contraint error which means it tries to insert,. but is not commiting any value.

  2. #2

    Default

    Please, provide more information: code, mappings, log file, exceptions etc.

  3. #3
    Join Date
    May 2007
    Posts
    16

    Default

    Application Context
    <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryB ean">
    <property name="jndiName" value="java:comp/env/jdbc/VikramJFADS" />
    </bean>

    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerE ntityManagerFactoryBean">
    <property name="dataSource" ref="dataSource"/>
    <property name="jpaVendorAdapter">
    <bean class="org.springframework.orm.jpa.vendor.TopLinkJ paVendorAdapter">
    <property name="showSql" value="true"/>
    <property name="generateDdl" value="false"/>
    <property name="databasePlatform" value="oracle.toplink.essentials.platform.database .oracle.OraclePlatform"/>
    </bean>
    </property>

    <property name="loadTimeWeaver">
    <bean class="org.springframework.instrument.classloading .oc4j.OC4JLoadTimeWeaver"/>
    </property>
    </bean>

    <bean id="txProxyTemplate" abstract="true"
    class="org.springframework.transaction.interceptor .TransactionProxyFactoryBean">
    <property name="transactionManager"><ref bean="jfaTransactionManager"/></property>
    <property name="transactionAttributes">
    <props>
    <prop key="save*">PROPAGATION_REQUIRED</prop>
    <prop key="remove*">PROPAGATION_REQUIRED</prop>
    <prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
    </props>
    </property>
    </bean>

    <bean id="jfaTransactionManager" class="org.springframework.orm.jpa.JpaTransactionM anager">
    <property name="entityManagerFactory" ref="entityManagerFactory"/>
    <property name="dataSource" ref="dataSource"/>
    </bean>

    In the DAO I simply write getJpaTemplate().persist(Object)

    Is there any configuration to set commit=true?

  4. #4

    Default

    Fine, but what error you get when trying to persist an object?

  5. #5
    Join Date
    May 2007
    Posts
    16

    Default

    Thats what I dont even get any exception. But the problem is it does not persist any value in the database. If i try to persist with primary key already in database, it gives me an exception saying that key already exists, which means that it tries to persist atleast, but does not commit the value. Is there any configuration in the server or application context to set commit=true? I am using Oc4j server and oracle database.

  6. #6

    Default

    Enable debug logging in Spring and check if the transaction manager works as you intended. You should see transaction manager log entries. I haven't used
    toplink but try to enable their logging facility and see what's going on there.

  7. #7
    Join Date
    Sep 2007
    Location
    Cluj Napoca, Romania
    Posts
    9

    Default

    Hello. I have the exact same problem. We're using EJB3, but for inserting some initial data to the DB we use Spring. We configured it to work with JPA, but data is not actually persisted. We're using Hibernate as the underlying implementation. The same problem occurred while testing the beans with ejb3unit. All the selects worked fine, but the persist didn't. Any help would be greatly appreciated!

    Thanks!

  8. #8
    Join Date
    Sep 2007
    Location
    Cluj Napoca, Romania
    Posts
    9

    Lightbulb

    Hi. I managed to solve the problem. All I needed was an @Transactional on the dao implementations. It is rather normal. As long as you don't have a transaction, the entity manager cannot perform a commit and flush the data.

  9. #9
    Join Date
    May 2007
    Posts
    16

    Default

    well in my case it is not working.

  10. #10
    Join Date
    Sep 2007
    Location
    Cluj Napoca, Romania
    Posts
    9

    Default

    Hello. I will give u my configuration and maybe that will help u. Unfortunately, I can only do that on Friday. Sorry.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •