Gmane
From: <Gavin.King <at> doi.vic.gov.au>
Subject: Re: New Query Language Features
Newsgroups: gmane.comp.java.hibernate.devel
Date: 2003-03-03 04:32:39 GMT (6 years, 17 weeks, 6 days, 4 hours and 22 minutes ago)

After reviewing the ODMG OQL spec, I am now inclined to support (but
discourage) the OQL-style syntax. The only reason for this is that HQL is
now sufficiently close to OQL that we have a reasonable ODMG implementation
(ie. we can remove the "work in progress" label from
net.sf.hibernate.odmg). So we can allow

    from Foo foo, foo.bars bar

resulting in an inner join (but we will clearly discourage this).

The following is a catalog of the main differences between OQL and HQL (the
ones I know so far)

(1)  OQL uses

    foo.bar = nil
    foo.bar != nil

whereas we have the SQL-style

    foo.bar is null
    foo.bar is not null

(but we could even try to support both in the future).

(2) The following query in OQL

    select Foo foo
    where foo.bar = 'bar'

returns UNDEFINED if foo.bar is null. (Whereas SQL and HQL return no row at
all.) I don't see how an OR mapper could possibly emulate this behaviour
efficiently, or what value it has to users. OQL forces users to write:

    select Foo foo
    where foo.bar!=nil
    andthen foo.bar = 'bar'

I am NOT keen on this.

(3) OQL uses

    select Summary(name: foo.name, count: foo.count) from Foo foo

whereas we use

    select new Summary(foo.name, foo.count) from Foo foo

HQL is more natural, I think.

(4) OQL will accept

    from Foo foo, Bar bar where bar in foo.bars

whereas Hibernate requires

    from Foo foo, Bar bar where bar in elements(foo.bars)

this is no big deal and is partly due to the fact that we also allow
indices(foo.bars) for which OQL, apparently, has no equivalent.

(5) OQL uses

    from Foo foo where count(foo.bars) > 5

whereas we have the size() function

    from Foo foo where size(foo.bars) > 5

I don't like the idea of clobbering the SQL count() function, and
re-aliasing it to produce a subquery!

Of course, Hibernate adds extra features that don't really fit into OQL and
vice-versa (eg. HQL outer and full joins or OQL method invocation). That
just goes to demonstrate that O/R mappers and OODBs are actually really
different things.

                                                                                                                                      
                    "Max Rydahl Andersen"                                                                                             
                    <max <at> eos.dk>                            To:     <hibernate-devel <at> lists.sourceforge.net>                           
                    Sent by:                                cc:                                                                       
                    hibernate-devel-admin <at> lists.sourc       Subject:     Re: [Hibernate] New Query Language Features                  
                    eforge.net                                                                                                        

                                                                                                                                      
                    02/03/03 06:31 AM                                                                                                 

You're on fire :)

Im +1 for explict syntax for the join type :)

Furthermore I would not loose sleep if the following
syntax was dropped:

  FROM Foo foo
  INNER JOIN foo.bars bar

Which is aliasing without the AS, right ?

I......eh...a friend of mine often have had sleepless night concerning
bug-hunting because of non-explict syntax, also including the AS and the
join-stuff.

/max

----- Original Message -----
From: "Gavin King" <gavin <at> incubus.de>
To: <hibernate-devel <at> lists.sourceforge.net>
Sent: Saturday, March 01, 2003 1:42 PM
Subject: [Hibernate] New Query Language Features

> I have finally (!) finished the following very requested new features:
>
> * more-standard FROM clause syntax
>
> FROM eg.Foo AS foo
> INNER JOIN foo.bars AS bar
>
> * outer joins
>
> FROM Foo AS foo
> LEFT JOIN foo.bar AS bar
> LEFT JOIN bar.bazSet AS baz
>
> * queries returning results in an object
>
> SELECT NEW Row(foo.name, foo.count, bar.amount)
> FROM Foo AS foo
> , Bar AS bar
>
>
>
> Now, with regard to the new FROM clause syntax, I have a question. When I
> originally designed the QL, I couldn't get hold of any decent info about
> OQL (the ODMG spec costs money), so I just created something that seemed
> sane to me. Eventually, Anton van Straaten donated a copy of the ODMG
> spec, so I then had something to work from. Unfortunately, ODMG OQL is
> (IMO) too complicated, underspecified and not really well-adapted to
> relational databases. (Note that noone ever produced anything remotely
> approaching a complete OQL implementation.) However, there are certain
> places where OQL is "closer" to SQL than Hibernate's query language is.
> The new changes bring Hibernate's syntax much closer to both SQL and OQL
> so that HQL is now the more "minimal" SQL extension. By side-effect,
there
> is a subset of HQL that is now also an OQL subset (ie. queries are
> simultaneously correct OQL and correct HQL).
>
>
> So, in HB2, we will continue to support the old syntax:
>
>   FROM foo IN CLASS Foo
>   , bar IN elements(foo.bars)
>
> for backward compatibility and because I still kinda like it ;) And we
> will now also support the new syntax:
>
>   FROM Foo AS foo
>   INNER JOIN foo.bars AS bar
>
> And even
>
>   FROM Foo foo
>   INNER JOIN foo.bars bar
>
> which I don't like so much, but is which consistent with both SQL and
OQL.
> Should we also allow:
>
>    FROM Foo AS foo
>    , foo.bars AS bar
>
> because I think OQL allows it (I'll check the spec tomorrow) and because
> it seems consistent with our old syntax.
>
> What I have in CVS currently will NOT allow the above syntax. To me, the
> use of a ',' implies a cross product, whereas this query would *actually*
> result in an inner join. So I think its better that we force you to use
an
> explicit 'INNER JOIN', 'FULL JOIN' or 'LEFT JOIN', unless it is
*actually*
> a cross product, ie.
>
>    FROM Foo AS foo
>    , Bar AS bar
>
> but I am interested in other opinions on this.
>
>
> Please note: none of this stuff is very well tested. I spent about 3 days
> refactoring the query language stuff to get to this point, so we need to
> put it through its paces before a final release of HB2.
>
> Gavin.
>
>
>
>
>
>
> -------------------------------------------------------
> This sf.net email is sponsored by:ThinkGeek
> Welcome to geek heaven.
> http://thinkgeek.com/sf
> _______________________________________________
> hibernate-devel mailing list
> hibernate-devel <at> lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/hibernate-devel
>

-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
hibernate-devel mailing list
hibernate-devel <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/hibernate-devel

**********************************************************************
Any personal or sensitive information contained in this email and
attachments must be handled in accordance with the Victorian Information
Privacy Act 2000, the Health Records Act 2001 or the Privacy Act 1988
(Commonwealth), as applicable.

This email, including all attachments, is confidential.  If you are not the
intended recipient, you must not disclose, distribute, copy or use the
information contained in this email or attachments.  Any confidentiality or
privilege is not waived or lost because this email has been sent to you in
error.  If you have received it in error, please let us know by reply
email, delete it from your system and destroy any copies.
**********************************************************************

-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf