简体   繁体   中英

How to customize hibernate @ElementCollection envers audit table name?

I'm currently using Hibernate & Envers version 5.2.9.Final . I want to use @ElementCollection with a custom table name for both the collection and the audit table .

What I know so far is that modifying default table names has a variety of annotations to work with: For the entity itself there are the annotations @Table and @SecondaryTable as well as the corresponding envers annotations @AuditTable and @SecondaryAuditTable. For changing the table name of an element collection there is the @CollectionTable annotaion. I have not been able to find a corresponding envers annotation so far. So my question is:

How can I change the name for a hibernate @ElementCollection envers audit table?


Additional info

In the hibernate envers ticket which tracks the adding of auditing support for element collections, the same question was asked back in 2013 but not answered.

A code snippet to make my setup clear:

@Entity
@Table(name = "\"user\"")
@SecondaryTable(name = "\"user_secondary\"")
@Audited
@AuditTable("\"user_audit\"")
@SecondaryAuditTable(secondaryTableName = "user_secondary",
        secondaryAuditTableName = "\"user_secondary_audit\"")
public class User {

    // ... stuff like id and other fields ...

    @ElementCollection
    @CollectionTable(name = "\"user_references\"")
    private Map<String, Long> references = new HashMap<>();
    // TODO FIXME how to get a custom name for the audit table?

    // ... more stuff like getters and setters
}

Hibernate generates all tables as intended, yet the collecction audit table is named 'user_references_AUD' while I would like to get the name 'user_references_audit' like for the other tables.

I'm also aware of the global settings affecting the audit table prefix or suffix , but that is only a last resort for my use case.


Update

As suggested I added a feature request to Hibernate JIRA.

That is because Envers has no complement for @CollectionTable .

You are welcomed to add a JIRA requesting that we add a complementing annotation and I can look at what is needed to add the functionality. Just at a glance, it shouldn't require too much as it merely needs to feed into the generated Envers entity table name for the collection middle entity.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM