Thursday, February 28, 2008

Hibernate reverse engineering and "yes_no" columns

Since attending JBossWorld Orlando, I've been playing with the JBoss Developer Studio. I've had some problems with reverse generation of my entities, and so I thought I'd post some of the solutions.

My database uses logical deletes ("Y" and "N".) The generated entities, which were typed as Boolean's choked on insert.

I haven't had much luck yet customizing the generation from the JBoss Developer Studio menu , and so I've been using the Hibernate Tools for Eclipse to generate my entities into a separate project, ModelProject, and then copying them into a seam project.

My plan was to use Seam tools to generate the crud ui from the project. However, right clicking the project and choosing "New -> Seam Generate Entities" and then selecting "Use existing entities" didn't do anything.

I started over and did the following :
ran seam-gen from the command line and created a new project, SeamProject
imported the resulting project into Eclipse
copied the reverse-engineered entities from ModelProject into SeamProject
ran "seam generate-ui" from the command line

This worked beautifully. The only hitch was I kept getting a vague error from DB2/400 when I tried to create a new entity, "[SQL0545] INSERT or UPDATE not allowed by CHECK constraint."

I checked all the constraints and after a few failed attempts determined that I wasn't violating any foreign keys. There were only a couple of not null fields one of which was the logical delete column. I had entered the translation I wanted into the hibernate.reveng.xml file (or at least I thought I had), but there was no annotation for "yes_no." I simply added @Type(type="yes_no") to the field, and everything worked.

Blogged with Flock

No comments: