I have the following problem. Every table in my project has four fields indicating user and date when the records were created and updated.
When trying to persist my objects I would like to avoid adding these fields to every object I use, so I created an Audit superclass. I am also using custom attributes to map the objects and fields to tables. I added the column attributes to my Audit class, but I could not add the Table attribute (as I do not have one). I also added the corresponing Table and Column attributes to the subclasses and appended the SuperClass field to the Table attribute.
After testing this I got the following results: my objects are being persisted but the audit fields are not.
Is what I am trying to do factible? If so, can you give me a hint as to how to proceed?
Thanks in advance,
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
It's possible to do what you want, but not via the custom attributes.
Instead you should use the XML Mapping file. Through the XML file you can include properties from the parent (abstract) class and map them to the columns you need in the individual class mappings.
You will need to repeat the four audit attribute mappings for each class in the XML, but that should be just a simple matter of cut and paste.
Also, if you don't need to set the superclass property to the audit class. You don't actually persist the audit class, so there is no need to include it in the o/r mapping.
I hope that makes sense. Let me know how you go.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks. It worked perfectly.
Anyway, after making it work I decided for associating the Audit object to my Auditable objects instead of making the Auditable objets inherit from it. So now, instead of having a superclass I have a class association (which is also working fine).
As an additional comment, I had to change from using custom attributes to using the xml configuration file. In my opinion it would have been better to use custom attributes to map the associations between classes and tables.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have the following problem. Every table in my project has four fields indicating user and date when the records were created and updated.
When trying to persist my objects I would like to avoid adding these fields to every object I use, so I created an Audit superclass. I am also using custom attributes to map the objects and fields to tables. I added the column attributes to my Audit class, but I could not add the Table attribute (as I do not have one). I also added the corresponing Table and Column attributes to the subclasses and appended the SuperClass field to the Table attribute.
After testing this I got the following results: my objects are being persisted but the audit fields are not.
Is what I am trying to do factible? If so, can you give me a hint as to how to proceed?
Thanks in advance,
It's possible to do what you want, but not via the custom attributes.
Instead you should use the XML Mapping file. Through the XML file you can include properties from the parent (abstract) class and map them to the columns you need in the individual class mappings.
You will need to repeat the four audit attribute mappings for each class in the XML, but that should be just a simple matter of cut and paste.
Also, if you don't need to set the superclass property to the audit class. You don't actually persist the audit class, so there is no need to include it in the o/r mapping.
I hope that makes sense. Let me know how you go.
Thanks. It worked perfectly.
Anyway, after making it work I decided for associating the Audit object to my Auditable objects instead of making the Auditable objets inherit from it. So now, instead of having a superclass I have a class association (which is also working fine).
As an additional comment, I had to change from using custom attributes to using the xml configuration file. In my opinion it would have been better to use custom attributes to map the associations between classes and tables.
Associations can be mapped using custom attributes.
You do it using AFAssociation (at the table level).
I'm glad everything is working for you.
- Richard