geronimo-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Jencks <david_jen...@yahoo.com>
Subject Re: CMP with OpenJPA on Apache Geronimo 3.0.1
Date Mon, 29 Dec 2014 16:03:44 GMT
It's been a few years….. IIRC the problem here is that your datasource is not set up correctly.
 Again IIRC you need both a transactional and a non-transactional datasource for the persistence-unit.
 Again IIRC this is more likely to work if the transactional datasource is XA.  The non transactional
datasource must be no-transaction.

hope this helps
david jencks

On Dec 29, 2014, at 10:35 AM, ivan frias <frias.ivan@gmail.com> wrote:

> Hi,
> Currently I am developing an application using OpenJPA . I've decide to use CMP to manage
the transactions.
> I am able to insert /edit and delete rows from the database ( through a configured Datasource
), however, it seems that transaction is only commited at Geronimo level. If I use the datasource
control to execute a query ( inside the management window on Geronimo ) I get the modified
rows, however If I try it outside the container ( e.g. using Sql Developer ) I can't see the
modifications.
> 
> Persistence.xml :
> 
> 
> <persistence-unit name="FleaCircus" transaction-type="JTA">
> 		<description>Flea Circus</description>
> 		<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
> 		<jta-data-source>FleaCircusOracleDS</jta-data-source>
> 		<class>de.carmedialab.db.entities.ApplicationItem</class>
> 		<class>de.carmedialab.db.entities.FleaResult</class>
> 		<class>de.carmedialab.db.entities.FleaResultType</class>
> 		<class>de.carmedialab.db.entities.ItemAttribute</class>
> 		<class>de.carmedialab.db.entities.ItemGroup</class>
> 		<class>de.carmedialab.db.entities.ItemType</class>
> 		<class>de.carmedialab.db.entities.ItemTypeAttribute</class>
> 		<class>de.carmedialab.db.entities.ItemTypeOperationAttribute</class>
> 		<class>de.carmedialab.db.entities.Operation</class>
> 		<class>de.carmedialab.db.entities.OperationAttribute</class>
> 		<class>de.carmedialab.db.entities.OperationType</class>
> 		<class>de.carmedialab.db.entities.Role</class>
> 		<class>de.carmedialab.db.entities.UserAccount</class>
> 		<class>de.carmedialab.db.entities.Measurement</class>
> 		<class>de.carmedialab.db.entities.MeasurementType</class>
> 		<class>de.carmedialab.db.entities.MeasurementAttribute</class>
> 		<class>de.carmedialab.db.entities.MeasurementAttributeType</class>
> 		<class>de.carmedialab.db.entities.Fleet</class>
> 
> 		<properties>
> 			<property name="openjpa.jdbc.SynchronizeMappings" value="validate" />
> 			<property
> 				name="openjpa.Compatibility.CheckDatabaseForCascadePersistToDetachedEntity"
> 				value="true" />
> 			  <!--<property name="openjpa.Log"
> 				value="DefaultLevel=WARN, Runtime=INFO, Tool=INFO, SQL=TRACE" />-->
> 		</properties>
> 	</persistence-unit>
> 
> 
> TestDaoImpl.java:
> 
> 
> package de.carmedialab.db.dao;
> 
> import java.util.Calendar;
> 
> import javax.ejb.Remote;
> import javax.ejb.Stateless;
> import javax.ejb.TransactionAttribute;
> import javax.ejb.TransactionAttributeType;
> import javax.persistence.EntityManager;
> import javax.persistence.PersistenceContext;
> import javax.persistence.PersistenceContextType;
> import javax.persistence.Query;
> 
> import de.carmedialab.db.entities.ApplicationItem;
> import de.carmedialab.db.entities.ItemType;
> 
> @Stateless
> @Remote(TestDao.class)
> public class TestDaoImpl implements TestDao{
> 	
> 	@PersistenceContext(type=PersistenceContextType.TRANSACTION)
> 	private EntityManager em;
> 
> 	@Override
> 	@TransactionAttribute(TransactionAttributeType.REQUIRED)
> 	public void save() {
> 
> 		try{			
> 			Query query = em.createQuery("select t from ItemType t where t.ittTypeName = :name");
> 			query.setParameter("name", "Passenger car");
> 			ItemType type = (ItemType)query.getSingleResult(); 
> 			
> 			ApplicationItem itm = new ApplicationItem();
> 			itm.setItemType(type);
> 			itm.setItmIsActive("Y");
> 			itm.setItmItemIdentifier("TEST");
> 			itm.setItmItemDescription("DESCRIPTION");
> 			itm.setItmItemName("NAME");
> 			itm.setItmInsertDate(Calendar.getInstance().getTime());
> 			itm.setItmInsertUser("SYSTEM");
> 			
> 			em.persist(itm);
> 			
> 			System.out.println("Item Persisted");
> 			
> 		}catch(Exception ex){
> 			ex.printStackTrace();
> 		} 
> 	}
> 
> 	@Override
> 	@TransactionAttribute(TransactionAttributeType.REQUIRED)
> 	public void delete() {
> 		try{
> 			Query query = em.createQuery("select i from ApplicationItem i where i.itmItemName
= :itmName");
> 			query.setParameter("itmName", "NAME");
> 			ApplicationItem itm = (ApplicationItem)query.getSingleResult();
> 			em.remove(itm); 
> 			System.out.println("Item Deleted");  
> 		}catch(Exception ex){
> 			ex.printStackTrace(); 
> 		}
> 	}
> }
> 
> 
> Best regards,
> Ivan Frias


Mime
View raw message