Hey i have a problem but i cant explain it myself. I use OpenJPA and have a simple class:

@Entity
public class Organisation implements Serializable{
@Id
private int id;
private String name;    

public Organisation(int id, String name){
    this.id = id;
    this.name = name;
}

public String getName() {
    return name;
}   
}

I add the organisation with names aa, bb, AA, BB and query it with:

TypedQuery<Organisation> qry = em.createQuery("select o from Organisation o order by o.name", Organisation.class);

EDIT: This is all the same WAR and database:
On Glassfish i get: aa, AA, bb, BB
On Websphere i get: AA,BB,aa,bb
On Oracle directly SQL-Query i get: aa, AA, bb, BB

I test it at home with glassfish/h2 and i get AA,BB,aa,bb

Where is my mistake?

有帮助吗?

解决方案

JPA doesn't do anything special with the ordering, it just generates the ORDER BY clause that gets passed to the database, so it's almost assuredly an issue with the database. Are you using a different database, or different connection parameters in the cases where you see different results? If the collation settings are different in the different scenarios you could see something like this.

Edit 1:

This other Stack Overflow question appears to resolve this issue:

stackoverflow.com/questions/8818201/oracle-order-by-different

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top