Sto lavorando al progetto in cui utilizzo Spring Data. Volevo compilare il campo creationTime
utilizzando l'annotazione @CreatedDate
utilizzando il metodo con l'annotazione @PreUpdate
o @PrePersist
(in questo modo funziona perfettamente). Quando lo faccio con @CreatedDate
lascia questo campo vuoto. Io uso il database postgresql. Documentation non è molto utile.L'annotazione Spring Data @CreatedDate non funziona per me
Avete idea di come posso risolvere il problema? Grazie!
import org.springframework.data.annotation.CreatedDate;
@Entity
@Table(name = "software")
public class Software implements Serializable {
// ...
@Column(name = "creation_time")
@CreatedDate
private Date creationTime;
//...
}
mio applicationContext
:
<jpa:repositories base-package="path.to.dao"/>
<context:component-scan base-package="path.to.dao"/>
<context:property-placeholder location="classpath:application.properties"/>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${db.driver}"/>
<property name="url" value="${db.url}"/>
<property name="username" value="${db.username}"/>
<property name="password" value="${db.password}"/>
</bean>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="packagesToScan" value="path.to.bean"/>
<property name="dataSource" ref="dataSource"/>
<property name="jpaVendorAdapter" ref="jpaAdapter"/>
<property name="jpaProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
<prop key="hibernate.ejb.naming_strategy">${hibernate.ejb.naming_strategy}</prop>
<prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
</props>
</property>
</bean>
<bean id="jpaAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"/>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
Che cosa stai usando per mantenere l'entità? –
Quello che voglio dire è che stai usando 'Session' o stai persistendo attraverso un servizio Spring Data? –
Ho un'interfaccia 'SoftwareRespository' che estende' JpaRepository ' –
alicjab