Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I think the problem is when ORM influences/encourages particular schema designs. When you no longer see tables as tables (which is storage) and rather see your database tables as instances of objects (how you would like to consume the data)

ORM (rails/AR in particular) makes it very diffcult to work with joins and build an object that read from multiple tables.

One workaround I think is to use database views. And see views as "instances of objects" and back ORM classes with them.



Java's JPA interface, of which Hibernate is an implementation, makes it pretty simple. Straight from the documentation of EclipseLink (another implementation):

  // query for a primitive
  Query query = em.createNativeQuery("SELECT SYSDATE FROM DUAL");
  Date result = (Date)query.getSingleResult();

  // query for a pair of primitives (bletcherous, but not disastrous)
  Query query = em.createNativeQuery("SELECT MAX(SALARY), MIN(SALARY) FROM EMPLOYEE");
  List<Object[]> results = query.getResultList();
  int max = results.get(0)[0];
  int min = results.get(0)[1];

  // query for a mapped object
  Query query = em.createNativeQuery("SELECT * FROM EMPLOYEE", Employee.class);
  List<Employee> result = query.getResultList();




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: