Hello.
I'm writing an EJB 3.0 application that tracks changes made to some fo it's tables. Let's say we have a table PERSON. This table will have 4 columns, PERSON_ID, VERSION, NAME and AGE. The tables primary key will be (PERSON_ID, VERSION).
Question 1: in the composite primary key, the PERSON_ID column should be auto-generated (via oracle sequence, for example), and the VERSION should me maintained by code. How can I implement this behaviour?
Question 2: To keep track of changes, every time I create or modify an object I frist create it's clone in the database. If for example I create the 20 year old Kenny, two records would be added to the database, (1, 0, Kenny, 20) and (1, 1, Kenny, 20). If Kenny was to age one year, the record (1, 1, Kenny, 20) would become (1, 2, Kenny, 21) and the record (1, 1, Kenny, 21) would be added.
I'm trying to do this using Entity Listeners, but I keep getting the following exception:
12:45:18,883 ERROR [STDERR] javax.ejb.EJBException: javax.persistence.Persistenc
eException: org.hibernate.id.IdentifierGenerationException: ids for this class m
ust be manually assigned before calling save(): ejb3tests.Person
...
Can anyone get me some ideas on how to get arround this?
Thanks in advance,
Hugo Oliveira
|