In My service layer i am using @transaction.From service i am calling DAO
Service layer code:
DAO COde:Code:@Component public class LocationImpl implements ILocation{ @Autowired private ILocationDao locationDaoImpl; @Override @Transactional(propagation=Propagation.REQUIRED,readOnly=false) public boolean addLocation(Location location) { System.out.println("Ganesha in service"); boolean saveFlag=locationDaoImpl.addLocation(location); return saveFlag; } }
Code:public class LocationDaoImpl implements ILocationDao{ @PersistenceContext(unitName="X") public EntityManager entitymanager; /*@PersistenceContext(unitName="X1") EntityManager em;*/ /*@Transactional*/ // commented public boolean addLocation(Location location) { entitymanager.persist(location); return true; } }
Business Object:
Code:@Entity @Table(name="LOCATION_NEW",schema="test") public class Location implements Serializable{ @Column(name="LOCATION_NAME") private String locationName; @Id @GeneratedValue(strategy=GenerationType.IDENTITY) @Column(name="LOCATION_ID") private long locationId; public String getLocationName() { return locationName; } public void setLocationName(String locationName) { this.locationName = locationName; } public long getLocationId() { return locationId; } public void setLocationId(long locationId) { this.locationId = locationId; } }
Spring Configuration:
<tx:annotation-driven />
<bean id="entitymanager"
class="org.springframework.orm.jpa.LocalContainerE ntityManagerFactoryBean">
<property name="persistenceUnitName" value="X" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.OpenJpaV endorAdapter" >
<property name="database" value="DB2" />
<property name="showSql" value="true" />
</bean>
</property>
</bean>
<bean class="org.springframework.orm.jpa.support.Persist enceAnnotationBeanPostProcessor" />
<tx:jta-transaction-manager />
Persistence xml:
<persistence-unit name="X" transaction-type="JTA">
<jta-data-source>jdbc/datasource</jta-data-source>
<class>com.businessobjects.Location</class>
<properties>
<property name="RuntimeUnenhancedClasses" value="supported"/>
</properties>
</persistence-unit>
When i run on Websphere application server,my location object is not saved.I am not getting any error.
If i put @Transaction on DAO addLocation method.it is getting saved.But i need to put on service layer so that i can call other DAo methods in the same transaction.
Console stackTrace is:
INFO [WebContainer : 2] openjpa.Runtime - Starting OpenJPA 2.1.1-SNAPSHOT
[2/14/13 22:53:50:868 IST] 00000032
SystemErr R 19494 TRACE [WebContainer : 2] openjpa.jdbc.SQL - <t 31882503, conn 29839727> executing stmnt 29839913 SELECT CURRENT SCHEMA FROM SYSIBM.SYSDUMMY1
[2/14/13 22:53:50:868 IST] 00000032
SystemErr R 19494 TRACE [WebContainer : 2] openjpa.jdbc.SQL - <t 31882503, conn 29839727> [0 ms] spent
Please help me.
Thanks
vaijesh


Reply With Quote