Hibernate @Filter entity by @ManyToOne field
<p>I'm trying to use Java's Hibernate @Filter on a many to one relationship field, but when I enable the filter and try to call a getAll method using the StockDailyRecord Service from an AJAX I get this:</p>

<pre><code>HTTP Status 500 - Request processing failed; 
nested exception is javax.persistence.PersistenceException:
org.hibernate.exception.SQLGrammarException: could not extract ResultSet
</code></pre>

<p>This is my entity where I define the filter:</p>

<pre><code>@Entity
@Table(name = "stock_daily_record", catalog = "mkyong")
@FilterDef(name="stockDailyRecordFilter")
@Filters({
    @Filter(name="stockDailyRecordFilter", condition="stock.name = 'My stock'"),
})
public class StockDailyRecord extends Entity implements Serializable {
         ...
    @ManyToOne
    @JoinColumn(name = "stock_id", referencedColumnName = "id", nullable = false )
    public Stock getStock() {
        return this.stock;
    }
}
</code></pre>

<p>However when I change the filter with the actual column in the database "stock_id" and compare it with the id I want the filter works without any exceptions.</p>

<pre><code>@Filter(name="stockDailyRecordFilter", condition="stock_id = 10")
</code></pre>

<p>Here is how I enable the filter in the StockDailyRecordService:</p>

<pre><code>    Session hSession = getSession();
    if (isAnonymous) {
        hSession.enableFilter("stockDailyRecordFilter");
    } else {
        hSession.disableFilter("stockDailyRecordFilter");
    }
</code></pre>

<p>Also, when I try the filter on other properties (say the StockDailyRecord has field "description") it works just fine. Is there a way to access the "name" property of the Stock entity from the Filter condition, because I don't really want to do the approach with the "stock_id = 10"?</p>