I have a Contact entity connected to a ContactList entity through a @OneToMany relation. Then the ContactList entity connects to the Review List entity through @ManyToOne. The ContactList entity has data related to the contact on the list. I need to sort the ContactList children from the Contact by the createdOn timestamp in Review List. I am not sure this is possible.

Contact entity

```
@OneToMany(mappedBy = "contact")
@OrderBy("created_on DESC") <-- This does not work.
private SortedSet<ContactList> contactLists;

```

ContactList entity:

```
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "LIST_ID")
private ReviewList reviewList;

```

ContactList compareTo:

```
@Override
public int compareTo(ContactList b) {
    if (this.getReviewList().getCreatedOn().getTime() == b.getReviewList().getCreatedOn().getTime()) {
        log.error("Two review lists have the exact same created time???");
        return 0;
    }

    return this.getReviewList().getCreatedOn().getTime() < b.getReviewList().getCreatedOn().getTime() ? -1 : 1;
}

```

Review List createdOn field I am trying to sort the parent by:

```
@Column(name="CREATED_ON", updatable=false)
private Timestamp createdOn;

```

I have tried it without the @OrderBy notation, and it will not compile. But everything I have tried to put in the quote fails. I have tried contactList as shown, reviewList, reviewList.createdOn, reviewList\_createdOn, and a couple others that were really dumb. 

It seems like Hibernate is taking the first part of the quoted string and putting it into the query directly. Whatever I put in there errors with this:

> 
> Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'contactlis0\_.created\_on' in 'order clause'
>  at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0\_91]
>  at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0\_91]
>  at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0\_91]
>  at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0\_91]
>  at com.mysql.jdbc.Util.handleNewInstance(Util.java:425) ~[mysql-connector-java-5.1.44.jar:5.1.44]
>  at com.mysql.jdbc.Util.getInstance(Util.java:408) ~[mysql-connector-java-5.1.44.jar:5.1.44]
>  at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:943) ~[mysql-connector-java-5.1.44.jar:5.1.44]
> 
> 
> 

And of course it does, since I'm trying to reference a field in another table. It needs to do some sort of JoinColumn in between.

Is there any way to do this? I could probably write a custom JPQL query to sort them how I want and pass that to the page separately, but I was trying to do this with annotation and hibernate.