title: Wrong number of parameters of TRIM function in Hibernate @Formula
body: <p>I'm trying to make a formula to select a user-friendly name of the user profile. It selects <strong>firstname + ' ' + lastname</strong> if at least one of them is not null and not blank (contains non-whitespace characters), otherwise it selects <strong>shortname</strong> (with the same conditions) and, finally, if <strong>shortname</strong> is blank or null, it selects <strong>id</strong>, converted to string.</p>
  
  <pre><code>@Formula("COALESCE(NULLIF(TRIM(BOTH FROM CONCAT(sp.firstname, ' ', sp.lastname)), ''), TRIM(p.shortname), to_char(p.id, 'FM9999999999999999')) " +
     "FROM socialprofile AS sp " +
     "JOIN profile AS p ON sp.id=p.id")
     public String getUserFriendlyName() {
        return super.getUserFriendlyName();
     }
  </code></pre>
  
  <p>The result is:</p>
  
  <pre><code>org.hibernate.HibernateException: Unexpected number of trim function operands : 10
  </code></pre>
  
  <p>but there is only 3 arguments: BOTH, FROM and result of CONCAT. Is there any workaround of this issue? DB is PostgreSQL 9.1, Hibernate version is 4.2.1.
  Just in case, here's the table structure:</p>
  
  <pre><code>Profile
    bigint id
    text shortname
  
  SocialProfile
    bigint id
    text firstname
    text lastname
  </code></pre>
  
  <p>They are related as One-to-One by <strong>id</strong> field, in Java code SocialProfile extends Profile. In PgAdmin SQL editor this request works perfectly.</p>