3
我在使用JPA AttributeConverter
與彈簧引導1.2.1 RELEASE,它工作正常。但我得到以下錯誤升級到春季啓動1.3.0.RELEASE嘗試應用AttributeConverter時出錯
Caused by: javax.persistence.PersistenceException: Error attempting to apply AttributeConverter
at org.hibernate.type.descriptor.converter.AttributeConverterSqlTypeDescriptorAdapter$1.bind(AttributeConverterSqlTypeDescriptorAdapter.java:103)
at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:286)
at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:281)
at org.hibernate.type.AbstractSingleColumnStandardBasicType.nullSafeSet(AbstractSingleColumnStandardBasicType.java:56)
at org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:2843)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:3248)
at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:3183)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:3525)
at org.hibernate.action.internal.EntityUpdateAction.execute(EntityUpdateAction.java:159)
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:465)
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:351)
at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:350)
at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:56)
at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1258)
at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:425)
at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.beforeTransactionCommit(JdbcTransaction.java:101)
at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.commit(AbstractTransactionImpl.java:177)
at org.hibernate.jpa.internal.TransactionImpl.commit(TransactionImpl.java:77)
at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:517)
... 81 more
Caused by: java.lang.NullPointerException
at rafito.spring.boot.domain.TimestampPersistenceConverter.convertToDatabaseColumn(TimestampPersistenceConverter.java:16)
at rafito.spring.boot.domain.TimestampPersistenceConverter.convertToDatabaseColumn(TimestampPersistenceConverter.java:10)
at org.hibernate.type.descriptor.converter.AttributeConverterSqlTypeDescriptorAdapter$1.bind(AttributeConverterSqlTypeDescriptorAdapter.java:97)
我不會在我的崗位設置JSON和serviceBeginTime目前serviceEndTime後。但是在升級彈簧啓動版本之前,這並沒有給我一個空指針。
Converter類
實體
@Column(name = "service_begin_time")
@Convert(converter = TimestampPersistenceConverter.class)
Long serviceBeginTime;
@Column(name = "service_end_time")
@Convert(converter = TimestampPersistenceConverter.class)
Long serviceEndTime;
數據庫領域
service_begin_time timestamp without time zone,
service_end_time timestamp without time zone,
爲什麼你不看異常的堆棧跟蹤,也許有一個嵌套的異常。最好還是把它發佈在問題中,然後人們得到信息 –
,所以你的轉換器中有一個NPE ......所以也許你的轉換器需要修復以適應零值。 –
是的。那是我的解決方法'@Override public timestamp convertToDatabaseColumn(Long aLong){ if(aLong == null) return null; 返回新的時間戳(aLong); }' – Appy