Search code examples
javaormspark-javaactivejdbc

ActiveJDBC - Mapping Legacy Columns


Is there a way to map a legacy column to a different name with ActiveJDBC? My use case involves a legacy database - I have date_created and last_updated which I'd like to be used as the created_at and updated_at columns so they get auto populated, but I'm not seeing a way to do this in the documentation. I think it'd be rather handy to have an annotation based way to map all columns (especially for those of us who like to use camelCase on the web side and underscores in our column names).


Solution

  • The names of these columns are kind of hard-coded in ActiveJDBC. There are a couple of solutions though:

    1. Create an updatable view in the database to satisfy the framework
    2. Implement this feature using ActiveJDBC lifecycle callbacks: http://javalite.io/lifecycle_callbacks

    If you chose the #2, you can manage these in the beforeSave() method by setting your attributes date_created and last_updated

    UPDATE: If you chose #2, be sure to overview ActiveJDBC Inheritance.