In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail what is the time zone setting mode of JPA + AuditingEntityListener in SpringBoot. The content of the article is of high quality, so the editor will share it with you for reference. I hope you will have some understanding of the relevant knowledge after reading this article.
JPA + AuditingEntityListener time zone settin
In a SpringBoot project, if the application enables EnableJpaAuditing and uses AuditingEntityListener to automatically audit the creation time and update time of the entity, there may be inconsistencies between the time zone of the generation time and the system time zone.
The following configurations can be added to the application configuration
Set the time zone to the specified time zone:
Spring.jpa.properties.hibernate.jdbc.time_zone = GMT+8@EntityListeners (AuditingEntityListener.class) introduction @ EntityListeners
Source code
/ * * Specifies the callback listener classes to be used for an * entity or mapped superclass. This annotation may be applied * to an entity class or mapped superclass. * * @ since Java Persistence 1.0 * / @ Target ({TYPE}) @ Retention (RUNTIME) public @ interface EntityListeners {/ * * The callback listener classes * / Class [] value ();}
Analysis.
The role of this annotation can be clearly understood from the comments on the source code, which is simply translated as follows: this annotation is used to specify the callback listener class on Entity or superclass. This annotation can be used on Entity or superclass.
AuditingEntityListener.class
Source code
/ * JPA entity listener to capture auditing information on persiting and updating entities. To get this one flying be * sure you configure it as entity listener in your {@ code orm.xml} as follows: * After that it's just a matter of activating auditing in your Spring config: * @ Configuration * @ EnableJpaAuditing * class ApplicationConfig {* *} * * * @ author Oliver Gierke * @ author Thomas Darimont * / @ Configurablepublic class AuditingEntityListener {private ObjectFactory handler / * * Configures the {@ link AuditingHandler} to be used to set the current auditor on the domain types touched. * * @ param auditingHandler must not be {@ literal null}. * / public void setAuditingHandler (ObjectFactory auditingHandler) {Assert.notNull (auditingHandler, "AuditingHandler must not be null!"); this.handler = auditingHandler;} / * * Sets modification and creation date and auditor on the target object in case it implements {@ link Auditable} on * persist events. * * @ param target * / @ PrePersist public void touchForCreate (Object target) {if (handler! = null) {handler.getObject () .markCreated (target);} / * * Sets modification and creation date and auditor on the target object in case it implements {@ link Auditable} on * update events. * * @ param target * / @ PreUpdate public void touchForUpdate (Object target) {if (handler! = null) {handler.getObject () .markModified (target);}
Analysis.
You can also see the role of the class from the comments of the class: this is a JPA Entity Listener that captures listening information when the Entity is persisted and updated.
On the SpringBoot JPA + AuditingEntityListener time zone setting is what is shared here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.