0

我正在尝试使用带有排序属性的 PageRequest 使用 GraphRepository 的 findAll() ,但出于某种原因,我的数据没有以排序方式返回。这是我的代码:

public class Playground {

    /**
     * @param args
     */
    public static void main(String[] args) {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(DefaultApplicationConfig.class);
        SocialRescueManager manager = (SocialRescueManager)context.getBean("socialRescueManager");

        manager.Civilians.deleteAll();

        manager.Civilians.save(new Civilian("B", "lastName1", Nationality.USA, EyeColor.BLUE, HairColor.BLOND, 180, new DateTime(1984, 1 , 9, 0, 0)));
        manager.Civilians.save(new Civilian("C", "lastName2", Nationality.USA, EyeColor.GREEN, HairColor.BLACK, 170, new DateTime(1985, 6 , 9, 0, 0)));
        manager.Civilians.save(new Civilian("A", "lastName3", Nationality.USA, EyeColor.BLUE, HairColor.BLOND, 175, new DateTime(1990, 10 , 23, 0, 0)));

        Pageable pageable = new PageRequest(0, 5, Direction.DESC, "firstName");

        Page<Civilian> results = manager.Civilians.findAll(pageable);

        for(Iterator<Civilian> i = results.iterator(); i.hasNext(); ) {
            Civilian civilian = i.next();
            System.out.println(civilian.getFirstName());
            System.out.println(civilian.getDateOfBirth());
        }

        context.close();
    }
}

我的平民课程如下所示:

@NodeEntity
public class Civilian extends Profile {

    @GraphProperty(propertyType = Long.class)
    DateTime dateOfBirth;

    public Civilian() {
    }

    public Civilian(String firstName, String lastName, Nationality nationality, EyeColor eyeColor, HairColor hairColor, int height, DateTime dateOfBirth) {
        super(firstName, lastName, nationality, eyeColor, hairColor, height);
        this.setDateOfBirth(dateOfBirth);
    }

    public DateTime getDateOfBirth() {
        return dateOfBirth;
    }

    public void setDateOfBirth(DateTime dateOfBirth) {
        this.dateOfBirth = dateOfBirth;
    }   
}

Civilian 类扩展了 Profile 类,如下所示:

public abstract class Profile extends AbstractEntity {

    @Indexed(indexType = IndexType.FULLTEXT, indexName = "firstName")
    String firstName;

    @Indexed(indexType = IndexType.FULLTEXT, indexName = "lastName")
    String lastName;

    @Indexed
    EyeColor eyeColor;

    @Indexed    
    HairColor hairColor;

    @Indexed
    Nationality nationality;

    @Indexed
    int height;

    public Profile() {

    }

    public Profile(String firstName, String lastName, Nationality nationality, EyeColor eyeColor, HairColor hairColor, int height) {
        this.setFirstName(firstName);
        this.setLastName(lastName);
        this.setNationality(nationality);
        this.setHairColor(hairColor);
        this.setEyeColor(eyeColor);
        this.setHeight(height);
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public EyeColor getEyeColor() {
        return eyeColor;
    }

    public void setEyeColor(EyeColor eyeColor) {
        this.eyeColor = eyeColor;
    }

    public HairColor getHairColor() {
        return hairColor;
    }

    public void setHairColor(HairColor hairColor) {
        this.hairColor = hairColor;
    }

    public Nationality getNationality() {
        return nationality;
    }

    public void setNationality(Nationality nationality) {
        this.nationality = nationality;
    }

    public int getHeight() {
        return height;
    }

    public void setHeight(int height) {
        this.height = height;
    }
}

所以,我的 Main() 方法的结果如下:

B
1984-01-09T00:00:00.000+02:00
C
1985-06-09T00:00:00.000+03:00
A
1990-10-23T00:00:00.000+02:00

但正如您所看到的,我将 PageRequest 对象设置为按“firstName”属性以 DESC 顺序对结果进行排序,所以我希望首先打印 C,然后是 B,最后是 A。

我究竟做错了什么?

谢谢。

4

1 回答 1

3

状态的javadoc CRUDRepository.findAll(Pageable)

注意:排序尚未实现

您必须提供修复,或者您不妨考虑使用启用排序的密码查询。例如

START n=node:firstName('firstName:abc')
RETURN n
ORDER BY n.firstName DESC
于 2013-04-30T10:33:32.567 回答