Blog Home  Home Add to any service  
Beckshome.com: Thomas Beck's Blog - Confusion over Configuration
Musings about technology and things tangentially related
 
# Saturday, December 16, 2006

My initial experiences with Oracle’s TopLink object-relational mapping tool have been less than pleasant. TopLink is the default Java Persistence API provider when creating persistence units for EJB3 style beans in NetBeans. When using TopLink out of the box with NetBeans, the tool’s default behavior is to behave in a case-sensitive fashion with respect to table and column names. This results in awful “Table XXXXX does not exist” errors, where XXXXX is, of course, the capitalized table name.


This posture represents the absolute antithesis to the recent, Ruby on Rails-driven trend towards “Convention over Configuration”; instead reverting to the longstanding software engineering tradition of confusion over configuration. Why wouldn’t you just set the default behavior to respect case insensitivity? I’m assuming that this can be set in a config file but I’m too mad to go thumbing through the documentation to find out where that is. The TopLink API has a setShouldForceFieldsToUpperCase() method. I don’t want to call that either. Why should I have to?

Hmm… if I remember correctly, were I to open a SQL*Plus command prompt and execute the statement CREATE TABLE foo, Oracle would create for me a table named FOO. Sounds like Oracle convention over ease of configuration. As far as I can see, EJB-QL is case insensitive and the database I’m using, Derby, is also case insensitive. My primitive troubleshooting points to TopLink as the culprit here. I’m going to swap in Hibernate and see if I’m right or wrong. Is anyone else experiencing similar problems?

Saturday, December 16, 2006 7:47:06 AM (Eastern Standard Time, UTC-05:00)  #    Comments [1]   Java - .NET - RoR  | 
Tuesday, May 15, 2007 2:06:57 PM (Eastern Standard Time, UTC-05:00)
found this looking up a similar issue, but I figured out the problem:

While this may seem counter intuitive, its the way Java and JDBC work - strings "ColumnName" is not the same as "COLUMNNAME". To top it off, not all databases operate the same - Oracle will return all caps, but others return all lowercase, and some are case sensitive by default. In Oracle (your example used it) there is a notion of case sensitivity by wrapping the name in quotes. So creating a table like "TableName" means that you can not look it up using TABLENAME through SQL*Plus any longer. So, when you define a field as
@Column(name="ColumnName") are you trying to access "ColumnName", COLUMNNAME or columnname as it depends on the database. Switching to a different database later on (JPA is DB platform independent after all) will mean you have to entirely change your mappings to account for this. So you will get problems with apps that are developed using one database but then moved to QA/production on another. TopLink is just using the string directly as is when doing lookups. Hibernate I believe has some notion of case insensitivity by default which will be less sensitive to common case mistakes such as using @Column(name="ColumnName") and joinColumn(name="COLUMNNAME") but what will happens if you ever switch to a case sensitive DB environment and how is this error going to manifest itself..
chris
Comments are closed.
Copyright © 2008 Thomas Beck. Some rights reserved.

Creative Commons License