The architecture is:
MDB.onMessage()->Stateless SessionBean->DAO
All of this in the context of BMT.
Hibernate version: 3.2.4sp1
Mapping file:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.spbase.model">
<class name="FrameOrder" table="FRAME_ORDER">
<id name="key" column="FRAME_ORDER_PK"/>
<property name="orderNumber" not-null="true"/>
<property name="owningFacility" not-null="true"/>
<property name="creationDate" not-null="true"/>
<property name="state" not-null="true"/>
<list name="transactionCollection" table="FRAME_ORDER_TRANSACTION" cascade="all">
<key column="FRAME_ORDER_PK"/>
<list-index column="collIndex"/>
<many-to-many column="TRANSACTION_ID" class="FrameTransaction"/>
</list>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
The DAO has one method
Code:
public void saveUsing(OrderTransaction anOrderTransaction){
.....Ommitted code to look up the SessionFactory and other Exception handling stuff
UserTransaction utx = (UserTransaction) iniCtx.lookup*("java:comp/UserTransaction");
utx.begin();
Session hibSess = sessFact.getCurrentSession();
/*
Check to see if an existing order exists
*/
FrameOrder order = hibSess.get(FrameOrder.class,anOrderTransaction.getOrderNumber());
if(order == null){
log.info("creating a new FrameOrder using order# " + anOrderTransaction.getOrderNumber());
order = new FrameOrder(anOrderTransaction.getOrderNumber());
}
order.add(anOrderTransaction);
hibSess.saveOrUpdate(order);
utx.commit();
log.info("saved FrameOrder # " + anOrderTransaction.getOrderNumber());
}
I have some test transactions with duplicate order numbers, but, different transaction numbers. That is part of the business domain.
When the above code is executed. I see in the log entries that "creating a new FrameOrder using order# "AA227789" appears multiple times. When it clearly should NOT, since I'm checking to see if this order exists before creating a new one. By, all indications the order should have been persisted as of the first commit. One other odd thing that occurs. The log message "saved FrameOrder #, "
appears all at once, not as the transaction come in via the MessageQueue-MDB.
Also, I receive an Duplicate key exception from the DB upon commit of the Orders which have already been persisted. Also, even though my SessionFactory has 0 for the batch size. It appears as though the
commits are happening in batch mode. Which would explain why different threads can't see the order
via the hibSess.get().
Could someone please tell me what in the world is going on here. Thanks in advance.
DB Version:
MySQL 5.0.41
mysql jdbc connector 5.05