morphia
morphia copied to clipboard
Query with disable validation: reverse order not work
I have made a test the represents my situation:
package afternoon.persistence.test;
import junit.framework.Assert;
import org.bson.types.ObjectId;
import org.junit.Before;
import org.junit.Test;
import afternoon.persistence.Dao;
import afternoon.utils.AppConfiguration;
import com.github.jmkgreen.morphia.annotations.Entity;
import com.github.jmkgreen.morphia.annotations.Id;
public class SortByIdTest {
@Entity("A")
static class A {
@Id ObjectId id;
String name;
public A(String name){
this.name=name;
}
public A(){}
}
@Before
public void setUp(){
AppConfiguration.setNameOfconfigFile("test.properties");
}
@Test
public void getLastByIdTest(){
A a1=new A("a1");
A a2=new A("a2");
A a3=new A("a1");
Dao.getDatastore().save(a1);
Dao.getDatastore().save(a2);
Dao.getDatastore().save(a3);
A a=Dao.getDatastore().createQuery(A.class).disableValidation().filter("name =", "a1").order("-id").get();
Assert.assertEquals("last id",a3.id, a.id );
}
}
Order of result is wrong.
see discussion here: https://github.com/mongodb/morphia/issues/475