-
1. Audit subclass that extends non-audited superclass
adamw May 12, 2011 3:42 AM (in response to izan)So you don't want to audit any of the fields from the base entity? (Apart from the id, which must be audited)
If so, there's a feature request to implement that, but it's not yet done.
Adam
-
2. Re: Audit subclass that extends non-audited superclass
izan May 12, 2011 4:37 AM (in response to izan)Here is a code example of the abstract entity:
@javax.persistence.Entity
@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
public abstract class Entity<ID extends Serializable>
implements Serializable
{
@Id
@Column(nullable=false)
@GeneratedValue(strategy=GenerationType.TABLE)
private Long id;
public Long getId()
{
return this.id;
}
public void setId(Long id) {
this.id = id;
}
public abstract ID getBusinessKey();
}
And here is the code for a subclass:
@javax.persistence.Entity
@SuppressWarnings("serial")
@Audited
public class TestClass extends Entity<String>{
@Column(nullable = false)
private String name;
@Column(nullable = false)
private Integer value;
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setValue(Integer value) {
this.value = value;
}
public Integer getValue() {
return value;
}
......
Some overrides here
......
}
This, when deployed, throws the following exception
Caused by: org.hibernate.HibernateException: could not init listeners
at org.hibernate.event.EventListeners.initializeListeners(EventListeners.java:205)
at org.hibernate.cfg.Configuration.getInitializedEventListeners(Configuration.java:1338)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1327)
at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:867)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:669)
... 57 more
Caused by: org.hibernate.MappingException: Entity 'com.model.entity.TestClass' is audited, but its superclass: 'com.model.entity.Entity' is not.
at org.hibernate.envers.configuration.metadata.AuditMetadataGenerator.generateInheritanceMappingData(AuditMetadataGenerator.java:327)
at org.hibernate.envers.configuration.metadata.AuditMetadataGenerator.generateFirstPass(AuditMetadataGenerator.java:408)
at org.hibernate.envers.configuration.EntitiesConfigurator.configure(EntitiesConfigurator.java:100)
at org.hibernate.envers.configuration.AuditConfiguration.<init>(AuditConfiguration.java:86)
at org.hibernate.envers.configuration.AuditConfiguration.getFor(AuditConfiguration.java:99)
at org.hibernate.envers.event.AuditEventListener.initialize(AuditEventListener.java:335)
at org.hibernate.event.EventListeners$1.processListener(EventListeners.java:198)
at org.hibernate.event.EventListeners.processListeners(EventListeners.java:181)
at org.hibernate.event.EventListeners.initializeListeners(EventListeners.java:194)
Is it possible to audit this child class in some way?
-
3. Re: Audit subclass that extends non-audited superclass
izan May 12, 2011 4:50 AM (in response to adamw)Oh sorry, I didn't reload the page so I missed your answer before posting :-( The thing is that I don't want every subclass that inherits from the abstract class to be audited, and also that I don't have access to the base class since it is inside a library included in the project. No idea when this feature would be implemented, right? Is there aniway in which I could contribute to the development of this feature? Well, and to the development of envers in general.
Thanks you very much!
-
4. Re: Audit subclass that extends non-audited superclass
adamw May 13, 2011 3:20 AM (in response to izan)1 of 1 people found this helpfulI think this is related to this issue:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-5917
(see the comments)
Am I right?
Adam
-
5. Re: Audit subclass that extends non-audited superclass
izan May 13, 2011 5:32 AM (in response to adamw)Totally right! Is there a solution for this in sight? How can I contribute?
-
6. Re: Audit subclass that extends non-audited superclass
adamw May 14, 2011 12:00 PM (in response to izan)There's also another user interested in fixing the problem (see the comments on the issue), so I suppose the first step would be to work together on some design of how to solve the problem - that is make things configurable enough so that the superclasses may be both audited and not. So maybe let's move the discussion to the issue and take it from there
Adam