Annotatiomania™, or why did Hibernate/JPA get so complex?

I was curious about good answers to this question on Stack Overflow:

http://stackoverflow.com/questions/7332904/how-to-store-a-collection-of-dates-in-hibernate

And a good answer came up, pointing at this Hibernate documentation page:

http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html/collections.html#collections-ofvalues

Is anyone out there actually willing to mess around with gazillions of annotations on simple methods? Who ever writes this stuff:

@Entity
public class User {
   [...]
   public String getLastname() { ...}

   @ElementCollection
   @CollectionTable(
      name="Addresses", 
      joinColumns=@JoinColumn(name="user_id"))
   @AttributeOverrides({
      @AttributeOverride(
         name="street1", 
         column=@Column(name="fld_street"))
   })
   public Set<Address> getAddresses() { ... }
}

@Embeddable
public class Address {
   public String getStreet1() {...}
   [...]
}

Do some developers despise SQL so much that they’re willing to put up with “annotatiomania”? Whatever happened with the good old

SELECT u.first_name, u.last_name, a.street1
FROM users u
JOIN addresses a ON a.user_id = u.id

Guys. If a technology starts doing things like “@AttributeOverrides”, then something IS smelling fishy

Oracle scalar subquery caching

The importance of being able to fully control executed SQL (using jOOQ, or plain JDBC) on large-scale systems becomes obvious every time you need to fine-tune your SQL queries for a specific RDBMS. In this case, we’re looking at Oracle and its miraculous scalar subquery caching mechanisms:

Usually, the context switch from SQL to PL/SQL and back is quite expensive for an average Oracle query, so we should normally omit putting stored functions as filtering, grouping, sorting criteria, even if they’re DETERMINISTIC. When we have large result sets, however, even functions in the query projection may turn out to be an execution plan nightmare. I recently raised the question on Stack Overflow, as I’m curious if there is any caching mechanism, that I could take advantage of for a concrete use-case:

http://stackoverflow.com/questions/7270467/is-there-a-pl-sql-pragma-similar-to-deterministic-but-for-the-scope-of-one-singl

And most interestingly, there are several. The accepted answer points to this very relevant article on Ask Tom’s Q/A:

http://www.oracle.com/technetwork/issue-archive/2011/11-sep/o51asktom-453438.html

Apparently, in scalar subqueries, function results may be cached! While this can be very useful for performance, it can also be very dangerous for consistency – as with any caching mechanism, but this one is highly implicit! So this will be cached:

-- my_function is NOT deterministic but it is cached!
select t.x, t.y, (select my_function(t.x) from dual)
from t

-- logically equivalent to this, uncached
select t.x, t.y, my_function(t.x) from t

Knowing this, I think I have to review quite a bit of SQL…