JPA using Glassfish provided JPA provider (Toplink Essentials) and Derby
I have an EAR that contains the following components:
2 war modules
2 ejb modules
1 jar with entity classes and persistence.xml
The UI in the first war module uses a JMS queue whose MDB invokes a stateless session bean that access the entities. The MDB is marked as [i]@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)[/i] and the method in the stateless session bean is marked as [i]@TransactionAttribute(TransactionAttributeType.REQUIRED)
[/i]
The second war module invokes a separate stateless session bean that uses the same stateless session bean as above to access the entities and does not go through the JMS queue.
All entity access is via a container managed EntityManager located via injection.
There are two entities that I am having a problem with. One is a Chassis entity the the other is a ConfigurationSet entity. There is a bidirectional [i]@OneToMany[/i] relationship between the Chassis entity and its ConfigurationSet entities. The collection of ConfigurationSet's in the Chassis entity is annotated as:
[i] @OneToMany(mappedBy="configurableHardware", cascade={CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH}, fetch=FetchType.EAGER)
@OrderBy("id DESC")
private List<ConfigurationSet> configurations;
[/i]
When I add a ConfigurationSet to this list, I make sure that I set the "configurableHardware" property to this Chassis entity containing the list, so I am sure that I am wiring up both sides of the relationship correctly.
The war module that access the stateless session bean directly creates a Chassis with an initial ConfigurationSet and then adds 3 additional ConfigurationSet entities to the Chassis. This is all within one transaction and he method in the stateless session bean commits successfully and the correct database entries are made.
The war module that accesses the stateless session bean via the MDB retrieves the Chassis entity using a query and the Chassis entity is found. The problem is that ConfigurationSet collection when accessed through this Chassis entity only has one of the ConfigurationSet instances in the list. In fact it is the first ConfigurationSet entity that was added to the Chassis entity when it was created. The other 3 ConfigurationSet entities are not in the list.
If I shutdown the server and restart, then the war module that accesses the stateless session bean via the MDB will see all 4 ConfigurationSet entities. This seems to me to indicate a caching problem.
Since both war modules and both ejb modules and the jar module containing the persistence unit are located in the same EAR (at the top level), and all entity access is via a container managed injected EntityManager, it seems to me that these should be using the same session cache but it appears that they do not.
I wonder how I can determine if two session caches are being used?
Any help will be greatly appreciated.
[Message sent by forum member 'bbergquist' (bbergquist)]
http://forums.java.net/jive/thread.jspa?messageID=283629