Comments (7)
Oliver Drotbohm commented
I exposed the setDateTimeForNow
property in the namespace element so that you simply switch of setting the date by configuring the auditing this way:
<jpa:auditing set-dates="false" />
Should be available in tonights snapshot so feel free to give it a try
from spring-data-jpa.
Rain Wang commented
But how I process the lastUpdatedDate every update?
from spring-data-jpa.
Rain Wang commented
How about add a 'dateAware' property in the namespace element so that we can supply the date by configuring the auditing this way:
<code>
<jpa:auditing auditor-aware-ref="auditorAware" date-aware-ref="dateAware" />
</code>
from spring-data-jpa.
Oliver Drotbohm commented
What is that you are actually trying to achieve? So far the usecases have been either to let the library set the date or disable that and let the database add the dates (e.g. by using triggers). I have a hard time coming up with a scenario where anything else makes sense. I'm not against adding that abstraction, I just want to get the actual rational you're asking for it :)
from spring-data-jpa.
Rain Wang commented
For example: I have a static method(e.g. getCurrentDbTime()) in my util class to get the current time from a database, I want to use the method to replace all of the 'new Date()', to ensure that all instances of current_time is consistent. So I want to have a dateAware property to touch the date by my method. The 'dbTime' I have mentioned isn't meaning to use triggers, just use my static method.
public interface DateAware {
DateTime getCurrentDateTime();
}
public class AuditingEntityListener<T> implements InitializingBean {
...
private DateAware dateAware;
public void setDateAware(final DateAware dateAware) {
this.dateAware = dateAware;
}
...
private DateTime touchDate(final Auditable<T, ?> auditable) {
DateTime now = new DateTime();
if (null != dateAware) {
now = dateAware.getCurrentDateTime();
}
...
}
...
}
public class AuditingBeanDefinitionParser implements BeanDefinitionParser {
...
public BeanDefinition parse(Element element, ParserContext parser) {
...
String dateAwareRef = element.getAttribute("date-aware-ref");
if (StringUtils.hasText(dateAwareRef)) {
builder.addPropertyValue("dateAware", createLazyInitTargetSourceBeanDefinition(dateAwareRef));
}
...
}
...
}
public class DateAwareStub implements DateAware {
public DateTime getCurrentDateTime() {
// TODO get current date from database
DateTime now = new DateTime();
return now;
}
}
<jpa:auditing auditor-aware-ref="auditorAware" date-aware-ref="dateAware" />
<bean id="auditorAware" class="org.springframework.data.jpa.domain.sample.AuditorAwareStub"/>
<bean id="dateAware" class="org.springframework.data.jpa.domain.sample.DateAwareStub" />
from spring-data-jpa.
Oliver Drotbohm commented
Okay, that seems to make sense. Reopening. Thanks for the explaination
from spring-data-jpa.
Oliver Drotbohm commented
Introduced DateTimeProvider
and exposed that one throguh the namespace. Default implementation contains the behavior we had so far
from spring-data-jpa.
Related Issues (20)
- Spring Data JPA projection to records using native queries does not work HOT 6
- potentiallyWrapWithWildcards usage is wrong in StringQuery HOT 1
- Release 3.1.11 (2023.0.11)
- Release 3.2.5 (2023.1.5)
- Release 3.3 RC1 (2024.0.0)
- Cannot use "IgnoreCase" in Spring boot data JPA with SQL server database HOT 3
- I'm curious about why SimpleJpaRepository checks twice whether the entity is in a persistent state when calling the delete method. HOT 14
- Query Generation Regression when using EntityGraphs on Version 3.2.3 and Hibernate 6.4.4.Final HOT 7
- Cannot run/debug tests with IntelliJ IDEA HOT 1
- Creation Timestamp updating in result but when I get from database nothing changes. HOT 1
- Multi-Tenancy with Spring boot(2.7.18) + Hibernate: "SessionFactory configured for multi-tenancy, but no tenant identifier specified" HOT 2
- Calling Postgres Function From Spring data jpa repository HOT 1
- Align OffsetScrolling to zero-based indexes
- Problem with Spring Data JPA with projections, specifications and SPEL HOT 3
- Repositories do not support collections mapped to SQL arrays HOT 1
- Suboptimal specification queries for object arrays HOT 5
- Broaden integration test runs against Hibernate 6
- Projections with findBy select can't / doesn't trim fields
- Spring Data JPA creates a query according to method name regardless of existing named query HOT 1
- JPA projection cannot project OffsetDateTime from timestampz HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from spring-data-jpa.