users@glassfish.java.net

Case insensitive primary key & FETCH LEFT JOIN does not work

From: <glassfish_at_javadesktop.org>
Date: Mon, 01 Sep 2008 00:50:45 PDT

Hi,

I am writing persistent beans for an existing legacy database (MS-SQL + Hibernate). In the articles table, the primary key is a case insensitive VARCHAR - stupid, but legacy. Every association is LAZY. In the order lines table, the articleno sometimes appears with a different case. If I do this SELECT:

SELECT DISTINCT o FROM Order o
 LEFT JOIN FETCH o.orderLines AS orderLine
 LEFT JOIN FETCH orderLine.article AS article
 LEFT JOIN FETCH article.designations
 LEFT JOIN FETCH o.customer
 WHERE o.orderNo=:orderNo

then the articles of the order lines with a different case are not loaded which gives a Lazy..Exception upon access. The generated query returns all orderlines and all articles within the join, so for me it looks like Glassfish (or Hibernate) simply ignore results that do not match case.

I tried this hack (we had some issues with spaces as well):

    @PostLoad
    public void postLoad() {
        articleNo = articleNo.toUpperCase().trim();
    }
    
which seems to work in the case the articles are already loaded by Hibernate but not with a clean cache. My current hack now is this:

        for (OrderLine orderLine : result.getOrderLines()) {
            orderLine.getArticle().getDesignation(Language.GERMAN).getClass();
        }

Does there is a way to tell Glassfish (or Hibernate) to ignore the case on primary keys?
[Message sent by forum member 'kurti' (kurti)]

http://forums.java.net/jive/thread.jspa?messageID=296488