SlideShare ist ein Scribd-Unternehmen logo
1 von 32
Envers + Seam + JBoss: Why
to use?
Diogo Souza
Envers + Seam + JBoss:
Why to use?
Better...
The handshake
Diogo Souza
Systems Analyst at Indra Company
http://3adiX.com.br
http://diogosouza.com.br
@diogo_souza_c
Ah, the Envers!
Once upon a time, in 2009…
What they say about…
“The Envers project aims to enable
easy auditing/versioning of persistent
classes […]”
Ref: http://www.jboss.org/envers
What they say about…
“[…] All that you have to do is
annotate your persistent class or
some of its properties, that you want
to audit, with @Audited. […]”
Ref: http://www.jboss.org/envers
What they say about…
“[…] For each audited entity, a table
will be created, which will hold the
history of changes made to the
entity. […]”
Ref: http://www.jboss.org/envers
And the best part…
“[…] You can then retrieve and query
historical data without much effort.”
Ref: http://www.jboss.org/envers
http://www.deviantart.com
Some features:
 Auditing of all mappings defined by
the JPA specification
 Auditing of some Hibernate
mappings, which extend JPA
 Logging data for each revision using
a "revision entity"
 Querying historical data
Ref: http://www.jboss.org/envers
http://www.deviantart.com
Basically
Each transaction...
...One revision
INSERT
UPDATE
DELETE
Where to use?
Wherever you have Hibernate!
 Standalone
 JBoss AS
 Spring
And how do we use in the past?
<property name="hibernate.ejb.event.post-insert"
value="org.hibernate.ejb.event.EJB3PostInsertEventListener,org.hibernat
e.envers.event.AuditEventListener" />
<property name="hibernate.ejb.event.post-update"
value="org.hibernate.ejb.event.EJB3PostUpdateEventListener,org.hiberna
te.envers.event.AuditEventListener" />
<property name="hibernate.ejb.event.post-delete"
value="org.hibernate.ejb.event.EJB3PostDeleteEventListener,org.hibernat
e.envers.event.AuditEventListener" />
<property name="hibernate.ejb.event.pre-collection-update"
value="org.hibernate.envers.event.AuditEventListener" />
<property name="hibernate.ejb.event.pre-collection-remove"
value="org.hibernate.envers.event.AuditEventListener" />
<property name="hibernate.ejb.event.post-collection-recreate"
value="org.hibernate.envers.event.AuditEventListener" />
In persistence.xml or hibernate.cfg.xml
And how to use?
<!-- Add on classpath | Maven -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-envers</artifactId>
<version>4.x.Final</version>
</dependency>
Requirements:
Hibernate 3+
Hibernate annotations
Simple sample
@Entity
public class Adress {
@Id
@GeneratedValue
private int id;
@Audited
private String streetName;
@Audited
private Long zipCode;
@Audited
@ManyToOne
private State state;
}
The whole entity
@Audited
public class Adress {
@Id
@GeneratedValue
private int id;
private String streetName;
private Long zipCode;
@ManyToOne
private State state;
}
@Audited // Here too!
public class State {
@Id
@GeneratedValue
private int id;
private String stateName;
private Long population;
}
… without a field
@Audited
public class Adress {
@Id
@GeneratedValue
private int id;
@NotAudited
private String streetName;
private Long zipCode;
@ManyToOne
private State state;
}
Changing the entity table
name
@Audited
@AuditTable(“TB_ADRESS_AUDIT”)
public class Adress {
@Id
@GeneratedValue
private int id;
@NotAudited
private String streetName;
private Long zipCode;
@ManyToOne
private State state;
}
The database
0 ADD
1 MOD
3 DEL
The revision
date!
Querying for entities of a
class at a given revision
AuditQuery query =
getAuditReader().createQuery()
.forEntitiesAtRevision(MyEntity.class,
revisionNumber);
Querying for revisions, at
which entities of a given class
changed
AuditQuery query =
getAuditReader().createQuery()
.forRevisionsOfEntity(MyEntity.class,
false, true);
Querying for revisions
between revision dates
AuditReader auditReader =
AuditReaderFactory.get(entityManager);
AuditQuery query = auditReader.createQuery()
.forRevisionsOfEntity(Punishment.class, false, true)
.add(AuditEntity.revisionProperty("timestamp")
.gt(timeStamp).lt(otherTimeStamp)
.add(AuditEntity.revisionType().eq(RevisionType.ADD));
List<Object[]> revisions = query.getResultList();
Configuration Properties
// Prefixes and suffixes
org.hibernate.envers.audit_table_prefix
org.hibernate.envers.audit_table_suffix
// Revision number and revision type fields
org.hibernate.envers.revision_field_name
org.hibernate.envers.revision_type_field_name
// Default schema used
org.hibernate.envers.default_schema
Demo Time!
I am not responsible for
any increases in the
number of Brazilian
punishments...
The guy!
Adam Warski
Ref: http://www.warski.org/blog/about/
http://warski.org
Good things!
 Easy!
 Data as always!
 Database schema
doesn’t change
 Minimal code changes
 Integration with
Hibernate/Red Hat
related
Not so good things!
 Dependency of
Hibernate.
 Not compatible with
Hibernate-XML-Age.
 Extra table for each
table.
Story Time!
References/Links
 www.jboss.org/envers
 http://docs.jboss.org/envers/docs/
 http://www.warski.org/blog/
Thanks! 

Weitere ähnliche Inhalte

Andere mochten auch

Processo de automação de artefatos de requisito slides
Processo de automação de artefatos de requisito   slidesProcesso de automação de artefatos de requisito   slides
Processo de automação de artefatos de requisito slides
Thiago Carvalho
 

Andere mochten auch (20)

Sist infgerencial4
Sist infgerencial4Sist infgerencial4
Sist infgerencial4
 
Beefataque
BeefataqueBeefataque
Beefataque
 
Sistema infgerencial5
Sistema infgerencial5Sistema infgerencial5
Sistema infgerencial5
 
Invasaocom exploits
Invasaocom exploitsInvasaocom exploits
Invasaocom exploits
 
Sistemas operacionais 6
Sistemas operacionais 6Sistemas operacionais 6
Sistemas operacionais 6
 
Inteligencia artifical 6
Inteligencia artifical 6Inteligencia artifical 6
Inteligencia artifical 6
 
Ssit informacoesgerenciais 5
Ssit informacoesgerenciais 5Ssit informacoesgerenciais 5
Ssit informacoesgerenciais 5
 
Processo de automação de artefatos de requisito slides
Processo de automação de artefatos de requisito   slidesProcesso de automação de artefatos de requisito   slides
Processo de automação de artefatos de requisito slides
 
Padrões de Projeto
Padrões de ProjetoPadrões de Projeto
Padrões de Projeto
 
Sistemas operacionais 4
Sistemas operacionais 4Sistemas operacionais 4
Sistemas operacionais 4
 
Sistemas operacionais 3
Sistemas operacionais 3Sistemas operacionais 3
Sistemas operacionais 3
 
Inteligencia artificial 4
Inteligencia artificial 4Inteligencia artificial 4
Inteligencia artificial 4
 
Sistemas operacionais1
Sistemas operacionais1Sistemas operacionais1
Sistemas operacionais1
 
Inteligencia artificial 1
Inteligencia artificial 1Inteligencia artificial 1
Inteligencia artificial 1
 
Data science
Data scienceData science
Data science
 
Introdução a Ciência de Dados
Introdução a Ciência de DadosIntrodução a Ciência de Dados
Introdução a Ciência de Dados
 
Testes nao funcionais 1
Testes nao funcionais 1Testes nao funcionais 1
Testes nao funcionais 1
 
Sistemas infgerencial3
Sistemas infgerencial3Sistemas infgerencial3
Sistemas infgerencial3
 
Seguranca informacao 1
Seguranca informacao 1Seguranca informacao 1
Seguranca informacao 1
 
Inteligencia artifical 7
Inteligencia artifical 7Inteligencia artifical 7
Inteligencia artifical 7
 

Ähnlich wie Envers + Seam + JBoss: Why to use?

Developing your first application using FI-WARE
Developing your first application using FI-WAREDeveloping your first application using FI-WARE
Developing your first application using FI-WARE
Fermin Galan
 
An Introduction to Tornado
An Introduction to TornadoAn Introduction to Tornado
An Introduction to Tornado
Gavin Roy
 
Developing your first application using FIWARE
Developing your first application using FIWAREDeveloping your first application using FIWARE
Developing your first application using FIWARE
FIWARE
 

Ähnlich wie Envers + Seam + JBoss: Why to use? (20)

Developing your first application using FI-WARE
Developing your first application using FI-WAREDeveloping your first application using FI-WARE
Developing your first application using FI-WARE
 
Cross-Platform Native Mobile Development with Eclipse
Cross-Platform Native Mobile Development with EclipseCross-Platform Native Mobile Development with Eclipse
Cross-Platform Native Mobile Development with Eclipse
 
Building Modern Apps using Android Architecture Components
Building Modern Apps using Android Architecture ComponentsBuilding Modern Apps using Android Architecture Components
Building Modern Apps using Android Architecture Components
 
BP-6 Repository Customization Best Practices
BP-6 Repository Customization Best PracticesBP-6 Repository Customization Best Practices
BP-6 Repository Customization Best Practices
 
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
 
An Introduction to Tornado
An Introduction to TornadoAn Introduction to Tornado
An Introduction to Tornado
 
OWASP SF - Reviewing Modern JavaScript Applications
OWASP SF - Reviewing Modern JavaScript ApplicationsOWASP SF - Reviewing Modern JavaScript Applications
OWASP SF - Reviewing Modern JavaScript Applications
 
Ambari Views - Overview
Ambari Views - OverviewAmbari Views - Overview
Ambari Views - Overview
 
Developing your first application using FIWARE
Developing your first application using FIWAREDeveloping your first application using FIWARE
Developing your first application using FIWARE
 
APPlause - DemoCamp Munich
APPlause - DemoCamp MunichAPPlause - DemoCamp Munich
APPlause - DemoCamp Munich
 
Boost Development With Java EE7 On EAP7 (Demitris Andreadis)
Boost Development With Java EE7 On EAP7 (Demitris Andreadis)Boost Development With Java EE7 On EAP7 (Demitris Andreadis)
Boost Development With Java EE7 On EAP7 (Demitris Andreadis)
 
Kicking off with Zend Expressive and Doctrine ORM (Sunshine PHP 2017)
Kicking off with Zend Expressive and Doctrine ORM (Sunshine PHP 2017)Kicking off with Zend Expressive and Doctrine ORM (Sunshine PHP 2017)
Kicking off with Zend Expressive and Doctrine ORM (Sunshine PHP 2017)
 
Devoxx 2012 hibernate envers
Devoxx 2012   hibernate enversDevoxx 2012   hibernate envers
Devoxx 2012 hibernate envers
 
Resthub framework presentation
Resthub framework presentationResthub framework presentation
Resthub framework presentation
 
ITT 2015 - Simon Stewart - Building Android Apps at Speed and Scale
ITT 2015 - Simon Stewart - Building Android Apps at Speed and ScaleITT 2015 - Simon Stewart - Building Android Apps at Speed and Scale
ITT 2015 - Simon Stewart - Building Android Apps at Speed and Scale
 
JSONpedia - Facilitating consumption of MediaWiki content
JSONpedia - Facilitating consumption of MediaWiki contentJSONpedia - Facilitating consumption of MediaWiki content
JSONpedia - Facilitating consumption of MediaWiki content
 
Advanced Web Development
Advanced Web DevelopmentAdvanced Web Development
Advanced Web Development
 
Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)
 
MongoDB.local Sydney: Evolving your Data Access with MongoDB Stitch
MongoDB.local Sydney: Evolving your Data Access with MongoDB StitchMongoDB.local Sydney: Evolving your Data Access with MongoDB Stitch
MongoDB.local Sydney: Evolving your Data Access with MongoDB Stitch
 
ASP.NET MVC Workshop for Women in Technology
ASP.NET MVC Workshop for Women in TechnologyASP.NET MVC Workshop for Women in Technology
ASP.NET MVC Workshop for Women in Technology
 

Mehr von Diogo Souza (6)

GraalVM: Harder, Better, Faster, Stronger
GraalVM: Harder, Better, Faster, StrongerGraalVM: Harder, Better, Faster, Stronger
GraalVM: Harder, Better, Faster, Stronger
 
Batch, Spring, Performance e outras coisas mais...
Batch, Spring, Performance e outras coisas mais...Batch, Spring, Performance e outras coisas mais...
Batch, Spring, Performance e outras coisas mais...
 
Desenvolvimento Web: Por que Java?
Desenvolvimento Web: Por que Java?Desenvolvimento Web: Por que Java?
Desenvolvimento Web: Por que Java?
 
Android: Por que usar? Como desenvolver?
Android: Por que usar? Como desenvolver?Android: Por que usar? Como desenvolver?
Android: Por que usar? Como desenvolver?
 
Java, android e o mercado de ti
Java, android e o mercado de tiJava, android e o mercado de ti
Java, android e o mercado de ti
 
Simples pelo simples google android com robo guice
Simples pelo simples   google android com robo guiceSimples pelo simples   google android com robo guice
Simples pelo simples google android com robo guice
 

Kürzlich hochgeladen

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Kürzlich hochgeladen (20)

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 

Envers + Seam + JBoss: Why to use?

  • 1.
  • 2. Envers + Seam + JBoss: Why to use? Diogo Souza
  • 3. Envers + Seam + JBoss: Why to use? Better...
  • 5. Diogo Souza Systems Analyst at Indra Company http://3adiX.com.br http://diogosouza.com.br @diogo_souza_c
  • 6. Ah, the Envers! Once upon a time, in 2009…
  • 7. What they say about… “The Envers project aims to enable easy auditing/versioning of persistent classes […]” Ref: http://www.jboss.org/envers
  • 8. What they say about… “[…] All that you have to do is annotate your persistent class or some of its properties, that you want to audit, with @Audited. […]” Ref: http://www.jboss.org/envers
  • 9. What they say about… “[…] For each audited entity, a table will be created, which will hold the history of changes made to the entity. […]” Ref: http://www.jboss.org/envers
  • 10. And the best part… “[…] You can then retrieve and query historical data without much effort.” Ref: http://www.jboss.org/envers http://www.deviantart.com
  • 11. Some features:  Auditing of all mappings defined by the JPA specification  Auditing of some Hibernate mappings, which extend JPA  Logging data for each revision using a "revision entity"  Querying historical data Ref: http://www.jboss.org/envers http://www.deviantart.com
  • 13. Where to use? Wherever you have Hibernate!  Standalone  JBoss AS  Spring
  • 14. And how do we use in the past? <property name="hibernate.ejb.event.post-insert" value="org.hibernate.ejb.event.EJB3PostInsertEventListener,org.hibernat e.envers.event.AuditEventListener" /> <property name="hibernate.ejb.event.post-update" value="org.hibernate.ejb.event.EJB3PostUpdateEventListener,org.hiberna te.envers.event.AuditEventListener" /> <property name="hibernate.ejb.event.post-delete" value="org.hibernate.ejb.event.EJB3PostDeleteEventListener,org.hibernat e.envers.event.AuditEventListener" /> <property name="hibernate.ejb.event.pre-collection-update" value="org.hibernate.envers.event.AuditEventListener" /> <property name="hibernate.ejb.event.pre-collection-remove" value="org.hibernate.envers.event.AuditEventListener" /> <property name="hibernate.ejb.event.post-collection-recreate" value="org.hibernate.envers.event.AuditEventListener" /> In persistence.xml or hibernate.cfg.xml
  • 15. And how to use? <!-- Add on classpath | Maven --> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-envers</artifactId> <version>4.x.Final</version> </dependency> Requirements: Hibernate 3+ Hibernate annotations
  • 16. Simple sample @Entity public class Adress { @Id @GeneratedValue private int id; @Audited private String streetName; @Audited private Long zipCode; @Audited @ManyToOne private State state; }
  • 17. The whole entity @Audited public class Adress { @Id @GeneratedValue private int id; private String streetName; private Long zipCode; @ManyToOne private State state; } @Audited // Here too! public class State { @Id @GeneratedValue private int id; private String stateName; private Long population; }
  • 18. … without a field @Audited public class Adress { @Id @GeneratedValue private int id; @NotAudited private String streetName; private Long zipCode; @ManyToOne private State state; }
  • 19. Changing the entity table name @Audited @AuditTable(“TB_ADRESS_AUDIT”) public class Adress { @Id @GeneratedValue private int id; @NotAudited private String streetName; private Long zipCode; @ManyToOne private State state; }
  • 20. The database 0 ADD 1 MOD 3 DEL The revision date!
  • 21. Querying for entities of a class at a given revision AuditQuery query = getAuditReader().createQuery() .forEntitiesAtRevision(MyEntity.class, revisionNumber);
  • 22. Querying for revisions, at which entities of a given class changed AuditQuery query = getAuditReader().createQuery() .forRevisionsOfEntity(MyEntity.class, false, true);
  • 23. Querying for revisions between revision dates AuditReader auditReader = AuditReaderFactory.get(entityManager); AuditQuery query = auditReader.createQuery() .forRevisionsOfEntity(Punishment.class, false, true) .add(AuditEntity.revisionProperty("timestamp") .gt(timeStamp).lt(otherTimeStamp) .add(AuditEntity.revisionType().eq(RevisionType.ADD)); List<Object[]> revisions = query.getResultList();
  • 24. Configuration Properties // Prefixes and suffixes org.hibernate.envers.audit_table_prefix org.hibernate.envers.audit_table_suffix // Revision number and revision type fields org.hibernate.envers.revision_field_name org.hibernate.envers.revision_type_field_name // Default schema used org.hibernate.envers.default_schema
  • 26. I am not responsible for any increases in the number of Brazilian punishments...
  • 27. The guy! Adam Warski Ref: http://www.warski.org/blog/about/ http://warski.org
  • 28. Good things!  Easy!  Data as always!  Database schema doesn’t change  Minimal code changes  Integration with Hibernate/Red Hat related
  • 29. Not so good things!  Dependency of Hibernate.  Not compatible with Hibernate-XML-Age.  Extra table for each table.