Paris Karagiannopoulos
Paris Karagiannopoulos

Reputation: 591

Renaming hibernate envers id and timestamp columns

I am trying to add a custom column to the auditing of an application.

I have a custom RevisionEntity:

@Entity
@Table(name = "REVINFO")
@RevisionEntity(UserRevisionListener.class)
public class UserRevEntity extends DefaultRevisionEntity {
    private String username;

    public String getUsername() { return username; }

    public void setUsername(String username) { this.username = username; }
}

When persisting the data hibernate executes sends this query to the database:

insert into REVINFO (timestamp, username, id) values (?, ?, ?)

The problem is that REVINFO table does not have id and timestamp fields and I get an error

SQLSyntaxErrorException: ORA-00904: "ID": invalid identifier

The REVINTO table looks like this:

enter image description here

Can I tell hibernate to map the id and timestamp to the REV and and REVTSTMP columns respectively?

Please help, thanks in advenace.

Upvotes: 1

Views: 1609

Answers (2)

Vel
Vel

Reputation: 16

AttributeOverride should solve this issue.

Please try:

@AttributeOverrides({
    @AttributeOverride(name = "timestamp", column = @Column(name = "REVTSTMP")),
    @AttributeOverride(name = "id", column = @Column(name = "REV"))
})
public class UserRevEntity extends DefaultRevisionEntity {
   private String username;

    public String getUsername() { return username; }

    public void setUsername(String username) { this.username = username; 

}

Upvotes: 0

Khalid Shah
Khalid Shah

Reputation: 3232

Try this.

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;

@Entity
@Table(name = "REVINFO")
@RevisionEntity(UserRevisionListener.class)
public class UserRevEntity extends DefaultRevisionEntity {
    @Column(name = "USERNAME")
    private String username;

    @Column(name = "REV")
    private Integer id;

    @Column(name = "REVTSTMP")
    private BigInteger timestamp;

    // Make getter and setters

    public String getUsername() { return username; }

    public void setUsername(String username) { this.username = username; }
}

Upvotes: 2

Related Questions