I use Couch DB with Ektorp at Spring 3. I read the document and have tried to implement examples. I am so new to these technologies. This is the point where I didn't understand:
#View( name = "all", map = "function(doc) { if (doc.type == 'Sofa' ) emit( null, doc._id )}")
public class SofaRepository extends CouchDbRepositorySupport<Sofa> {
#View( name = "avg_sofa_size", map = "function(doc) {...}", reduce = "function(doc) {...}")
public int getAverageSofaSize() {
ViewResult r = db.queryView(createQuery("avg_sofa_size"));
return r.getRows().get(0).getValueAsInt();
}
}
How does that wievs work and how to define them, what happens at that lines?
CouchDbRepositorySupport out of the box provides the following methods to the SofaRepository:
public void add(Sofa entity);
public void update(Sofa entity);
public void remove(Sofa entity);
public Sofa get(String id);
public Sofa get(String id, String rev);
public List<T> getAll();
public boolean contains(String docId);
By having this inline view annotation for CouchDbRepositorySupport:
#View( name = "all", map = "function(doc) { if (doc.type == 'Sofa' ) emit( null, doc._id )}")
You redefine the return from a getAll() method.
You also adding another method getAverageSofaSize() to your repository, with inline View:
#View( name = "avg_sofa_size", map = "function(doc) {...}", reduce = "function(doc) {...}")
which explicitly provides a query that db.queryView(createQuery("avg_sofa_size")); undersntad. db here is a CouchDbConnector that is able to create, delete, purge, find, etc..
Take a look at more documentation about defining in line Views
Related
I have this design which I self-proclaim to be Composite Pattern, though I'm not entirely sure about that. So I'm aksing for your statement on this.
This is the interface which collectively describes all of them
public interface DomainResourceBuilder<T extends DomainResource> {
T buildInsertion(T persistence, EntityManager entityManager) throws Exception;
T buildUpdate(T model, T persistence, EntityManager entityManger);
<E extends T> DomainResourceBuilder<E> and(DomainResourceBuilder<E> next);
}
This one describes DomainResourceBuilder as a pair
public abstract class AbstractDomainResourceBuilder<D extends
DomainResource> implements DomainResourceBuilder<D> {
#Override
public <E extends D> DomainResourceBuilder<E>
and(DomainResourceBuilder<E> next) {
return new CompositeDomainResourceBuilder<>(this, next);
}
private class CompositeDomainResourceBuilder<T extends D>
extends AbstractDomainResourceBuilder<T> {
private final DomainResourceBuilder<D> parentBuilder;
private final DomainResourceBuilder<T> childBuilder;
public
CompositeDomainResourceBuilder(DomainResourceBuilder<D>
parentBuilder,
DomainResourceBuilder<T> childBuilder) {
super();
this.parentBuilder = parentBuilder;
this.childBuilder = childBuilder;
}
#SuppressWarnings("unchecked")
#Override
public T buildInsertion(T model, EntityManager
entityManager) throws Exception {
return childBuilder.buildInsertion((T)
parentBuilder.buildInsertion(model, entityManager),
entityManager);
}
#SuppressWarnings("unchecked")
#Override
public T buildUpdate(T model, T persistence,
EntityManager entityManger) {
return childBuilder.buildUpdate(model, (T)
parentBuilder.buildUpdate(model, persistence,
entityManger), entityManger);
}
}
}
Concrete class plays the Leaf role
public class CustomerBuilder extends AbstractDomainResourceBuilder<Customer> {
#Override
public
Customer buildInsertion(Customer persistence, EntityManager entityManager) throws Exception {
return persistence;
}
#Override
public
Customer buildUpdate(Customer model, Customer persistence, EntityManager entityManger) {
return persistence;
}
}
Can I call this a Composite Pattern?
This is how I use it. Assumming I have the following hierarchy.
AbstractEntity
|___User
|___Customer
Now I want to implement different logics on each class, so with the design I'll create specific logic for those class and then ultimately compose them into one, which is still one of their kind. Something like this.
// group of objects
DomainResourceBuilder<AbstractEntity> abstractEntityBuilder = new AbstractEntityBuilder<>();
DomainResourceBuilder<User> userBuilder = new UserBuilder<>();
DomainResourceBuilder<Customer> customerBuilder = new CustomerBuilder<>();
// treat them as a whole (unify them all)
DomainResourceBuilder<Customer> compositeCustomerBuilder =
abstractEntityBuilder
.and(userBuilder)
.and(customerBuilder);
I do not think that it looks like Composite pattern as:
there is no a place where a group of objects that are treated the same way as a single instance of the same type of object.
In my view, it looks like it uses Builder pattern with generics that can treat hierarchy of entities.
UPDATE:
In my view it is not group of objects:
// group of objects
DomainResourceBuilder<AbstractEntity> abstractEntityBuilder = new AbstractEntityBuilder<>();
DomainResourceBuilder<User> userBuilder = new UserBuilder<>();
DomainResourceBuilder<Customer> customerBuilder = new CustomerBuilder<>();
If the above objects will be put in collection, then it can be called as group of objects. In my honour opinion, it is just object variables.
In the following lines of code, Fluent interface design pattern can be seen as methods can be chained:
// treat them as a whole (unify them all)
DomainResourceBuilder<Customer> compositeCustomerBuilder =
abstractEntityBuilder
.and(userBuilder)
.and(customerBuilder);
Let me show an example where group of objects can be treat as a whole.
The following literature has great examples and explanations:
this beautiful, very cool and interesting book by Eric Freeman
this article about composite pattern at wiki
this article about composite pattern at codemaze
Imagine you are building browser and you want to show controls. Your task is to show values of all of your controls placed in DOM browser.
So example code would look like this.
We need some base class for controls:
public abstract class ControlBase
{
protected string name;
protected string value;
public ControlBase(string name, string value)
{
this.name = name;
this.value = value;
}
public abstract string ShowValue();
}
and its operations:
public interface IControlOperations
{
void Add(ControlBase gift);
void Remove(ControlBase gift);
}
Then we create a composite control where we can have group of objects:
public class CompositeControl : ControlBase, IControlOperations
{
// group of objects
private List<ControlBase> _controls;
public CompositeControl(string name, string value)
: base(name, value)
{
_controls = new List<ControlBase>();
}
public void Add(ControlBase gift)
{
_controls.Add(gift);
}
public void Remove(ControlBase gift)
{
_controls.Remove(gift);
}
// group of objects can be treat as a whole
public override string ShowValue()
{
StringBuilder allValues = new StringBuilder();
Console.WriteLine($"{name} has the following values:");
foreach (var gift in _controls)
{
allValues.AppendLine(gift.ShowValue());
}
return allValues.ToString();
}
}
And our UI controls:
public class TextBox : ControlBase
{
public TextBox(string name, string value)
: base(name, value)
{
}
public override string ShowValue()
{
Console.WriteLine($"{name} has {value}");
return value;
}
}
public class CheckBox : ControlBase
{
public CheckBox(string name, string value)
: base(name, value)
{
}
public override string ShowValue()
{
Console.WriteLine($"{name} with value {value}");
return value;
}
}
And then we can call code like this:
var textBox_Phone = new TextBox("textBox_Phone", "1");
textBox_Phone.ShowValue();
Console.WriteLine();
//composite control
var divContainer = new CompositeControl("divContainer", string.Empty);
var textBox_Name = new TextBox("textBox_Name", "Joseph");
var textBox_Surname = new TextBox("textBox_Surname", "Albahari");
divContainer.Add(textBox_Name);
divContainer.Add(textBox_Surname);
Console.WriteLine($"Total values of this composite control " +
$"is: {divContainer.ShowValue()}");
I have a few repositories that extend org.springframework.data.mongodb.repository.MongoRepository. I have added some methods for searching entities by different parameters, however, in any search, I only want to search for entities that have the active field set to true (have opted for marking as active=false in place of deleting). For example, two sample repositories would look like this:
interface XxRepository extends MongoRepository<Xx, String> {
Optional<Xx> findOneByNameIgnoreCaseAndActiveTrue(String name)
Page<Xx> findByActiveTrue(Pageable pageable)
Xx findOneByIdAndActiveTrue(String id)
}
interface YyRepository extends MongoRepository<Yy, String> {
Optional<Yy> findOneByEmailAndActiveTrue(String email)
}
Is there any way that would allow me not to add byActiveTrue\ andActiveTrue to each and every method and set it up somewhere in one place for all the queries?
Please try this. No need to provide implementation. Change 'active' and 'email' to your db column name.
interface YyRepository extends MongoRepository<Yy, String> {
#Query(value = "{ 'active' : { '$eq': true }, 'email' : ?0 }")
Optional<Yy> findOneByEmailAndActiveTrue(#Param("email") String email)
}
You can write an template query into the MongoRepository using Criteria.
Example
class abstract MongoRepository<W, X> {
protected Class<W> typeOfEntity;
private Class<X> typeOfId;
public MongoRepository() {
typeOfEntity = (Class<W>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];
typeOfId = (Class<X>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];
}
public W get(X id) throws Exception {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<W> q = cb.createQuery(typeOfEntity);
Root<W> r = q.from(typeOfEntity);
String idName = CommonEntity.findIdFieldName(typeOfEntity);
Predicate andClose = cb.and(cb.equal(r.get("active"), true));
q.where(cb.equal(r.get(idName), id), andClose);
return em.createQuery(q).getSingleResult();
}
}
After that, you stay confident into the object running way ans stereotyping to run the good type of request.
The findIdFieldNameis an method using the #Id to get the id field name.
public abstract class CommonEntity implements Serializable {
public static String findIdFieldName(Class cls) {
for (Field field : cls.getDeclaredFields()) {
String name = field.getName();
Annotation[] annotations = field.getDeclaredAnnotations();
for (int i = 0; i < annotations.length; i++) {
if (annotations[i].annotationType().equals(Id.class)) {
return name;
}
}
}
return null;
}
}
I would like to pass parameter name as a parameter to other method, f.e:
I have class:
public class Foo() {
public Bar bar;
public Bar anotherBar;
public Bar yetAnotherBar;
public void doSomethingWithBar() {
common.doingSomething(
getMostImportantBarParameterName()
);
}
}
And in this class I would to have method:
public String getMostImportantBarParameterName() {
return Foo.bar;
}
but instead of returning value of bar, I would like to get a name of parameter bar, so it should just return "bar".
For now I have to do this that way:
public String getMostImportantBarParameterName() {
return "bar";
}
Why I wanna achieve something like that?
I am trying as much I can to avoid using strings in my code, cause in refactorization process I will bypass (skip) it accidentally.
But if I will have "hard coded" parameters that way, when I will later rename this parameter it will be automatically replaced in all instances by Eclipse IDE (Using LALT+LSHIFT+R)
Also my method: common.doingSomething() use parameter in runtime, So I won't get compilation error, which it makes hard to maintain this method.
I don't write unit test, cause I can't yet.
Please give me some help on this. Thanks
----------------- EDIT ------------------------
Real life usage.
I would like to have method to access database records in generic way.
Common database operation in my application is:
Getting records from TableName where Parameter = SomeValue
So I would like to have generic method for that in generic entity listed below:
#MappedSuperclass
public abstract class GenericModel<T extends GenericModel> {
#Transient protected Class<T> entityClass;
private List<T> getByParameterAndValue(String parameter, String value) {
List<T> entities = new ArrayList<T>();
String sqlString = "SELECT e FROM " + entityClass.getSimpleName() + " e WHERE e."+ parameter + " = :value";
TypedQuery<T> query = JPA.em().createQuery(sqlString, entityClass).setParameter("value", value);
try {
entities = query.getResultList();
} catch (NoResultException e1) {
entities = null;
} catch (Exception e) {
Index.toLog("error","Unsupported error in Generic model class in " + entityClass);
}
return entities;
}
which is extended by real entities f.e.:
public class User extends GenericModel<User> {
public String name;
public String email;
public String date;
public String department;
public List<User> getUsersByDepartments(String dep) {
return getByParameterAndValue("department", dep);
}
}
The problem is that in JPA TypedQuery:
TypedQuery<User> query = em.createQuery("SELECT u FROM User u WHERE u.department = :department", User.class);
return query.setParameter("department", department).getSingleResult();
First of all, I think you should reconsider your approach. Using field names like this (either by reflection or hard coded Strings) is not very robust. In general, reflection should be avoided if possible.
What are you trying to achieve? What will common.doingSomething be doing with the field name?
It might be better to model the importance explicitly with an accessor:
class Foo {
private Bar bar;
private Bar anotherBar;
private Bar yetAnotherBar;
public Bar getMostImportantBar() {
return bar;
}
}
To answer your question about generics. You can either select the field by its index or by its name. Both are not robust, for when you change the field name, the String used to get it via reflection will not change with it, and if you change the order of the fields, the index will be wrong.
Here's how to do it:
Class foo = Foo.class;
Field[] fields = foo.getFields();
// get by index
Field firstField = fields[0];
String firstFieldName = firstField.getName();
// get by name
Field barField = foo.getField("bar");
String barFieldName = barField.getName();
EDIT (after reading updated question):
In any Object Relational Mapping solution there is a boundary where the object-oriented realm ends and the relational realm begins. With your solution you are pulling that boundary a bit further into your code, in order to gain ease of use for your specific model classes and queries. The consequence of that is that you get more 'boiler plate' style code as part of your application (the GenericModel class) and that the boundary becomes more visible (the reference to a field by index or name using reflection). This type of code is generally harder to understand, test and maintain. On the other hand, once you get it right it doesn't change that often (if your assumption about the query type you usually need turns out to be valid).
So I think this is not a ridiculous use case for reflection, even though I myself would probably still stick to JPA and accept the similarity of the queries. With a good JPA framework, expressing these queries does not incur a lot of code.
About the hard-coded field names vs indexes, I advise you to go with the field names because they are easier to understand and debug for your successors. I would make sure the field name is expressed in the model class where the field resides, to make it as clear as possible that the two belong together, similar to the example you gave:
public class User extends GenericModel<User> {
public static final String FIELD_NAME = "name";
public static final String FIELD_EMAIL = "email";
public static final String FIELD_DATE = "date";
public static final String FIELD_DEPARTMENT = "department";
private String name;
private String email;
private String date;
private String department;
// the byXXX naming scheme is a quite common shorthand for lookups
public List<User> byDepartment(String department) {
return getByParameterAndValue(FIELD_DEPARTMENT, department);
}
BTW I think getByParameterAndValue cannot be private (must be at least default). Also I don't think you should initialize List<T> entities = new ArrayList<T>() at the start. You can do that in the catch(Exception e) to avoid unnecessary initialization if the query succeeds or returns no results. An your fields should be private (shown above).
Of course, this approach still results in one lookup method for each field. A different solution is to create a service for this and leave the model objects aenemic (without behavior):
public class DaoService {
public <T extends GenericModel> List<T> get(Class<T> entityClass, String fieldName, String value) {
List<entityClass> entities;
String sqlString = "SELECT e FROM " + entityClass.getSimpleName() + " e WHERE e."+ fieldName+ " = :value";
TypedQuery<T> query = JPA.em().createQuery(sqlString, entityClass).setParameter("value", value);
try {
entities = query.getResultList();
} catch (NoResultException e) {
entities = null;
} catch (Exception e) {
entities = new ArrayList<T>()
}
return entities;
}
}
Usage:
List<User> = daoService.get(User.class, User.FIELD_DEPARTMENT, value);
Here's another (slightly wild) idea I just had. Each model class is also a query template:
public abstract class ModelQuery<T extends ModelQuery> {
// TODO set from constructor
private Class<T> entityClass;
private Field[] allFields = entityClass.getFields();
private List<T> getByTemplate() {
List<Field> queryFields = new ArrayList<Field>();
String sql = selectFieldsAndCreateSql(queryFields);
TypedQuery<T> query = setQueryParameters(queryFields, sql);
return executeQuery(query);
}
private String selectFieldsAndCreateSql(List<Field> queryFields) throws IllegalAccessException {
StringBuilder sql = new StringBuilder();
sql.append("SELECT e FROM ")
.append(entityClass.getSimpleName())
.append("e WHERE ");
for (Field field : allFields) {
if (field.get(this) != null) {
sql.append("e.")
.append(field.getName())
.append(" = :")
.append(field.getName());
// keep track of the fields used in the query
queryFields.add(field);
}
}
return sql.toString();
}
private TypedQuery<T> setQueryParameters(List<Field> queryFields, String sql) throws IllegalAccessException {
TypedQuery<T> query = JPA.em().createQuery(sql, entityClass);
for (Field field : queryFields) {
query.setParameter(field.getName(), field.get(this));
}
return query;
}
private List<T> executeQuery(TypedQuery<T> query) {
List<T> entities;
try {
entities = query.getResultList();
} catch (NoResultException e1) {
entities = null;
} catch (Exception e) {
entities = new ArrayList<T>();
}
return entities;
}
}
Usage:
User userQuery = new User();
userQuery.setDepartment("finance");
List<User> results = userQuery.getByTemplate();
I guess there are more ways to skin this cat. Good luck with finding your optimal solution!
To get private field names
use foo.getDeclaredFields(); instead of foo.getFields();
Here are also you have some minor issue
fields[0] means, the first declared field, in which 0 is again hard coded
If you change the order of declaration then again it could be a trouble for you, which will never get refracted
I would recommend using
1.) The Class.forName() SPI logic where you can inject the expected business logic on the fly.
2.) The Spring DI with interfaces and implementations using auto wiring
I want to create a Swingtable with a dynamic Layout, regarding the class data that is set as sources.
To be more specific:
I have a class with multiple attributes. When creating the table, I want to do it, so that the table looks: "which public getFunction with returntyp String are available" and use the attributes behind this functions as Columnnames and later also as source for the rows.
That is working at the moment.
My problem now is:
How can I ensure a specific order of my Columns with this approach?
for example i have a column "ID","callsign","categorie".
I want to display them in this order.
No metter how i order the methodes in sourceCode, the columns are allways in the same order ("ID","categorie","callsign").
java.lang.reflect.Method methodes[] = null;
methodes = classObjectOfT.getMethods();
List<String> tempList=new ArrayList<String>();
for (java.lang.reflect.Method m: methodes)
{
if (m.getReturnType().equals(String.class)&&m.getName().startsWith("get"))
{
tempList.add(m.getName().substring(3));
}
}
columnNames=(String[]) tempList.toArray(new String[tempList.size()]);
above is the code i use for retriving the columnames.
A workaround would be to name the attributes/getMethodes "ID_00","Callsign_01","Categorie_02" and do the ordering by using the last 2 chars of the String, but that would be rather ugly and i'm searching for a cleaner solution.
I would suggest creating an annotation which you would use to define the order and even more meta data for your table columns, for example a label:
#Retention(RetentionPolicy.RUNTIME)
#interface TableColumn {
String label();
int order();
}
Then retrieve them like this:
public Set<Method> findTableColumsGetters(Class<TestTableData> clazz) {
Set<Method> methods = new TreeSet<>(new Comparator<Method>() {
#Override
public int compare(Method o1, Method o2) {
return Integer.valueOf(o1.getAnnotation(TableColumn.class).order())
.compareTo(o2.getAnnotation(TableColumn.class).order());
}
});
for(Method method : clazz.getMethods()) {
if(method.isAnnotationPresent(TableColumn.class)) {
methods.add(method);
}
}
return methods;
}
Here is some testings:
Test table data
static class TestTableData {
private String id, callsign, categorie;
#TableColumn(label = "Caterogy", order = 3)
public String getCategorie() {
return categorie;
}
public void setCategorie(String categorie) {
this.categorie = categorie;
}
#TableColumn(label = "Call sign", order = 2)
public String getCallsign() {
return callsign;
}
public void setCallsign(String callsign) {
this.callsign = callsign;
}
#TableColumn(label = "ID", order = 1)
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
}
Test:
#Test
public void findTableColumsGetters() {
Set<Method> getters = findTableColumsGetters(TestTableData.class);
for(Method getter : getters) {
TableColumn annotation = getter.getAnnotation(TableColumn.class);
System.out.printf("%d %s (%s)%n", annotation.order(), annotation.label(), getter.getName());
}
}
Output:
1 ID (getId)
2 Call sign (getCallsign)
3 Caterogy (getCategorie)
I would suggest though that you don't retrieve the annotation reach time you need info from it, instead create a Metadata class for your methods where you put everyting including the method itself while you are performing the search.
i am trying to fetch only max(assetHistoryId) but my below code returing 3 columns max(assetHistoryId), eventId, and assetIdentifier in result.
how to group the columns with out projection using criteria.
you can find my code below.
final Criteria agcriteria = createCriteria(someclass.class);
agcriteria.add(Restrictions.in("eventId", listOfEventIds));
agcriteria.add(Restrictions.ne("action", "T"));
agcriteria.add(
Restrictions.between("modifyDate", lastProcessedTime,
batchStartTime));
agcriteria.setProjection(Projections.projectionList()
.add(Projections.groupProperty("assetIdentifier"))
.add(Projections.groupProperty("eventId"))
.add(Projections.max("assetHistoryId")));
val = agcriteria.list();
please help me any one ?
If i understand you correctly, you want only max(assetHistoryId) without any other column details.
You can try something like this:
Criteria agcriteria = createCriteria(someclass.class);
agcriteria.setProjection(Projections.projectionList()
.add(Projections.max("assetHistoryId")));
You can add restrictions to it, if any... like this: agcriteria.add(Criteria c); or the same set of conditions
agcriteria.add(Restrictions.in("eventId", listOfEventIds));
agcriteria.add(Restrictions.ne("action", "T"));
agcriteria.add(
Restrictions.between("modifyDate", lastProcessedTime,
batchStartTime));
Ok, boys and girls. I know it's a necro and Hibernate Criteria Api was deprecated long ago. But still there are systems which use this API, so hope it will be useful.
I could not find a way to do it with built-in hibernate projections, so I've decided to make my own ones. First of all we will need to create a new projection class which will produce nothing in SELECT clause, but still have it in group clause.
public class NoPropertyGroupProjection extends SimpleProjection {
private String propertyName;
protected NoPropertyGroupProjection(String propertyName) {
this.propertyName = propertyName;
}
#Override
public boolean isGrouped() {
return true;
}
#Override
public Type[] getTypes(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
return new Type[] { };
}
#Override
public String toSqlString(Criteria criteria, int position, CriteriaQuery criteriaQuery) throws HibernateException {
return "";
}
#Override
public String toGroupSqlString(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
return StringHelper.join( ", ", criteriaQuery.getColumns( propertyName, criteria ) );
}
#Override
public String toString() {
return propertyName;
}
}
That's a copy of PropertyProjection from the version of Hibernate I have with some changes.
It won't work alone (it is just much complicated to force it work alone), but in most cases we still need something to be selected.
So the next thing we need is to fix ProjectionList as it will break with empty column we're trying to pass it. So, here's the next class. Shame elements list is private, but we have sufficient getters to achieve our goal.
public class ProjectionListWithOnlyGroupBySupport extends ProjectionList {
#Override
public String toSqlString(Criteria criteria, int loc, CriteriaQuery criteriaQuery) throws HibernateException {
final StringBuilder buf = new StringBuilder();
String separator = "";
for ( int i = 0; i < this.getLength(); i++ ) {
Projection projection = this.getProjection(i);
String addition = projection.toSqlString( criteria, loc, criteriaQuery );
if (!"".equals(addition)) {
buf.append(separator).append(addition);
loc += getColumnAliases(loc, criteria, criteriaQuery, projection).length;
separator = ", ";
}
}
return buf.toString();
}
private static String[] getColumnAliases(int loc, Criteria criteria, CriteriaQuery criteriaQuery, Projection projection) {
return projection instanceof EnhancedProjection
? ( (EnhancedProjection) projection ).getColumnAliases( loc, criteria, criteriaQuery )
: projection.getColumnAliases( loc );
}
}
Again, small adjustments for the original class. Now we have everything needed to accomplish our goal. But for convenience we will create one more class.
public final class AdvancedProjections {
public static NoPropertyGroupProjection groupBy(String propertyName) {
return new NoPropertyGroupProjection( propertyName );
}
public static ProjectionList projectionList() {
return new ProjectionListWithOnlyGroupBySupport();
}
}
After we've created all these classes, we can change the code from the question:
final Criteria agcriteria = createCriteria(someclass.class);
agcriteria.add(Restrictions.in("eventId", listOfEventIds));
agcriteria.add(Restrictions.ne("action", "T"));
agcriteria.add(
Restrictions.between("modifyDate", lastProcessedTime,
batchStartTime));
agcriteria.setProjection(AdvancedProjections.projectionList()
.add(Projections.max("assetHistoryId"))
.add(AdvancedProjections.groupBy("assetIdentifier"))
.add(AdvancedProjections.groupBy("eventId")));
val = agcriteria.list();
Voila!