Showing posts with label emf. Show all posts
Showing posts with label emf. Show all posts

Monday, March 16, 2009

Use EMF and Riena

EMF, Teneo and Riena are great Eclipse projects. Use EMF to model your business objects and generate the Java code, use Teneo to persist through Hibernate and Riena to transfer your objects to the Eclipse RCP client and back. Isn't that sexy!

Nevertheless As I tried to use that setup, I ran into a few problems.
  • Transferring a 0...* reference causes an Exception: java.util.ArrayList ([...]) cannot be assigned to org.eclipse.emf.common.util.EList
  • Registered Adapters (EObjectImpl:eAdapters) can not be passed over the wire and causes Exception
  • In some cases I had trouble transferring the EObjectImpl:eProperties attribute
The way I figured to solve those issues, is the AbstractSerializerFactory.

Through extension points I can register my own EObjectSerializerFactory which uses my Deserialiser/Serializer for all EObjects.
My classes need to be in a "common" plug-in which is active on the server and client.
Both the EObjectSerializer and EObjectDeserializer are based on the JavaSerializer/JavaDeserializer provided by Caucho.

Basiclly all I do, is serializing the content of the EStructuralFeatures instead of serializing the Java fields.
So this way eFlags, eAdapters, eContainer, eContainerFeatureID and eProperties (EObjectImpl fields) are not passed over the wire.
I my case this works since I don't need the eContainer on the server.

Here the classes, maybe they help you to use the same combination:
EObjectSerializerFactory.java


/*******************************************************************************
* $URL: $
*
* Copyright (c) 2007 henzler informatik gmbh, CH-4106 Therwil
*******************************************************************************/
package com.softmodeler.service.communication;

import java.util.HashMap;
import java.util.Map;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EPackage;

import com.caucho.hessian.io.AbstractSerializerFactory;
import com.caucho.hessian.io.Deserializer;
import com.caucho.hessian.io.HessianProtocolException;
import com.caucho.hessian.io.Serializer;

/**
* EObjectSerializerFactory, provides a serializer and deserializer for EObjects
*
* @see EObjectSerializer
* @see EObjectDeserializer
* @author created by Author: fdo, last update by $Author: fdo $
* @version $Revision: 1236 $, $Date: 2009-03-03 22:51:32 +0100 (Di, 03 Mrz 2009) $
*/
public class EObjectSerializerFactory extends AbstractSerializerFactory {
/** class name suffix for implemented EClassifiers */
private static final String CLASS_SUFFIX = "Impl"; //$NON-NLS-1$
/** packages that should be excluded from reading */
private static final String[] EXCLUDE_PACKAGE_NS_URI = new String[] { "http://www.eclipse.org/emf/2002/Ecore" }; //$NON-NLS-1$

/** internal cache of all EClassifiers existing in the system, ClassifierName=>EClassifier */
private Map allClassifiers = null;

/**
* Returns a map with all relevant EClassifiers
*
* @return map ClassifierName=>EClassifier
*/
private Map getAllClassifiers() {
if (allClassifiers == null) {
allClassifiers = new HashMap();

// iterate the EPackages and place all classifiers in the allClassifiers map
for (Object value : EPackage.Registry.INSTANCE.values()) {
if (value instanceof EPackage) {
EPackage ePackage = (EPackage) value;
if (isValidPackage(ePackage.getNsURI())) {
for (EClassifier eClassifier : ePackage.getEClassifiers()) {
allClassifiers.put(eClassifier.getName(), eClassifier);
}
}
}
}
}
return allClassifiers;
}

/**
* Returns true if the package is valid (not in the EXCLUDE_PACKAGE_NS_URI list)
*
* @param nsURI the package NameSpace URI
* @return true if valid
*/
private boolean isValidPackage(String nsURI) {
for (String excludePackage : EXCLUDE_PACKAGE_NS_URI) {
if (excludePackage.equals(nsURI)) {
return false;
}
}
return true;
}

/**
* Returns the EClassifier for the passed Class
*
* @param cl
* @return returns null if the class is not an EObject or not found in the EPackages
*/
@SuppressWarnings("unchecked")
private EClass getClassifier(Class cl) {
if (EObject.class.isAssignableFrom(cl)) {
String name = cl.getSimpleName();
if (name.endsWith(CLASS_SUFFIX)) {
EClassifier classifier = getAllClassifiers().get(name.substring(0, name.indexOf(CLASS_SUFFIX)));
if (classifier instanceof EClass) {
return (EClass) classifier;
}
}
}
return null;
}

@SuppressWarnings("unchecked")
@Override
public Deserializer getDeserializer(Class cl) throws HessianProtocolException {
EClass classifier = getClassifier(cl);
if (classifier != null) {
return new EObjectDeserializer(classifier);
}
return null;
}

@SuppressWarnings("unchecked")
@Override
public Serializer getSerializer(Class cl) throws HessianProtocolException {
EClass classifier = getClassifier(cl);
if (classifier != null) {
return new EObjectSerializer(classifier);
}
return null;
}
}




EObjectSerializer.java


/*******************************************************************************
* $URL: $
*
* Copyright (c) 2007 henzler informatik gmbh, CH-4106 Therwil
*******************************************************************************/
package com.softmodeler.service.communication;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.impl.EObjectImpl;

import com.caucho.hessian.io.AbstractHessianOutput;
import com.caucho.hessian.io.AbstractSerializer;
import com.caucho.hessian.io.JavaSerializer;

/**
* Serializes EObjects, this class is based on the {@link JavaSerializer} instead of working with java fields,
* {@link EStructuralFeature} are used to serialize the 'data' values of the {@link EObject}.

* Java fields of the {@link EObjectImpl}; eAdapters, eFlags, eContainer, eContainerFeatureID and eProperties are
* ignored
*
* @see JavaSerializer
* @author created by Author: fdo, last update by $Author: fdo $
* @version $Revision: 1151 $, $Date: 2009-02-25 22:47:19 +0100 (Mi, 25 Feb 2009) $
*/
public class EObjectSerializer extends AbstractSerializer {
private List fieldSerializers;
private List fields;

/**
* constructor
*
* @param classifier
*/
@SuppressWarnings("unchecked")
public EObjectSerializer(EClass classifier) {
fields = classifier.getEAllStructuralFeatures();
fieldSerializers = new ArrayList();

for (EStructuralFeature feature : fields) {
if (!feature.isMany()) {
EClassifier eDataType = feature.getEType();
Class type = eDataType.getInstanceClass();
fieldSerializers.add(getFieldSerializer(type));
} else {
fieldSerializers.add(ListFieldSerializer.SER);
}
}
}

@SuppressWarnings("unchecked")
@Override
public void writeObject(Object obj, AbstractHessianOutput out) throws IOException {
if (out.addRef(obj)) {
return;
}

Class cl = obj.getClass();

int ref = out.writeObjectBegin(cl.getName());

if (ref < -1) { writeObject10((EObject) obj, out); } else { if (ref == -1) { writeDefinition20(out); out.writeObjectBegin(cl.getName()); } writeInstance((EObject) obj, out); } } private void writeObject10(EObject obj, AbstractHessianOutput out) throws IOException { for (int i = 0; i < feature =" fields.get(i);" i =" 0;" feature =" fields.get(i);" ser =" new" value =" null;" value =" obj.eGet(feature);" ser =" new" value =" false;" value =" (Boolean)" ser =" new" value =" 0;" value =" (Integer)" ser =" new" value =" 0;" value =" (Long)" ser =" new" value =" 0;" value =" (Double)" ser =" new" value =" null;" value =" (String)" ser =" new" value =" null;" objvalue =" (List)" value =" new">



EObjectDeserializer.java


/*******************************************************************************
* $URL: $
*
* Copyright (c) 2007 henzler informatik gmbh, CH-4106 Therwil
*******************************************************************************/
package com.softmodeler.service.communication;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.impl.EObjectImpl;
import org.eclipse.emf.ecore.util.EcoreUtil;

import com.caucho.hessian.io.AbstractHessianInput;
import com.caucho.hessian.io.AbstractMapDeserializer;
import com.caucho.hessian.io.HessianFieldException;
import com.caucho.hessian.io.IOExceptionWrapper;
import com.caucho.hessian.io.JavaDeserializer;

/**
* Deserializes EObjects, this class is based on the {@link JavaDeserializer} instead of working with java fields,
* {@link EStructuralFeature} are used to deserialize the 'data' values of the {@link EObject}.

* Java fields of the {@link EObjectImpl}; eAdapters, eFlags, eContainer, eContainerFeatureID and eProperties are
* ignored
*
* @see JavaDeserializer
* @author created by Author: fdo, last update by $Author: fdo $
* @version $Revision: 1236 $, $Date: 2009-03-03 22:51:32 +0100 (Di, 03 Mrz 2009) $
*/
public class EObjectDeserializer extends AbstractMapDeserializer {
private Map fieldMap;
private EClass classifier;

/**
* constructor
*
* @param classifier
*/
public EObjectDeserializer(EClass classifier) {
this.classifier = classifier;
fieldMap = getFieldMap(classifier);
}

@SuppressWarnings("unchecked")
@Override
public Class getType() {
return classifier.getInstanceClass();
}

@Override
public Object readMap(AbstractHessianInput in) throws IOException {
try {
EObject obj = instantiate();

return readMap(in, obj);
} catch (IOException e) {
throw e;
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new IOExceptionWrapper(classifier.getName() + ":" + e.getMessage(), e); //$NON-NLS-1$
}
}

@Override
public Object readObject(AbstractHessianInput in, String[] fieldNames) throws IOException {
try {
Object obj = instantiate();
return readObject(in, (EObject) obj, fieldNames);
} catch (IOException e) {
throw e;
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new IOExceptionWrapper(classifier.getName() + ":" + e.getMessage(), e); //$NON-NLS-1$
}
}

public Object readMap(AbstractHessianInput in, EObject obj) throws IOException {
try {
int ref = in.addRef(obj);

while (!in.isEnd()) {
Object key = in.readObject();

FieldDeserializer deser = fieldMap.get(key);

if (deser != null) {
deser.deserialize(in, obj);
} else {
in.readObject();
}
}

in.readMapEnd();

in.setRef(ref, obj);
return obj;
} catch (IOException e) {
throw e;
} catch (Exception e) {
throw new IOExceptionWrapper(e);
}
}

public Object readObject(AbstractHessianInput in, EObject obj, String[] fieldNames) throws IOException {
try {
int ref = in.addRef(obj);

for (String name : fieldNames) {
FieldDeserializer deser = fieldMap.get(name);

if (deser != null) {
deser.deserialize(in, obj);
} else {
in.readObject();
}
}

in.setRef(ref, obj);
return obj;
} catch (IOException e) {
throw e;
} catch (Exception e) {
throw new IOExceptionWrapper(obj.getClass().getName() + ":" + e, e); //$NON-NLS-1$
}
}

/**
* create an instance of the passed classifier
*
* @return
* @throws Exception
*/
protected EObject instantiate() throws Exception {
return EcoreUtil.create(classifier);
}

/**
* Creates a map featureName=>FieldDeserializer.
*/
@SuppressWarnings("unchecked")
protected Map getFieldMap(EClass classifier) {
Map fieldMap = new HashMap();

for (EStructuralFeature feature : classifier.getEAllStructuralFeatures()) {
if (feature.isTransient() || fieldMap.containsKey(feature.getName())) {
continue;
}
FieldDeserializer deser;

EClassifier eDataType = feature.getEType();
Class type = eDataType.getInstanceClass();

if (String.class.equals(type)) {
deser = new StringFieldDeserializer(feature);
} else if (byte.class.equals(type)) {
deser = new ByteFieldDeserializer(feature);
} else if (short.class.equals(type)) {
deser = new ShortFieldDeserializer(feature);
} else if (int.class.equals(type)) {
deser = new IntFieldDeserializer(feature);
} else if (long.class.equals(type)) {
deser = new LongFieldDeserializer(feature);
} else if (float.class.equals(type)) {
deser = new FloatFieldDeserializer(feature);
} else if (double.class.equals(type)) {
deser = new DoubleFieldDeserializer(feature);
} else if (boolean.class.equals(type)) {
deser = new BooleanFieldDeserializer(feature);
} else if (feature.isMany()) {
deser = new EListDeserializer(feature);
} else {
deser = new ObjectFieldDeserializer(feature);
}

fieldMap.put(feature.getName(), deser);
}
return fieldMap;
}

abstract static class FieldDeserializer {
protected EStructuralFeature feature;

public FieldDeserializer(EStructuralFeature feature) {
this.feature = feature;
}

abstract void deserialize(AbstractHessianInput in, EObject obj) throws IOException;

}

static class EListDeserializer extends FieldDeserializer {

EListDeserializer(EStructuralFeature feature) {
super(feature);
}

@SuppressWarnings("unchecked")
@Override
void deserialize(AbstractHessianInput in, EObject obj) throws IOException {
List value = null;

try {
value = (List) in.readObject(List.class);
if (value.size() > 0) {
obj.eSet(feature, value);
}
} catch (Exception e) {
logDeserializeError(feature, obj, value, e);
}
}
}

static class ObjectFieldDeserializer extends FieldDeserializer {

ObjectFieldDeserializer(EStructuralFeature feature) {
super(feature);
}

@Override
void deserialize(AbstractHessianInput in, EObject obj) throws IOException {
Object value = null;

try {
value = in.readObject(feature.getEType().getInstanceClass());

if (value != null) {
obj.eSet(feature, value);
}
} catch (Exception e) {
logDeserializeError(feature, obj, value, e);
}
}
}

static class BooleanFieldDeserializer extends FieldDeserializer {
BooleanFieldDeserializer(EStructuralFeature feature) {
super(feature);
}

@Override
void deserialize(AbstractHessianInput in, EObject obj) throws IOException {
boolean value = false;

try {
value = in.readBoolean();

obj.eSet(feature, value);
} catch (Exception e) {
logDeserializeError(feature, obj, value, e);
}
}
}

static class ByteFieldDeserializer extends FieldDeserializer {
ByteFieldDeserializer(EStructuralFeature feature) {
super(feature);
}

@Override
void deserialize(AbstractHessianInput in, EObject obj) throws IOException {
int value = 0;

try {
value = in.readInt();

obj.eSet(feature, value);
} catch (Exception e) {
logDeserializeError(feature, obj, value, e);
}
}
}

static class ShortFieldDeserializer extends FieldDeserializer {
ShortFieldDeserializer(EStructuralFeature feature) {
super(feature);
}

@Override
void deserialize(AbstractHessianInput in, EObject obj) throws IOException {
int value = 0;

try {
value = in.readInt();

obj.eSet(feature, value);
} catch (Exception e) {
logDeserializeError(feature, obj, value, e);
}
}
}

static class IntFieldDeserializer extends FieldDeserializer {
IntFieldDeserializer(EStructuralFeature feature) {
super(feature);
}

@Override
void deserialize(AbstractHessianInput in, EObject obj) throws IOException {
int value = 0;

try {
value = in.readInt();

obj.eSet(feature, value);
} catch (Exception e) {
logDeserializeError(feature, obj, value, e);
}
}
}

static class LongFieldDeserializer extends FieldDeserializer {
LongFieldDeserializer(EStructuralFeature feature) {
super(feature);
}

@Override
void deserialize(AbstractHessianInput in, EObject obj) throws IOException {
long value = 0;

try {
value = in.readLong();

obj.eSet(feature, value);
} catch (Exception e) {
logDeserializeError(feature, obj, value, e);
}
}
}

static class FloatFieldDeserializer extends FieldDeserializer {
FloatFieldDeserializer(EStructuralFeature feature) {
super(feature);
}

@Override
void deserialize(AbstractHessianInput in, EObject obj) throws IOException {
double value = 0;

try {
value = in.readDouble();

obj.eSet(feature, value);
} catch (Exception e) {
logDeserializeError(feature, obj, value, e);
}
}
}

static class DoubleFieldDeserializer extends FieldDeserializer {
DoubleFieldDeserializer(EStructuralFeature feature) {
super(feature);
}

@Override
void deserialize(AbstractHessianInput in, EObject obj) throws IOException {
double value = 0;

try {
value = in.readDouble();

obj.eSet(feature, value);
} catch (Exception e) {
logDeserializeError(feature, obj, value, e);
}
}
}

static class StringFieldDeserializer extends FieldDeserializer {
StringFieldDeserializer(EStructuralFeature feature) {
super(feature);
}

@Override
void deserialize(AbstractHessianInput in, EObject obj) throws IOException {
String value = null;

try {
value = in.readString();

obj.eSet(feature, value);
} catch (Exception e) {
logDeserializeError(feature, obj, value, e);
}
}
}

static void logDeserializeError(EStructuralFeature feature, Object obj, Object value, Throwable e)
throws IOException {
String fieldName = (feature.getContainerClass().getName() + "." + feature.getName()); //$NON-NLS-1$

if (e instanceof HessianFieldException) {
throw (HessianFieldException) e;
} else if (e instanceof IOException) {
throw new HessianFieldException(fieldName + ": " + e.getMessage(), e); //$NON-NLS-1$
}

if (value != null) {
throw new HessianFieldException(fieldName + ": " + value.getClass().getName() + " (" + value + ")" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ " cannot be assigned to " + feature.getEType().getName()); //$NON-NLS-1$
} else {
throw new HessianFieldException(fieldName + ": " + feature.getEType().getName() //$NON-NLS-1$
+ " cannot be assigned from null", e); //$NON-NLS-1$
}
}
}

Tuesday, December 2, 2008

Generic Hibernate DAO

I intended to create a post about Hibernate subselects, but I decided to post the whole Generic Hibernate DAO.

A short briefing of the surrounding system.
I have different child classes of "BasicObject" they all got an according "ObjectRef" which is a small object (id,name,locale) used as reference on the larger BasicObject (like in a tree or document content). The reference object and the BasicObject have the same id (UUID).
The whole software is a server/client application using Eclipse EMF to model, generate and handle the business objects, Eclipse Riena for remoting and Hibernate/Teneo for persistence. Ohh and for sure Eclipse RCP as client. Isn't the Eclipse movement great :-).

To the subselects, I used them in the search(...) method.
The search() restricts the select on BasicObject fields and returns a list of ObjectRefs. This saves us a lot of bandwidth since BasicObjects can have n fields of any size and the ObjectRef only has three.
The first query (DetachedCriteria) which is restricted based on the BasicObject fields (i.e. name LIKE 'test' AND description LIKE 'Start%') is used to restrict the actual query on ObjectRef using the result (ids) of the DetachedCriteria query.

As for the rest of the class, it's a Generic Hibernate Data Access Object even though the name ends in "Service". I just combined the Service and DAO, since in our case, it doesn't make sense to separate them.
Maybe the create() method is a bit confusing, that's because we use the Eclipse Modeling Framework to create the business objects.

BasicObjectService.java


/*******************************************************************************
* $RCSfile: $ Copyright (c) 2007 henzler informatik gmbh, CH-4106 Therwil
*******************************************************************************/
package com.softmodeler.service.impl;

import java.lang.reflect.ParameterizedType;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Property;
import org.hibernate.criterion.Restrictions;

import com.softmodeler.model.BasicObject;
import com.softmodeler.model.ObjectRef;
import com.softmodeler.service.IBasicObjectService;
import com.softmodeler.service.ModelUtil;

/**
* The BasicObjectService implements the default handling for all BasicObject sub services
*
* @author created by Author: fdo, last update by $Author: $
* @version $Revision: $, $Date: $
*/
public abstract class BasicObjectService implements
IBasicObjectService {
/** The Hibernate Session */
protected Session session;
/** The Entity Manager */
protected EntityManager entityManager;

/**
* The constructor
*
* @param session
* @param entityManager
*/
public BasicObjectService(Session session, EntityManager entityManager) {
this.session = session;
this.entityManager = entityManager;
}

/**
* Returns the class of the BasicObject
*
* @return
*/
@SuppressWarnings("unchecked")
protected Class getObjectClass() {
return (Class) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];

}

/**
* Returns the class of the ObjectRef
*
* @return
*/
@SuppressWarnings("unchecked")
protected Class getRefClass() {
return (Class) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[1];
}

/**
* Begins a Transaction
*
* @return
*/
protected EntityTransaction beginTransaction() {
EntityTransaction transaction = entityManager.getTransaction();
if (!transaction.isActive()) {
transaction.begin();
}
return transaction;
}

@SuppressWarnings("unchecked")
@Override
public K create() {
// create the objects using the according EPackage
EPackage modelPackage = ModelUtil.getModelPackage();
EPackage refPackage = ModelUtil.getRefPackage();
EClass objectEClass = (EClass) modelPackage.getEClassifier(getObjectClass().getSimpleName());
EClass refEClass = (EClass) refPackage.getEClassifier(getRefClass().getSimpleName());
K object = (K) modelPackage.getEFactoryInstance().create(objectEClass);
V ref = (V) refPackage.getEFactoryInstance().create(refEClass);

// set the ids
object.setId(EcoreUtil.generateUUID());
ref.setId(object.getId());

// store objects in the database
EntityTransaction transaction = beginTransaction();
session.save(object);
session.save(ref);
transaction.commit();
return object;
}

@SuppressWarnings("unchecked")
@Override
public void delete(K object) {
EntityTransaction transaction = beginTransaction();

// load first, to prevent delete problems
Criteria criteria = session.createCriteria(getObjectClass());
criteria.add(Restrictions.eq(ID, object.getId()));
K loadedObject = (K) criteria.uniqueResult();

Criteria criteriaRef = session.createCriteria(getRefClass());
criteriaRef.add(Restrictions.eq(ID, object.getId()));
V loadedRef = (V) criteria.uniqueResult();

session.delete(loadedObject);
session.delete(loadedRef);
transaction.commit();
}

@SuppressWarnings("unchecked")
@Override
public List findAllRefs() {
Criteria critica = session.createCriteria(getRefClass());
return critica.list();
}

@SuppressWarnings("unchecked")
@Override
public K findById(String uuid) {
Criteria criteria = session.createCriteria(getObjectClass());
criteria.add(Restrictions.eq(ID, uuid));
return (K) criteria.uniqueResult();
}

@SuppressWarnings("unchecked")
@Override
public K findByRef(V ref) {
Criteria criteria = session.createCriteria(getObjectClass());
criteria.add(Restrictions.eq(ID, ref.getId()));
return (K) criteria.uniqueResult();
}

@SuppressWarnings("unchecked")
@Override
public V getRef(K object) {
Criteria criteria = session.createCriteria(getRefClass());
criteria.add(Restrictions.eq(ID, object.getId()));
return (V) criteria.uniqueResult();
}

@Override
public void store(K object) {
EntityTransaction transaction = beginTransaction();
entityManager.merge(object);
transaction.commit();
}

@Override
public void storeRef(ObjectRef ref) {
EntityTransaction transaction = beginTransaction();
entityManager.merge(ref);
transaction.commit();
}


@SuppressWarnings("unchecked")
@Override
public List search(Map fieldValues) {
DetachedCriteria objCritica = DetachedCriteria.forEntityName(getObjectClass().getSimpleName(), "obj");
for (String field : fieldValues.keySet()) {
objCritica.add(Restrictions.like(field, fieldValues.get(field)));
}
objCritica.setProjection(Property.forName(ID));
Criteria criteria = session.createCriteria(getRefClass());
criteria.add(Property.forName(ID).in(objCritica));
return criteria.list();
}
}



Here the according interface:
IBasicObjectService.java


/*******************************************************************************
* $RCSfile: $ Copyright (c) 2007 henzler informatik gmbh, CH-4106 Therwil
*******************************************************************************/
package com.softmodeler.service;

import java.util.List;
import java.util.Map;

import com.softmodeler.model.BasicObject;
import com.softmodeler.model.ObjectRef;

/**
* @author created by Author: fdo, last update by $Author: $
* @version $Revision: $, $Date: $
*/
public interface IBasicObjectService {
/** Id field */
public static final String ID = "id";

/**
* Creates, stores and returns an object
*
* @return
*/
K create();

/**
* Creates, stores and returns an object reference
*
* @return
*/
V getRef(K object);

/**
* Deletes an object
*
* @param object
*/
void delete(K object);

/**
* Stores an object
*
* @param object
*/
void store(K object);

/**
* Stores a reference object
*
* @param ref
*/
void storeRef(V ref);

/**
* Finds an object, by it's uuid
*
* @param AutoJobRef
* @return
*/
K findById(String uuid);

/**
* Finds an object, using it's reference object
*
* @param ref
* @return
*/
K findByRef(V ref);

/**
* Returns a list containing all ref objects
*
* @return
*/
List findAllRefs();

/**
* Searches ObjectRefs using the passed map to create the query
*
* @param fieldValues field name => value
* @return
*/
List search(Map fieldValues);
}