[EJB 3.0 Users] - Persistence Context Transaction
by MarcusDidiusFalco
I am experimentig with JPA and I have difficulties to reproduce an example taken from JavaMagazin 9/09 about the ECB Pattern.
JBoss 5.1.0 GA, MySQL 5.0
The "boundary" (facade)
@Stateless
| public class OrderServiceBean implements OrderService {
|
|
|
| @EJB
| DeliveryService deliveryService;
|
| @EJB
| Warehouse warehouse;
|
| @TransactionAttribute(TransactionAttributeType.REQUIRED)
| public Order order(Order newOrder) throws BillingException {
|
| Order order = warehouse.checkout(newOrder);
|
|
| deliveryService.deliver(order);
| return order;
| }
| }
|
|
The Warehouse Bean persists the order. This works like expected:
| @Stateless
| public class WarehouseBean implements Warehouse {
|
| @PersistenceContext(unitName="ECB")
| EntityManager entityManager;
|
| @TransactionAttribute(TransactionAttributeType.MANDATORY)
| public Order checkout(Order order) {
| this.entityManager.merge(order);
| return order;
| }
| }
However the DeliveryService modifies the order:
| @Stateless
| public class DeliveryServiceBean implements DeliveryService{
|
| @TransactionAttribute(TransactionAttributeType.MANDATORY)
| public void deliver(Order order) {
| order.setDelivered(true);
| order.setProductId(2);
| }
| }
Since the transaction should be still running, I expect that order is still in the persistence context and that the changes made by the DeliveryService should be automatically persisted. However they never arrive in the database.
Do I get the whole concept or persistence context wrong? Or is there some bug in my code?
| <?xml version="1.0" encoding="UTF-8"?>
|
| <!-- $Id: mysql-ds.xml 71535 2008-04-01 07:05:03Z adrian(a)jboss.org $ -->
| <!-- Datasource config for MySQL using 3.0.9 available from:
| http://www.mysql.com/downloads/api-jdbc-stable.html
| -->
|
| <datasources>
| <local-tx-datasource>
| <jndi-name>ECBDS</jndi-name>
| <connection-url>jdbc:mysql://localhost:3306/ecb</connection-url>
| <driver-class>com.mysql.jdbc.Driver</driver-class>
| <user-name>root</user-name>
| <password>ritak1</password>
| <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-name>
| <!-- should only be used on drivers after 3.22.1 with "ping" support
| <valid-connection-checker-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLValidConnectionChecker</valid-connection-checker-class-name>
| -->
| <!-- sql to call when connection is created
| <new-connection-sql>some arbitrary sql</new-connection-sql>
| -->
| <!-- sql to call on an existing pooled connection when it is obtained from pool - MySQLValidConnectionChecker is preferred for newer drivers
| <check-valid-connection-sql>some arbitrary sql</check-valid-connection-sql>
| -->
|
| <!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) -->
| <metadata>
| <type-mapping>mySQL</type-mapping>
| </metadata>
| </local-tx-datasource>
| </datasources>
|
| <?xml version="1.0" encoding="UTF-8"?>
| <persistence:persistence version="1.0"
| xmlns:persistence="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 persistence_1_0.xsd">
| <persistence:persistence-unit name="ECB">
| <persistence:description>ECB</persistence:description>
| <persistence:jta-data-source>java:ECBDS</persistence:jta-data-source>
| <persistence:properties>
| <persistence:property name="hibernate.hbm2ddl.auto" value="create-drop" />
| <persistence:property name="dialect" value="org.hibernate.dialect.MySQLDialect" />
| <persistence:property name="hibernate.show_sql" value="true" />
| <persistence:property name="hibernate.format_sql" value="true" />
| </persistence:properties>
| </persistence:persistence-unit>
| </persistence:persistence>
|
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4268429#4268429
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4268429
14 years, 6 months
[Installation, Configuration & Deployment] - Can't access env-entry
by anukumar004
Hi,
I am using jboss-4.2.3.GA on solaris. I created a simple client.war application which tries to access an env-entry. I get the following error -
2009-12-02 00:08:24,358 INFO [STDOUT] ======================================================
2009-12-02 00:08:24,360 INFO [STDOUT]
2009-12-02 00:08:24,360 INFO [STDOUT] == Configuration Failure ==
2009-12-02 00:08:24,361 INFO [STDOUT]
2009-12-02 00:08:24,361 INFO [STDOUT] PropertiesManager(): Could not find java:comp/env/tapestry/property_file setting
2009-12-02 00:08:24,361 INFO [STDOUT] which is the variable that tells the framework where to find the properties file.
2009-12-02 00:08:24,361 INFO [STDOUT]
2009-12-02 00:08:24,361 INFO [STDOUT] ======================================================
The code is as follows
client.jsp
%@page contentType="text/html"
import="java.util.*,javax.naming.*"
%>
<%
String propertiesFile="";
try
{
Context initContext = new InitialContext();
propertiesFile=(String)initContext.lookup("java:comp/env/tapestry/property_file");
}
catch(Exception e)
{
System.out.println("======================================================");
System.out.println(" ");
System.out.println("== Configuration Failure ==");
System.out.println(" ");
System.out.println("PropertiesManager(): Could not find java:comp/env/tapestry/property_file setting");
System.out.println("which is the variable that tells the framework where to find the properties file.");
System.out.println(" ");
System.out.println("======================================================");
}
out.println(propertiesFile);
%>
WEB-INF/web.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<env-entry>
Path to config file
<env-entry-name>tapestry/property_file</env-entry-name>
<env-entry-value>/project/WORK/Web-gui/config/sm.properties</env-entry-value>
<env-entry-type>java.lang.String</env-entry-type>
</env-entry>
</web-app>
jndi tree
java:comp namespace of the client.war application:
+- UserTransaction[link -> UserTransaction] (class: javax.naming.LinkRef)
+- env (class: org.jnp.interfaces.NamingContext)
| +- security (class: org.jnp.interfaces.NamingContext)
| | +- realmMapping[link -> java:/jaas/other] (class: javax.naming.LinkRef)
| | +- subject[link -> java:/jaas/other/subject] (class: javax.naming.LinkRef)
| | +- securityMgr[link -> java:/jaas/other] (class: javax.naming.LinkRef)
| | +- security-domain[link -> java:/jaas/other] (class: javax.naming.LinkRef)
When I deploy client.war on the jboss-4.2.3.GA running on windows, the application runs fine. Can someone please help me with this ?
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4268418#4268418
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4268418
14 years, 6 months
[jBPM Users] - Re: Advice regarding complex proccess modeling
by saraswati.santanu
Hi,
This is a pretty late response. Out on a trip an could not access for few days.
The way you are creating sub tasks may not work. You should use command service to get your job done instead of using direct methods on tasks. Command service will ensure all the interceptors are invoked before a call is made to your command. One such interceptor will create a DBSession for you. A sample code should look like this:
| Task task = //get the parent task somehow
| //create a new task which is a child of the task above
| Task subTask = taskService.newTask(task.getId());
| subTask.setName(subTaskName);
| //this is important as this call will add this task to the sub task
| //set of the parent task. I believe this should have been done
| //during the previous call, but atleast now, it does not happen
| ((TaskImpl)task).addSubTask((TaskImpl)subTask);
|
Also there is a method in taskService to get sub tasks of a task, try using that when you need to get the sub tasks.
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4268414#4268414
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4268414
14 years, 6 months
[JBoss Cache Users] - Re: Concurrency problems - cache puts lost
by a.kluge
I extended the test a bit by adding transactions.
A minimal cache.xml:
| <?xml version="1.0" encoding="UTF-8"?>
| <jbosscache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
| xmlns="urn:jboss:jbosscache-core:config:3.0">
|
| <!-- Configure the TransactionManager -->
| <transaction transactionManagerLookupClass="org.jboss.cache.transaction.GenericTransactionManagerLookup
| "/>
|
| </jbosscache>
|
| TransactionManager txmanager = new DummyTransactionManagerLookup().getTransactionManager();
|
Then starting and ending a transaction around the put in the write thread:
| for (int id=1000*iteration + 100*writer; id<1000*iteration + 100*(writer+1); id++)
| {
| String key = "Key" + id;
| txmanager.begin();
| cache.put(FQN, key, VALUE);
| LOG.info("Putting " + key);
| Object result = cache.get(FQN, key);
| if (result == null)
| {
| LOG.error("Missing value for immediate get of " + key + ".");
| }
| txmanager.commit();
| result = cache.get(FQN, key);
| if (result == null)
| {
| LOG.error("Missing value for post transaction get of " + key + ".");
| }
| }
|
This produced some interesting results:
The immediate get never failed.
The post commit get failed sometimes.
The readthread get failed sometimes.
The readthread failed on items that the post commit thread successfully returned.
For example
anonymous wrote :
| $ grep "post transaction" errors.20091201.log | wc -l
| 228
| $ grep "Missing value for Key" errors.20091201.log | wc -l
| 3660
|
Next, I synchronized a section of the write thread:
| for (int id=1000*iteration + 100*writer; id<1000*iteration + 100*(writer+1); id++)
| {
| String key = "Key" + id;
| synchronized (LOCK_HOLDER)
| {
| txmanager.begin();
| cache.put(FQN, key, VALUE);
| LOG.info("Putting " + key);
| Object result = cache.get(FQN, key);
| if (result == null)
| {
| LOG.error("Missing value for immediate get of " + key + ".");
| }
| txmanager.commit();
| result = cache.get(FQN, key);
| if (result == null)
| {
| LOG.error("Missing value for post transaction get of " + key + ".");
| }
| }
| }
|
With this, I have no missed gets.
What happens if I move the commit outside of the synchronization block?
| for (int id=1000*iteration + 100*writer; id<1000*iteration + 100*(writer+1); id++)
| {
| String key = "Key" + id;
| synchronized (LOCK_HOLDER)
| {
| txmanager.begin();
| cache.put(FQN, key, VALUE);
| LOG.info("Putting " + key);
| Object result = cache.get(FQN, key);
| if (result == null)
| {
| LOG.error("Missing value for immediate get of " + key + ".");
| }
| }
| txmanager.commit();
| Object result = cache.get(FQN, key);
| if (result == null)
| {
| LOG.error("Missing value for post transaction get of " + key + ".");
| }
| }
|
Sure enough, the missing values issues return when the commit is not synchronized.
In my production code I have placed the cache writes (puts, remove, etc) inside of
synchronized blocks using a common lock object, and my data integrity issues
have vanished. However, the need for the synchronization in these cases was
definitely unexpected.
Alex
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4268403#4268403
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4268403
14 years, 6 months