-
Aug 25th, 2007, 07:21 AM
#1
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.
-
Aug 26th, 2007, 03:03 AM
#2
Please, provide more information: code, mappings, log file, exceptions etc.
-
Aug 27th, 2007, 07:03 AM
#3
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?
-
Aug 27th, 2007, 03:26 PM
#4
Fine, but what error you get when trying to persist an object?
-
Aug 28th, 2007, 01:16 AM
#5
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.
-
Aug 28th, 2007, 01:46 AM
#6
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.
-
Sep 3rd, 2007, 06:30 AM
#7
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!
-
Sep 3rd, 2007, 08:20 AM
#8
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.
-
Sep 4th, 2007, 02:23 AM
#9
well in my case it is not working.
-
Sep 4th, 2007, 02:46 PM
#10
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
-
Forum Rules