SQL Zone is brought to you in partnership with:

I am the founder and CEO of Data Geekery GmbH, located in Zurich, Switzerland. With our company, we have been selling database products and services around Java and SQL since 2013. Ever since my Master's studies at EPFL in 2006, I have been fascinated by the interaction of Java and SQL. Most of this experience I have obtained in the Swiss E-Banking field through various variants (JDBC, Hibernate, mostly with Oracle). I am happy to share this knowledge at various conferences, JUGs, in-house presentations and on our blog. Lukas is a DZone MVB and is not an employee of DZone and has posted 233 posts at DZone. You can read more from them at their website. View Full User Profile

Annotatiomania™, or Why Did Hibernate/JPA Get So Complex?

08.01.2012
| 680 views |
  • submit to reddit

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

Published at DZone with permission of Lukas Eder, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)