Envers hard-coded to ask RevisionEntity for "id" instead of @RevisionNumber?
dfisher95350 May 16, 2011 4:37 PMI'm trying to use a non-PK field for RevisionNumber. I seem to be very close to succeeding. Within the transaction (1) the insert of the REVISION row succeeds, (2) the select of the MySQL-generated integer REV_ID (revisionNumber) succeeds, but then the insert of the MYENTITY_AUDIT row fails. It fails because Envers seems to be hard-coded to ask my RevisionEntity for its "id" instead of its @RevisionNumber when it goes to set the RevisionNumber on MYENTITY_AUDIT.
My PK entity.id is a String UUID. I have created another field, called REV_ID in the table and revisionNumber in the Java RevisionEntity. It is of course an integer. So, the very last step of my transaction is a type mismatch (data truncated) when trying to insert the mis-obtained String id in place of the integer RevisionNumber.
I've been in the Envers source. I thought the fix might be as simple as reading a property for revisionNumberPath (which has a hard-coded ".id" appended to it) but it's not that easy, or I am off track. I would appreciate any help or advice. It seems so close to working. (If there is no confiugration solution, I am prepared to alter Envers code in my project, if it comes to that. Even then, I could use some advice. The configuration classes seem fairly complex.)
Where my RevisionEntity (sub-class) contains:
private
String id;
private
int
revisionNumber;
@Id
@GeneratedValue
(generator =
"system-uuid"
)
@GenericGenerator
(name =
"system-uuid"
, strategy =
"uuid"
)
@Column
(name =
"ID"
)
public
String getId() {
return
id;
}
public
void
setId(String id) {
this
.id = id;
}
@RevisionNumber
@Generated
(GenerationTime.ALWAYS)
@Column
(name =
"REV_ID"
, updatable =
false
, insertable =
false
)
public
int
getRevisionNumber() {
return
revisionNumber;
}
public
void
setRevisionNumber(
int
revisionNumber) {
this
.revisionNumber = revisionNumber;
}
Where the MySQL table definition is:
CREATE TABLE REVISION (
ID CHAR(
32
) NOT NULL
, REV_ID INTEGER NOT NULL AUTO_INCREMENT
, REV_TIMESTAMP BIGINT NOT NULL
, REV_DETAILS VARBINARY(
64000
)
, USER_ID CHAR(
32
)
, CONSTRAINT PK_ID PRIMARY KEY (ID)
, CONSTRAINT UQ_REVID UNIQUE (REV_ID)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;