Spring Boot JPA 2.0.4 Auditing broken? - spring-boot

I upgraded my app from Boot 2.0.3 to 2.0.4 and now #CreatedDate and #LastModifiedDate from JPA Data Auditing are null rather than containing dates.
DB config contains #EnableJpaAuditing and the model contains
#EntityListeners(AuditingEntityListener.class)
...
#CreatedDate
private Date createdAt;
#LastModifiedDate
private Date updatedAt;
Worked as expected prior to the upgrade.
Any ideas?

Related

#Transient - Why data is getting saved in Database?

I have an entity variable annotated with #Transient like below. Which means it should not be stored in the Database.
#Transient
private String passwordConfirm;
But when I go to H2-Console, I can see the data is saved there.
Why so? and How can I avoid it?
You're probably using #org.springframework.data.annotation.Transient.
Change it to the right import: #javax.persistence.Transient
This will do the job.
#javax.persistence.Transient is used by the persistence provider (eg.: Hibernate). The persistence provider looks for JPA spec annotations. #org.springframework.data.annotation.Transient is not a part of the JPA spec, so, the persistence provider ignores it.
The #org.springframework.data.annotation.Transient is intended to be used when Spring Data is the actual ORM. Some examples are Spring Data Elasticsearch and Spring Data MongoDB. These Spring Data implementations use the #org.springframework.data.annotation.Transient just like Hibernate uses the #javax.persistence.Transient - not mapping the marked field into the database.

What's the difference between #CreationTimestamp and #CreatedDate in Spring boot jpa?

#Entity
public class Foo {
#CreatedDate
private LocalDateTime createdDateTime;
#CreationTimestamp
private LocalDateTime creationTimestamp;
}
In Spring boot entity class
I don't know which one to use
What's the different?
#CreatedDate is a Spring annotation and covered in the reference documentation. It is applicable to all stores covered by Spring Data: JPA, JDBC, R2DBC, MongoDb, Cassandra and so on.
#CreationTimestamp is a Hibernate annotation covered in the reference documentation. It is applicable to Hibernate only.
As far as what they actually do they are pretty much the same with the Spring variant supporting more data types.

Use Hibernate with Spring Boot, Wildfly and Oracle DB

I'm trying to understand how to write a simple method to retrieve data from a DB without success.
I'm using Spring Boot 2.1, Hibernate (provided by Spring Boot), Wildfly 14 and Oracle 12.
Connection with the DB seems to work using datasources on standalone.xml (read by the application.properties file). My problem is that if I try to use EntityManager, EntityManagerFactory or Repositories they are always null and I cannot understand why.
Probably I'm missing something on the configuration. My application.properties is:
# Datasource
spring.datasource.jndi-name=java:/TestDB
# Hibernate
hibernate.dialect: org.hibernate.dialect.Oracle10gDialect
hibernate.show_sql: true
# logging
logging.pattern.console=%d{yyyy-MM-dd HH:mm:ss} %-5level %logger{36} - %msg%n
logging.level.org.hibernate.SQL=debug
I defined a simple Entity like this
public class MyEntity {
#Id
#Column
private int myId;
private int anotherData;
... (getters and setters) ...
}
Now I don't know what to do.
I created a DAO class with some Autowired variables (like EntityManagerFactory) but they're always null.
How can I manipulate my entities?
I foud the solution looking at this example.

How to autowire NamedParameterJdbcTemplate in Spring Boot

I understand that Spring Boot automatically configure JDBCTemplate for us. But i don't know exactly which way is correct when i want to autowire NamedParameterJdbcTemplate.
private NamedParameterJdbcTemplate template
or
private NamedParameterJdbcTemplate namedParameterJdbcTemplate;
P.S : i'm using Spring Boot 1.5.1 Release
I just found the answer by reading Spring Boot API, both ways are working and it does not depend on what we name it. Problem was solved.

Upgrading to Spring Boot 1.5.1, #Valid no longer triggering validation

Upgraded an application to Spring Boot 1.5.1. I have controllers defined like:
public ResponseEntity<MappingJacksonValue> save(#Valid #RequestBody Brand brand, BindingResult bindingResult) {
...
}
When I execute my integration tests and expect validation to fail on Brand because of a #Size or #NotNull constraint, they never fail.
I upgraded to version 1.5.2.RELEASE and the #valid annotation returned to work.

Resources