hi all!
somehow, hibernate doesnt load the contained objects of the requested object.
im loading a modulefolder, but the contained module is not loaded along with it.(see mapping)
why is that?
important parts of mapping below, full mapping file available here:
http://donhofer.net/mirror/hibernate/hibernate.hbm.xml
Ta, chris
Hibernate version:
3
Mapping documents:
Code:
<union-subclass entity-name="ModuleFolder" abstract="false" lazy="false" extends="LearningObject" table="`MODULEFOLDER`">
<meta attribute="eclassName">ModuleFolder</meta>
<meta attribute="epackage">lobj.ecore</meta>
<many-to-one name="folderMeta" entity-name="FolderMeta" cascade="delete,merge,persist,save-update,lock,refresh" lazy="false" insert="true" update="true" not-null="false">
<column not-null="false" unique="false" name="`FOLDERMETA_ID`"/>
</many-to-one>
<bag name="moduleFolder" lazy="true" cascade="delete,merge,persist,save-update,lock,refresh">
<key update="true">
<column name="`MODULEFOLDER_ID`" not-null="false" unique="false"/>
</key>
<one-to-many entity-name="ModuleFolder"/>
</bag>
<bag name="module" lazy="false" cascade="delete,merge,persist,save-update,lock,refresh">
<key update="true">
<column name="`MODULEFOLDER_ID`" not-null="false" unique="false"/>
</key>
<one-to-many entity-name="Module"/>
</bag>
<many-to-one name="accessControl" entity-name="AccessControl" cascade="delete,merge,persist,save-update,lock,refresh" lazy="false" insert="true" update="true" not-null="false">
<column not-null="false" unique="false" name="`ACCESSCONTROL_ID`"/>
</many-to-one>
</union-subclass>
Code between sessionFactory.openSession() and session.close():Code:
session = dataStore.getSessionFactory().openSession();
Transaction tx = session.getTransaction();
ResourceSet resourceSet = new ResourceSetImpl();
// Register the appropriate resource factory to handle all file extentions.
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put
("lobj",
new LobjResourceFactoryImpl());
// Register the package to ensure it is available during loading.
//
resourceSet.getPackageRegistry().put
(LobjPackage.eNS_URI,
LobjPackage.eINSTANCE);
//create resource
Resource rs = resourceSet.createResource(URI.createFileURI("dummy.lobj"));
// start transaction
tx.begin();
// query for object by ID
Query qry = session.createQuery("from "+eclassname+" where id='"+id+"'");
List list = qry.list();
for(Iterator iter = list.iterator(); iter.hasNext();){
EObject element = (EObject) iter.next();
rs.getContents().add(element);
for (Iterator featureIterator =
EcoreUtil.getAllContents(element, true);
featureIterator.hasNext(); ) {
EObject eObject = (EObject)featureIterator.next();
rs.getContents().add(eObject);
}
}
//serialize resource
String myObject = resourceToString(rs, encoding);
tx.commit();
session.close();
return myObject;
Name and version of the database you are using:
mysql 4.1.1