我正在尝试设置(作为一个java初学者)SpringJPA审计,时间为数小时/天。。。我开始感到非常沮丧,因为我找不到问题。我真的很感谢你的帮助。
@LastModifiedBy和@LastModifiedDate注释正在工作,但@CreatedBy和@CreatedDate始终为空。
下面是sql查询调试输出:2017-06-16 16:40:39[main]DEBUG n.t.d.l.l。SLF4JQueryLoggingListener n.t.d.s.SLF4JLogUtils writeLog-名称:,时间:0,成功:False,类型:Prepared,批次:False,QuerySize:1,批次大小:0,查询:[“更新申请人设置APT\U AGE\U CRE=?,APT\U DTE\U CRE=?,APT\U AGE\U UPD=?,APT\U DTE\U UPD=?,APT\U地址=?,APT\U出生日期=?,APT\U城市=?,APT\U名字=?,APT\U内部参考=?,APT\U姓氏=?,APT\U矩阵=?,APT\U国籍=?,APT\U国家=?,APT\U性别=?,APT\U状态=?,APT\U邮编=,其中PK\U ID=,APT\U参数为空,时间戳[(空,整数),12017-06-16 16:40:39.618,1,rue des totos,1985-12-30 00:00:00.0,NULL(VARCHAR),Toto,NULL(INTEGER),Xyz,122222126127127,M,NULL(VARCHAR),NULL(INTEGER),1)]
重要的部分是前两个参数,它们是@createdBy和@CreatedDate:(NULL(INTEGER),NULL(TIMESTAMP),1,2017-06-16 16:40:39.618
@ModifiedBy的值为1,@ModifiedDate的值为:2017-06-16 16:40:39.618两者都是正确的。
public class AuditorAwareImpl implements AuditorAware<Agent>{
protected static final Logger LOGGER_DEBUG = LoggerFactory.getLogger("debug");
@Override
public Agent getCurrentAuditor() {
LOGGER_DEBUG.debug("Loading auditor");
Agent agent = new Agent();
agent.setId(1);
return agent;
}
@MappedSuperclass
@EntityListeners(value = {AuditingEntityListener.class})
public class AbstractAuditedEntity extends AbstractEntity {
private static final long serialVersionUID = 7151010030414095019L;
@CreatedBy
@OneToOne @JoinColumn(name = "APT_AGE_CRE", nullable = false)
protected Agent createdBy;
@CreatedDate
@Type(type = "org.jadira.usertype.dateandtime.threeten.PersistentZonedDateTime")
@Column(name = "APT_DTE_CRE", nullable = false) //@DateTimeFormat(pattern = "dd/MM/yyyy HH:mm")
protected ZonedDateTime creationTime;
@LastModifiedBy
@OneToOne @JoinColumn(name = "APT_AGE_UPD", nullable = false)
protected Agent updatedBy;
@LastModifiedDate
@Type(type = "org.jadira.usertype.dateandtime.threeten.PersistentZonedDateTime")
@Column(name = "APT_DTE_UPD", nullable = false) //@DateTimeFormat(pattern = "dd/MM/yyyy HH:mm")
protected ZonedDateTime updatingTime;
}
public class Applicant extends AbstractAuditedEntity {
private static final long serialVersionUID = -5651129526769191543L;
@Id
@Column(name = "PK_APT_NUM_ID")
@SequenceGenerator(name = "ApplicantSequence", sequenceName = "SEQ_APPLICANT", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "ApplicantSequence")
private Integer id;
@Column(name = "APT_INTERNAL_REF")
private Integer internalRef;
@NaturalId(mutable = true)
@Column(name = "APT_MATRICULE", unique = true, length = 13)
@NotNull
@MatriculeValidator
private String matricule;
@Column(name = "APT_SEX", length = 1)
@Enumerated(EnumType.STRING)
@NotNull
private SexCode sexCode;
@Column(name = "APT_LASTNAME", length = 100)
@NotNull
private String lastName;
@Column(name = "APT_FIRSTNAME", length = 100)
@NotNull
private String firstName;
@Column(name = "APT_STATUS", length = 1)
@Enumerated(EnumType.STRING)
private ApplicantStatusCode statusCode;
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "APT_COUNTRY", foreignKey = @ForeignKey(name = "FK_APT_COUNTRY"))
private Country residencyCountry;
@Column(name = "APT_BIRTHDATE")
@NotNull
@DateTimeFormat(pattern = "dd/MM/yyyy")
private ZonedDateTime birthdate;
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "APT_NATIONALITY", foreignKey = @ForeignKey(name = "FK_APT_NATIONALITY"))
private Country nationality;
@Column(name = "APT_ZIP_CODE")
private Integer zipCode;
@Column(name = "APT_ADDRESS", length = 250)
private String address;
@Column(name = "APT_CITY", length = 60)
private String city;
现在,奥姆。xml和applicationContext。xml
<?xml version="1.0" encoding="UTF-8"?>
<entity-mappings
xmlns="http://java.sun.com/xml/ns/persistence/orm"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_2_0.xsd" version="2.0">
<persistence-unit-metadata>
<persistence-unit-defaults>
<entity-listeners>
<entity-listener class="org.springframework.data.jpa.domain.support.AuditingEntityListener" />
</entity-listeners>
</persistence-unit-defaults>
</persistence-unit-metadata>
</entity-mappings>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<context:annotation-config/>
<jpa:repositories base-package="aficom.model.repository" entity-manager-factory-ref="entityManagerFactory"
transaction-manager-ref="transactionManager"/>
<bean id="auditorBean" class="aficom.model.audit.AuditorAwareImpl"/>
<jpa:auditing auditor-aware-ref="auditorBean"/>
<bean id="dataSource" class="org.apache.tomcat.dbcp.dbcp2.BasicDataSource">
<property name="url" value="jdbc:oracle:thin:@localhost:1521:XE"/>
<property name="driverClassName" value="oracle.jdbc.OracleDriver"/>
<property name="username" value="aficom"/>
<property name="password" value="1234"/>
</bean>
<!-- sql proxy -->
<bean id="dataSourceProxy" class="net.ttddyy.dsproxy.support.ProxyDataSource">
<property name="dataSource" ref="dataSource"/>
<property name="listener" ref="listeners"/>
</bean>
<bean id="listeners" class="net.ttddyy.dsproxy.listener.ChainListener">
<property name="listeners">
<list>
<bean class="net.ttddyy.dsproxy.listener.logging.SLF4JQueryLoggingListener"/>
<bean class="net.ttddyy.dsproxy.listener.DataSourceQueryCountListener"/>
</list>
</property>
</bean>
<!-- end sql proxy -->
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="aficom"/>
<property name="packagesToScan" value="aficom.model"/>
<!-- use sql proxy as datasource -->
<property name="dataSource" ref="dataSourceProxy"/>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="showSql" value="true"/>
<property name="database" value="ORACLE"/>
<property name="databasePlatform" value="org.hibernate.dialect.Oracle10gDialect"/>
</bean>
</property>
<property name="jpaProperties">
<props>
<!-- required jadira config for spring jpa auditing -->
<prop key="jadira.usertype.autoRegisterUserTypes">true</prop>
<prop key="jadira.usertype.javaZone">UTC</prop>
<prop key="jadira.usertype.databaseZone">UTC</prop>
</props>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<tx:annotation-driven transaction-manager="transactionManager"/>
</beans>
我正在尝试运行的测试:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({ "classpath:applicationContext.xml"})
@Transactional
public class TestRepo {
protected static final Logger LOGGER_MODEL = LoggerFactory.getLogger("model");
@PersistenceContext protected EntityManager entityManager;
@Test
@Rollback(false)
@Transactional
public void saveApplicant(){
Applicant a = new Applicant();
a.setId(1);
a.setFirstName("Toto");
a.setLastName("Xyz");
a.setAddress("1, rue des totos");
a.setMatricule("122222222126");
a.setSexCode(SexCode.M);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy");
LocalDateTime localDate = LocalDate.parse("30/12/1985",formatter).atStartOfDay();
ZonedDateTime zone = ZonedDateTime.of(localDate, ZoneId.of("Europe/Luxembourg"));
a.setBirthdate(zone);
a.setResidencyCountry(this.entityManager.find(Country.class,127));
a.setNationality(this.entityManager.find(Country.class,127));
LOGGER_MODEL.debug(a.toString());
this.repo.save(a);
}
一些日志输出:
2017-06-16 16:40:38 [main] INFO o.s.o.j.LocalContainerEntityManagerFactoryBean o.s.o.j.AbstractEntityManagerFactoryBean buildNativeEntityManagerFactory - Initialized JPA EntityManagerFactory for persistence unit 'aficom'
2017-06-16 16:40:39 [main] INFO o.s.t.c.t.TransactionContext o.s.t.c.t.TransactionContext startTransaction - Began transaction (1) for test context [DefaultTestContext@73c31181 testClass = TestRepo, testInstance = TestRepo@3d620a1, testMethod = saveApplicant@TestRepo, testException = [null], mergedContextConfiguration = [MergedContextConfiguration@ef718de testClass = TestRepo, locations = '{classpath:TEST-applicationContextDao.xml}', classes = '{}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{}', contextCustomizers = set[[empty]], contextLoader = 'org.springframework.test.context.support.DelegatingSmartContextLoader', parent = [null]]]; transaction manager [org.springframework.orm.jpa.JpaTransactionManager@5e5beb8a]; rollback [false]
Hibernate: select country0_.PK_COU_NUM_ID as PK_COU_NUM_ID1_2_0_, country0_.COU_IBAN_PATTERN as COU_IBAN_PATTERN2_2_0_, country0_.COU_ISO_2 as COU_ISO_3_2_0_, country0_.COU_ISO_3 as COU_ISO_4_2_0_, country0_.COU_LANG as COU_LANG5_2_0_, country0_.COU_NAME as COU_NAME6_2_0_, country0_.COU_NATIONALITY as COU_NATIONALITY7_2_0_, country0_.COU_ZIP_CODE as COU_ZIP_CODE8_2_0_ from COUNTRY country0_ where country0_.PK_COU_NUM_ID=?
2017-06-16 16:40:39 [main] DEBUG n.t.d.l.l.SLF4JQueryLoggingListener n.t.d.s.SLF4JLogUtils writeLog - Name:, Time:2, Success:True, Type:Prepared, Batch:False, QuerySize:1, BatchSize:0, Query:["select country0_.PK_COU_NUM_ID as PK_COU_NUM_ID1_2_0_, country0_.COU_IBAN_PATTERN as COU_IBAN_PATTERN2_2_0_, country0_.COU_ISO_2 as COU_ISO_3_2_0_, country0_.COU_ISO_3 as COU_ISO_4_2_0_, country0_.COU_LANG as COU_LANG5_2_0_, country0_.COU_NAME as COU_NAME6_2_0_, country0_.COU_NATIONALITY as COU_NATIONALITY7_2_0_, country0_.COU_ZIP_CODE as COU_ZIP_CODE8_2_0_ from COUNTRY country0_ where country0_.PK_COU_NUM_ID=?"], Params:[(127)]
Hibernate: select applicant0_.PK_APT_NUM_ID as PK_APT_NUM_ID1_1_0_, applicant0_.APT_AGE_CRE as APT_AGE_CRE14_1_0_, applicant0_.APT_DTE_CRE as APT_DTE_CRE2_1_0_, applicant0_.APT_AGE_UPD as APT_AGE_UPD15_1_0_, applicant0_.APT_DTE_UPD as APT_DTE_UPD3_1_0_, applicant0_.APT_ADDRESS as APT_ADDRESS4_1_0_, applicant0_.APT_BIRTHDATE as APT_BIRTHDATE5_1_0_, applicant0_.APT_CITY as APT_CITY6_1_0_, applicant0_.APT_FIRSTNAME as APT_FIRSTNAME7_1_0_, applicant0_.APT_INTERNAL_REF as APT_INTERNAL_REF8_1_0_, applicant0_.APT_LASTNAME as APT_LASTNAME9_1_0_, applicant0_.APT_MATRICULE as APT_MATRICULE10_1_0_, applicant0_.APT_NATIONALITY as APT_NATIONALITY16_1_0_, applicant0_.APT_COUNTRY as APT_COUNTRY17_1_0_, applicant0_.APT_SEX as APT_SEX11_1_0_, applicant0_.APT_STATUS as APT_STATUS12_1_0_, applicant0_.APT_ZIP_CODE as APT_ZIP_CODE13_1_0_ from APPLICANT applicant0_ where applicant0_.PK_APT_NUM_ID=?
2017-06-16 16:40:39 [main] DEBUG n.t.d.l.l.SLF4JQueryLoggingListener n.t.d.s.SLF4JLogUtils writeLog - Name:, Time:3, Success:True, Type:Prepared, Batch:False, QuerySize:1, BatchSize:0, Query:["select applicant0_.PK_APT_NUM_ID as PK_APT_NUM_ID1_1_0_, applicant0_.APT_AGE_CRE as APT_AGE_CRE14_1_0_, applicant0_.APT_DTE_CRE as APT_DTE_CRE2_1_0_, applicant0_.APT_AGE_UPD as APT_AGE_UPD15_1_0_, applicant0_.APT_DTE_UPD as APT_DTE_UPD3_1_0_, applicant0_.APT_ADDRESS as APT_ADDRESS4_1_0_, applicant0_.APT_BIRTHDATE as APT_BIRTHDATE5_1_0_, applicant0_.APT_CITY as APT_CITY6_1_0_, applicant0_.APT_FIRSTNAME as APT_FIRSTNAME7_1_0_, applicant0_.APT_INTERNAL_REF as APT_INTERNAL_REF8_1_0_, applicant0_.APT_LASTNAME as APT_LASTNAME9_1_0_, applicant0_.APT_MATRICULE as APT_MATRICULE10_1_0_, applicant0_.APT_NATIONALITY as APT_NATIONALITY16_1_0_, applicant0_.APT_COUNTRY as APT_COUNTRY17_1_0_, applicant0_.APT_SEX as APT_SEX11_1_0_, applicant0_.APT_STATUS as APT_STATUS12_1_0_, applicant0_.APT_ZIP_CODE as APT_ZIP_CODE13_1_0_ from APPLICANT applicant0_ where applicant0_.PK_APT_NUM_ID=?"], Params:[(1)]
Hibernate: select agent0_.PK_AGE_NUM_ID as PK_AGE_NUM_ID1_0_0_, agent0_.AGE_ACTIVE as AGE_ACTIVE2_0_0_, agent0_.AGE_EMAIL as AGE_EMAIL3_0_0_, agent0_.AGE_FIRSTNAME as AGE_FIRSTNAME4_0_0_, agent0_.AGE_IAM as AGE_IAM5_0_0_, agent0_.AGE_INFOS as AGE_INFOS6_0_0_, agent0_.AGE_LASTNAME as AGE_LASTNAME7_0_0_, agent0_.AGE_MATRICULE as AGE_MATRICULE8_0_0_, agent0_.AGE_PHONE as AGE_PHONE9_0_0_, agent0_.AGE_PROFILE as AGE_PROFILE10_0_0_, agent0_.AGE_TITLE as AGE_TITLE11_0_0_ from AGENT agent0_ where agent0_.PK_AGE_NUM_ID=?
2017-06-16 16:40:39 [main] DEBUG n.t.d.l.l.SLF4JQueryLoggingListener n.t.d.s.SLF4JLogUtils writeLog - Name:, Time:1, Success:True, Type:Prepared, Batch:False, QuerySize:1, BatchSize:0, Query:["select agent0_.PK_AGE_NUM_ID as PK_AGE_NUM_ID1_0_0_, agent0_.AGE_ACTIVE as AGE_ACTIVE2_0_0_, agent0_.AGE_EMAIL as AGE_EMAIL3_0_0_, agent0_.AGE_FIRSTNAME as AGE_FIRSTNAME4_0_0_, agent0_.AGE_IAM as AGE_IAM5_0_0_, agent0_.AGE_INFOS as AGE_INFOS6_0_0_, agent0_.AGE_LASTNAME as AGE_LASTNAME7_0_0_, agent0_.AGE_MATRICULE as AGE_MATRICULE8_0_0_, agent0_.AGE_PHONE as AGE_PHONE9_0_0_, agent0_.AGE_PROFILE as AGE_PROFILE10_0_0_, agent0_.AGE_TITLE as AGE_TITLE11_0_0_ from AGENT agent0_ where agent0_.PK_AGE_NUM_ID=?"], Params:[(1)]
2017-06-16 16:40:39 [main] DEBUG debug l.e.m.a.m.a.AuditorAwareImpl getCurrentAuditor - Loading auditor
2017-06-16 16:40:39 [main] DEBUG debug l.e.m.a.m.a.AuditorAwareImpl getCurrentAuditor - Loading auditor
Hibernate: update APPLICANT set APT_AGE_CRE=?, APT_DTE_CRE=?, APT_AGE_UPD=?, APT_DTE_UPD=?, APT_ADDRESS=?, APT_BIRTHDATE=?, APT_CITY=?, APT_FIRSTNAME=?, APT_INTERNAL_REF=?, APT_LASTNAME=?, APT_MATRICULE=?, APT_NATIONALITY=?, APT_COUNTRY=?, APT_SEX=?, APT_STATUS=?, APT_ZIP_CODE=? where PK_APT_NUM_ID=?
2017-06-16 16:40:39 [main] DEBUG n.t.d.l.l.SLF4JQueryLoggingListener n.t.d.s.SLF4JLogUtils writeLog - Name:, Time:0, Success:False, Type:Prepared, Batch:False, QuerySize:1, BatchSize:0, Query:["update APPLICANT set APT_AGE_CRE=?, APT_DTE_CRE=?, APT_AGE_UPD=?, APT_DTE_UPD=?, APT_ADDRESS=?, APT_BIRTHDATE=?, APT_CITY=?, APT_FIRSTNAME=?, APT_INTERNAL_REF=?, APT_LASTNAME=?, APT_MATRICULE=?, APT_NATIONALITY=?, APT_COUNTRY=?, APT_SEX=?, APT_STATUS=?, APT_ZIP_CODE=? where PK_APT_NUM_ID=?"], Params:[(NULL(INTEGER),NULL(TIMESTAMP),1,2017-06-16 16:40:39.618,1, rue des totos,1985-12-30 00:00:00.0,NULL(VARCHAR),Toto,NULL(INTEGER),Xyz,1122222222126,127,127,M,NULL(VARCHAR),NULL(INTEGER),1)]
2017-06-16 16:40:39 [main] WARN o.h.e.j.s.SqlExceptionHelper o.h.e.j.s.SqlExceptionHelper logExceptions - SQL Error: 1407, SQLState: 72000
2017-06-16 16:40:39 [main] ERROR o.h.e.j.s.SqlExceptionHelper o.h.e.j.s.SqlExceptionHelper logExceptions - ORA-01407: cannot update ("AFICOM"."APPLICANT"."APT_DTE_CRE") to NULL
2017-06-16 16:40:39 [main] INFO o.h.e.j.b.i.AbstractBatchImpl o.h.e.j.b.i.AbstractBatchImpl release - HHH000010: On release of batch it still contained JDBC statements
2017-06-16 16:40:39 [main] ERROR o.h.i.ExceptionMapperStandardImpl o.h.i.ExceptionMapperStandardImpl mapManagedFlushFailure - HHH000346: Error during managed flush [org.hibernate.exception.ConstraintViolationException: could not execute statement]
2017-06-16 16:40:39 [main] WARN o.s.t.c.TestContextManager o.s.t.c.TestContextManager afterTestMethod - Caught exception while allowing TestExecutionListener [org.springframework.test.context.transaction.TransactionalTestExecutionListener@4cf4d528] to process 'after' execution for test: method [public void TestRepo.saveApplicant()], instance [TestRepo@3d620a1], exception [null]
org.springframework.dao.DataIntegrityViolationException: could not execute statement; SQL [n/a]; constraint [null]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException(HibernateJpaDialect.java:278)
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:244)
at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:521)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:761)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:730)
at org.springframework.test.context.transaction.TransactionContext.endTransaction(TransactionContext.java:128)
at org.springframework.test.context.transaction.TransactionalTestExecutionListener.afterTestMethod(TransactionalTestExecutionListener.java:227)
at org.springframework.test.context.TestContextManager.afterTestMethod(TestContextManager.java:319)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:94)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:252)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: org.hibernate.exception.ConstraintViolationException: could not execute statement
at org.hibernate.dialect.Oracle8iDialect$3.convert(Oracle8iDialect.java:551)
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:111)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:97)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:208)
at org.hibernate.engine.jdbc.batch.internal.NonBatchingBatch.addToBatch(NonBatchingBatch.java:45)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:3188)
at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:3067)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:3447)
at org.hibernate.action.internal.EntityUpdateAction.execute(EntityUpdateAction.java:145)
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:589)
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:463)
at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:337)
at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:39)
at org.hibernate.internal.SessionImpl.doFlush(SessionImpl.java:1435)
at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:491)
at org.hibernate.internal.SessionImpl.flushBeforeTransactionCompletion(SessionImpl.java:3201)
at org.hibernate.internal.SessionImpl.beforeTransactionCompletion(SessionImpl.java:2411)
at org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.beforeTransactionCompletion(JdbcCoordinatorImpl.java:467)
at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.beforeCompletionCallback(JdbcResourceLocalTransactionCoordinatorImpl.java:146)
at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.access$100(JdbcResourceLocalTransactionCoordinatorImpl.java:38)
at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl$TransactionDriverControlImpl.commit(JdbcResourceLocalTransactionCoordinatorImpl.java:220)
at org.hibernate.engine.transaction.internal.TransactionImpl.commit(TransactionImpl.java:68)
at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:517)
... 24 common frames omitted
Caused by: java.sql.SQLException: ORA-01407: cannot update ("AFICOM"."APPLICANT"."APT_DTE_CRE") to NULL
at oracle.jdbc.driver.T4CTTIoer11.processError(T4CTTIoer11.java:494)
at oracle.jdbc.driver.T4CTTIoer11.processError(T4CTTIoer11.java:446)
at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:1054)
at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:623)
at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:252)
at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:612)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:226)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:59)
at oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreparedStatement.java:910)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1119)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3780)
at oracle.jdbc.driver.T4CPreparedStatement.executeInternal(T4CPreparedStatement.java:1343)
at oracle.jdbc.driver.OraclePreparedStatement.executeLargeUpdate(OraclePreparedStatement.java:3865)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:3845)
at oracle.jdbc.driver.OraclePreparedStatementWrapper.executeUpdate(OraclePreparedStatementWrapper.java:1061)
at org.apache.tomcat.dbcp.dbcp2.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:97)
at org.apache.tomcat.dbcp.dbcp2.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:97)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at net.ttddyy.dsproxy.proxy.PreparedStatementProxyLogic.invoke(PreparedStatementProxyLogic.java:171)
at net.ttddyy.dsproxy.proxy.jdk.PreparedStatementInvocationHandler.invoke(PreparedStatementInvocationHandler.java:32)
at com.sun.proxy.$Proxy63.executeUpdate(Unknown Source)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:205)
... 43 common frames omitted
Caused by: oracle.jdbc.OracleDatabaseException: ORA-01407: cannot update ("AFICOM"."APPLICANT"."APT_DTE_CRE") to NULL
at oracle.jdbc.driver.T4CTTIoer11.processError(T4CTTIoer11.java:498)
... 67 common frames omitted
Process finished with exit code -1
天啊...这太愚蠢了......我在这里发现了问题:https://github.com/jhipster/generator-jhipster/issues/1774。
问题是我做了一个更新,在更新createby和createDate时总是空的。我知道在这两个字段中都添加了“updateable=false”,现在它可以工作了。
所以我的AbstractAuditedEntity看起来像这样,请注意“updateable=false”:
@CreatedBy
@OneToOne @JoinColumn(name = "APT_AGE_CRE", nullable = false, updatable = false)
protected Agent createdBy;
@CreatedDate
@Type(type = "org.jadira.usertype.dateandtime.threeten.PersistentZonedDateTime")
@Column(name = "APT_DTE_CRE", nullable = false, updatable = false) //@DateTimeFormat(pattern = "dd/MM/yyyy HH:mm")
protected ZonedDateTime creationTime;
我使用的是spring boot,因此我没有使用任何xml文件进行配置。我要做的是,在使用MongoRepositories保存数据时,启用OngOAuditing以保存createdDate、lastModifiedDate等。 我的模特课 我使用@CreateDate注释来保存createDate。我对DateTime使用了jodatime依赖项 Spring-data-mongoDB也添加在
我正在使用Spring Mongo审计和@CreatedDate@CreatedBy不工作,但@LastModifiedDate和@LastModifiedBy工作正常。 我在配置类上添加了@EnableMongoAudting,并定义了AuditAware。 审核类别为: 当我保存文档时,它在createdOn和createdBy中都设置为null,但在modifiedOn和modifiedBy
我正在使用spring数据的审计能力,并且有一个类似于这样的类: 现在,我相信我已经很好地配置了审计,因为我可以看到在更新域对象时,createdBy、createdDate、lastModifiedBy和lastModifiedDate都得到了正确的值。 但是,我的问题是,当我更新一个对象时,我会丢失createdBy和createddate的值。所以,当我第一次创建对象时,我有所有四个值,但是
我已经将一个旧的spring boot 1.5.3项目更新为spring boot 2.0.0。释放我有一个审计实体,有两个ZonedDateTime类型的字段,用@CreatedBy和@LastModifiedDate注释。 在以前的版本中,一切正常。然而,在新的更新中,在存储库中保存实体时,我会遇到一个错误,即 我检查了AnnotationAuditingMetaData,我发现与ZonedD
我使用的是Spring数据JDBC。 我有一个实体,其中的字段用
我在spring data jdbc中使用简单的crud操作和审计。因此,当我插入新记录时,审计工作完全正常。但是当我更新我的记录时,我的createdby和createddate设置为null。有什么方法可以避免修改这些列吗? 注意:column(可更新= false)特性不支持spring data jdbc。 我的审计实体如下所示: 以及使用@EnableJdbcAuditing和定义下面的