Hello,
This is my second post on the same subject, maybe I was a bit unclear last time since I got no answer so I'll try again being a bit more specific.
Ok, here we go...
I have a POJO object called Category, which has child categories and a parent category. In my system I am using boh the EntityMode.MAP ( yes I know its a bit experimental but it fits like the glove for me, thats why) and the EntityMode.POJO to persist the category, Why?
Well all my objects are so called
MetadataObjects, which means that they have a Map where Im putting all the propety values into. I also have some getters and setters, which fools the user to belive it has acctual properties, while in reality they just do a put and get into the Map.
The getters and setters represenets values that are present in one database table, which I use to map the Category Object to:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="se.so4it.dam.api.category.CategoryImplementation" table="Category" lazy="false">
<id name="id" column="id" type="long" unsaved-value="null">
<generator class="native"/>
</id>
<property name="guid" column="guid" type="string" unique="true"/>
<property name="name" column="name" type="string"/>
<property name="level" column="level" type="integer"/>
<set name="categories" lazy="false" inverse="true" cascade="all">
<key column="parentId"/>
<one-to-many class="se.so4it.dam.api.category.CategoryImplementation"/>
</set>
<many-to-one name="parent" column="parentId" not-null="false" class="se.so4it.dam.api.category.CategoryImplementation"/>
<set name="records" lazy="false" table="CategoryToRecord" cascade="none">
<key column="categoryId"/>
<many-to-many class="se.so4it.dam.api.record.RecordImplementation" column="recordId"/>
</set>
</class>
</hibernate-mapping>
The map represnets values that are present in another database table, usually an allready existing one.
Code:
<class entity-name="FullCategoryMetadataModel" table="CategoryMetadata" lazy="false">
<id name="id" column="id" type="long" unsaved-value="null">
<generator class="native"/>
</id>
<property name="entityId" column="entityId" type="long"/>
<property name="guid" column="guid" type="string"/>
<property name="parentId" column="parentId" type="long"/>
<property name="name" column="name" type="string"/>
<property name="level" column="level" type="integer"/>
<property name="c0" column="c0" type="string"/>
<property name="c1" column="c1" type="string"/>
<property name="c2" column="c2" type="string"/>
<property name="c3" column="c3" type="string"/>
<property name="c4" column="c4" type="string"/>
</class>
I have a
MetadataModel concepts, where each a dynamical mapping like the one above represents a MetadataModel. I have a Swing GUI where the user can search and watch entities represented by these metadata models. The category is allways the same when it comes to the structural part, but I want to be able to create metadata models on the fly and tie them to the customers existing database.
Ok to the problem then...
I am using a JTA transaction, which I activate on the call to a command object. That command object in its turn uses a number of different DAO objects to persist my entities. So whatever I do inside the command gets commited or rollbacked when I leave the command object. Inside the command object I noramly first save the Category structure and then save the Category metadata, using a supplied metadata model. Both theses calls are acctualy using the values in the MAP. The Category save works fine but when saving with EntityMode.MAP (that is the acctual MAP where the values are present) nothing gets persisted.
So I'm in the same transaction, and first do a saveOrUpdate on the Category and the do a
Code:
Session mapSession = sessionFactory.getCurrentSession().getSession(EntityMode.Map)
mapSession.saveOrUpdate("metata model name",Map map)
When leaving the transaction the Category gets commited but the Map does not.
I realy dont know why, but can it be that Hibernate some how:
Do not se the Entity>Mode.MAP session as dirty
Do not allow for sessions that are created from the current session to be commited in the same transaction
What I would like to achive is to have a Spring interceptor load all the enteties for me using the JtaTransactionManager and then just let the commands do whatever and guaranteeing the uses that it will either be commited (if success) or rollbacked if failure.
I cant say enough how urgent it is that I solve this so if any one out there has some ideas it would be great.
Regards
Magnus
P:s Please tell me if you think this is an idiotic way of doing it and give some suggestion D:s