10 March 2007

java persistence

i've been fighting against hibernate for a few days trying to correct some mappings within entities that have very simple relationships. we chose to go the annotation route and i am seriously regretting that choice. the annotations push databasespeak into the domain and clutter code with what amounts to useless information.

rather than being able to express a concept of ownership or backreference to a parent entity cleanly and concisely, i am left telling hibernate how to build tables/sql for me--all in classes that are not meant to know about a database. for example, i need to use a combination of @OneToMany, @ManyToOne, @JoinColumn, etc across classes. i should be using @Parent, @Owned, @Shared, or some such higher-level descriptors. at least toplink used a separate class to define mappings. those were the days...

probably the most frustrating element has been the quality of online documentation at the hibernate site. it is horribly vague and lacks clear prose--i guess a common problem in IT. the API documentation is the worst i've seen: simply generated javadoc from uncommented code. that one really bit me when i created my own PreInsertEventListener and was left to dig up an example in source code to know that a boolean return value of onPreInsert meant 'veto the insert.' is it really that hard to describe that in a javadoc comment? it's been a common problem i've found in java development in general: one must find the source code to know how to use something in a framework or change its behavior.

No comments:

Post a Comment