PDA

View Full Version : Automatic ID and Column fields



Chris Messina
Jun 2nd, 2009, 03:04 PM
I am having fun trying this tool out, but I have a question.

When Roo creates a new entity (as an example I will use a class called Cycle) using
new persistent class jpa -name ~.Cycle a Cycle_Roo_Entity.aj file is created which contains (among other things) an id field and version field which are mapped to the columns "id" and "version". Is there a way to customize this?

In my particular case I do not have much control over the database and in most cases the only version column in the table would probably be an "update_date" column (which besides having a different column name is also a date instead of integer). Furthermore, our id column is not always called "id". For instance on an table called CYCLE the id field may be called "CYCLE_ID".

I tried to make edits the Cycle_Roo_Entity.aj file by hand in eclipse but Roo just changed them back.

Thanks,
Chris

rhart
Jun 2nd, 2009, 05:29 PM
You cannot change .aj files, these files are "managed" by Roo. Instead, add the id field and the getter and setter to the Cycle class and annotate as you require. When you save the Cycle.java file you'll notice that Roo removes the id and it's getter and setter from the Cycle_Roo_Entity.aj file. If you copy the values from the Cycle_Roo_Entity.aj make sure you remove the "Cycle." prefix

Ben Alex
Jun 2nd, 2009, 09:11 PM
Thanks rhart. Another way is to use the @RooEntity annotation attributes, so you can do things like @RooEntity(identifierField="myOtherName"). There are various attributes in the class to fine-tune version etc. Because this annotation appears on your .java file, you can edit it easy and still have the benefits of Roo auto-managing your ITDs.

Chris Messina
Jun 5th, 2009, 01:27 PM
Perfect, thanks for the help Ben and rhart.