Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

spring jpa auditing lastmodifiedby and lastmodifiedDate are ok, but createdBy and createdDate annotation are always null [duplicate]

I'm trying to setup (as a java beginner) spring jpa auditing for hours/days now ... and I'm starting to get very frustrating as I can't find the problem. I would really appreciate some help.

@LastModifiedBy and @LastModifiedDate annotations are working, but @CreatedBy and @CreatedDate are always NULL.

Here is the sql query debugging output: 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,122222222126,127,127,M,NULL(VARCHAR),NULL(INTEGER),1)]

The important part is the first 2 parameters which are the @createdBy and @CreatedDate: (NULL(INTEGER),NULL(TIMESTAMP),1,2017-06-16 16:40:39.618

The @ModifiedBy has value: 1 and the @ModifiedDate has value: 2017-06-16 16:40:39.618 Both are correct.

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;

Now orm.xml and 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>

The test I'm trying to run:

@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);
    }

Some of the log output:

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
like image 594
Didier Avatar asked Jun 16 '17 15:06

Didier


1 Answers

Oh my god ... this was so stupid .... I found the problem here: https://github.com/jhipster/generator-jhipster/issues/1774 .

The Problem was that I do an update and while updating the createby and createDate are always NULL. I' have know added the "updatable = false" to both fields and it now working.

So my AbstractAuditedEntity looks some what like this, please note the "updatable = 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;
like image 101
Didier Avatar answered Nov 08 '22 09:11

Didier