Showing posts with label jpa. Show all posts
Showing posts with label jpa. Show all posts

Wednesday, January 6, 2010

hibernate console in intellij idea 9

I was pleasantly surprised to find better hibernate support in intellij idea 9, which was recently released.

They had hibernate support in 8.x, including a console, where you could run queries against your data using the mappings you had configured. However in version 9, they added the ability to use named parameters with associated values. So in essence, you can paste in a hql query and it autodetects the named parameters, e.g. :username. That pops up on the right pane as a named paraemeter. You just double click that, set its value, and you can run the query.

intellij has had support for this in their jdbc console in the past, but it's very handy now with the hibernate console. It removes one step from having to debug queries - you no longer have to use just the sql output that hibernate outputs and then piece queries back together and then try to guess where the disconnect was :).

See intellij feature request:
http://youtrack.jetbrains.net/issue/IDEADEV-41129

Related to hibernate console, don't forget to have the ehcache.jar in your module's classpath if you want to use the hibernate console. You can find the jar in the basic core download of hibernate - in the lib/optional/ehcache directory of the bundle. The console requires the secondary cache and will give you odd secondary cache errors if you don't have it in the path.

See this about loading ehcache:
http://youtrack.jetbrains.net/issue/IDEA-21914

Friday, May 1, 2009

JPA composite key craziness (vs. SQL Alchemy)

I know that a framework generally isn't designed to handle edge use cases gracefully. The old saying goes that you make the common case fast and the rare case possible. That often turns out to be the case for frameworks as well.

I was trying to map a composite key that made up an Oracle view - two foreign keys. The JPA is sadly very complicated with its mapping of composite keys (hibernate doc link). I heard stories around the office like, "I think XXX tried to do one of those, but then he backed out those changes." and "I did one of those once (shudder)."

In response to my ranting, a python guru friend of mine who works on both python code and java code regularly, told me that SQL Alchemy has had support for composite keys since version 0.1. He said it's pretty simple... Too bad. Too bad the JPA standard isn't better. However, maybe now that Oracle is buying Sun, the JPA will get a shot in the arm.