Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8392393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:30:27+00:00 2026-06-09T19:30:27+00:00

I’m wanting to use Envers to audit a many-to-many relation with an embedded component

  • 0

I’m wanting to use Envers to audit a many-to-many relation with an embedded component but I’m having trouble with a MappingException saying the the ComponentType is not supported. This is relevant portion of the stack trace:

Caused by: org.hibernate.MappingException: Type not supported: org.hibernate.type.ComponentType
        at org.hibernate.envers.configuration.metadata.IdMetadataGenerator.addIdProperties(IdMetadataGenerator.java:74)
        at org.hibernate.envers.configuration.metadata.IdMetadataGenerator.addId(IdMetadataGenerator.java:105)
        at org.hibernate.envers.configuration.metadata.AuditMetadataGenerator.generateFirstPass(AuditMetadataGenerator.java:413)
        at org.hibernate.envers.configuration.EntitiesConfigurator.configure(EntitiesConfigurator.java:101)
        at org.hibernate.envers.configuration.AuditConfiguration.<init>(AuditConfiguration.java:103)
        at org.hibernate.envers.configuration.AuditConfiguration.getFor(AuditConfiguration.java:135)
        at org.hibernate.envers.event.EnversIntegrator.integrate(EnversIntegrator.java:63)
        at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:295)
        at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1737)
        at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:76)
        at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:905)

Reading the Envers reference, it appears that Envers can handle
what I’m trying to do. According to the reference:

If you’d like to override auditing behaviour of some fields/properties inherited from @Mappedsuperclass or in an embedded component, you can apply the @AuditOverride(s) annotation on the subtype or usage site of the component.

Here’s my association entity. You can see where I tried to use @AuditOverride at the class level to prevent auditing the embedded component. I also tried using the annotation on the field itself. Neither made a difference.

@Audited
//  @AuditOverride(name = "pk", isAudited = false) <===== Didn't help
@Table(name = "user_role")
@javax.persistence.Entity
@AssociationOverrides
(
    {
    @AssociationOverride
        (name = "pk.user", joinColumns = @JoinColumn(name = "id")),
    @AssociationOverride
        (name = "pk.role", joinColumns = @JoinColumn(name = "id"))
    }
)
public class UserRole extends Entity<UserRole>
{
    private static final long serialVersionUID = 1L;

    private Date expirationDate;
    private UserRolePk pk = new UserRolePk();

    public UserRole() {}

    //  @AuditOverride(name = "pk", isAudited = false) <== Didn't help
    @EmbeddedId
    public UserRolePk getPk() { return pk; }

    @Transient
    public User getUser() { return getPk().getUser(); }

    @Transient
    public Role getRole() { return getPk().getRole(); }
...
}

Here’s the user entity:

@Audited
@Table(name = "applicationuser")
@javax.persistence.Entity
public class User extends Entity<User>
{
    private static final long serialVersionUID = 1L;
    private String firstName;
    private String lastName;
    private String email;
    private Set<UserRole> userRoles = new HashSet<UserRole>(0);

    @OneToMany(fetch = FetchType.LAZY, cascade=CascadeType.ALL,
        mappedBy = "pk.user", orphanRemoval = true)

    public Set<UserRole> getUserRoles() { return userRoles; }
...
}

Here’s the role entity:

@Audited
@Table(name = "role")
@javax.persistence.Entity
public class Role extends Entity<Role>
{
    private static final long serialVersionUID = 1L;
    private String name;
    private String label;
    private Set<UserRole> userRoles = new HashSet<UserRole>(0);

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "pk.role",
        cascade=CascadeType.ALL, orphanRemoval = true)

    public Set<UserRole> getUserRoles() { return userRoles; }
...
}

Here’s the embedded component:

@Embeddable
public class UserRolePk implements Serializable
{
    private static final long serialVersionUID = 1L;

    private User user;
    private Role role;

    @ManyToOne
    public User getUser() { return user; }

    @ManyToOne
    public Role getRole() { return role; }
...
}

And finally, here is my base entity, for completeness:

@MappedSuperclass()
public abstract class Entity<X extends Entity<X>>
    implements Comparable<X>, Serializable
{
    private static final long serialVersionUID = 1L;
    private Long id;
    private Timestamp timestamp;
...
}

I’ve read the Envers reference and perused the forum, but the information
seems pretty sparse. Any ideas or pointers on this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T19:30:29+00:00Added an answer on June 9, 2026 at 7:30 pm

    I resolved this by discarding the embeddable component, UserRolePk, and just going with @JoinColumn e.g.

    public class UserRole extends Entity<UserRole>
    {
        private User user;
        private Role role;
    
        public UserRole() {}
    
        @ManyToOne(fetch=FetchType.EAGER, optional=false)
        @JoinColumn(name="userid", referencedColumnName = "id", insertable=false, updatable=false)
        // XmlTransient used to prevent the following exception when JAXB marshals this into XML:
        //  com.sun.istack.SAXException2: A cycle is detected in the object graph. This will cause
        //  infinitely deep XML:
        @XmlTransient
        public User getUser() { return this.user; }
    
        @ManyToOne(fetch=FetchType.EAGER, optional=false)
        @JoinColumn(name="roleid", referencedColumnName = "id", insertable=false, updatable=false)
        public Role getRole() { return this.role; }
    ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
Seemingly simple, but I cannot find anything relevant on the web. What is the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.