persist()中的SQL语法异常

时间:2015-07-28 14:45:11

标签: hibernate jpa hibernate-mapping

我试图坚持一个实体,但收到错误:

could not execute statement; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not execute statement

执行时

public void createTransaction(PositionTransaction account){
        em.persist(account);
        em.refresh(account);
    }

所有account字段都已填写(id除外 - 它是一个IDENTITY) enter image description here

这是我对PositionTransaction的映射:

@Entity
@Table(name = "POSITION_PROJ_TRANSACTION")
public class PositionTransaction {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "ID", columnDefinition = "NUMERIC(15, 0)",unique = true,nullable = false)
private Long id;

@Column(name = "VALUE_DATE")
private LocalDate valueDate;

@Column(name = "AMOUNT")
private BigDecimal balance;

@Column(name = "COMMENT")
private String comment;

@Column(name = "STATUS")
private Integer status;

@ManyToOne
@JoinColumn(name = "PARENT_ID")
private FaAccount positionAccount;
public FaAccount getPositionAccount() { return positionAccount; }
public void setPositionAccount(FaAccount positionAccount) {
    this.positionAccount = positionAccount;
}

public Long getId() {
    return id;
}

public void setId(Long id) {
    this.id = id;
}

public LocalDate getValueDate() {
    return valueDate;
}

public void setValueDate(LocalDate valueDate) {
    this.valueDate = valueDate;
}

public BigDecimal getBalance() {
    return balance;
}

public void setBalance(BigDecimal balance) {
    this.balance = balance;
}

public String getComment() {
    return comment;
}

public void setComment(String comment) {
    this.comment = comment;
}

public Integer getStatus() {
    return status;
}

public void setStatus(Integer status) {
    this.status = status;
}

@Override
public String toString() {
    return "PositionTransaction{" +
            "id=" + id +
            ", valueDate=" + valueDate +
            ", balance=" + balance +
            ", comment='" + comment + '\'' +
            ", status=" + status +
            ", positionAccount=" + positionAccount +
            '}';
}

@Override
public int hashCode() {
    return id != null ? id.hashCode() : 0;
}

}

跟踪:

17:55:21.210 [http-nio-8081-exec-1] WARN  o.h.e.jdbc.spi.SqlExceptionHelper -  [] SQL Error: 210, SQLState: S0001
17:55:21.210 [http-nio-8081-exec-1] ERROR o.h.e.jdbc.spi.SqlExceptionHelper -  [] Conversion failed when converting datetime from binary/varbinary string.
17:55:21.215 [http-nio-8081-exec-1] ERROR r.c.i.a.a.a.PositionEndpoint -  [] X: 
org.springframework.dao.InvalidDataAccessResourceUsageException: could not execute statement; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not execute statement
    at org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException(HibernateJpaDialect.java:238) ~[spring-orm-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:221) ~[spring-orm-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:417) ~[spring-orm-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:59) ~[spring-tx-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:213) ~[spring-tx-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:147) ~[spring-tx-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:653) ~[spring-aop-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at 

在您发表评论后,我修改了代码,但这是另一个异常:

18:41:01.389 [JavaFX Application Thread] ERROR io.datafx.core.ExceptionHandler -  [] DataFX Exception Handler
io.datafx.controller.flow.FlowException: java.lang.reflect.InvocationTargetException
    at io.datafx.controller.flow.action.FlowMethodAction.handle(FlowMethodAction.java:53) ~[flow-8.0.jar:na]
    at io.datafx.controller.flow.FlowHandler.handle(FlowHandler.java:231) [flow-8.0.jar:na]
    at io.datafx.controller.flow.FlowHandler.handle(FlowHandler.java:163) [flow-8.0.jar:na]
    at io.datafx.controller.flow.FlowHandler.handleActionWithExceptionHandler(FlowHandler.java:338) [flow-8.0.jar:na]
    at io.datafx.controller.flow.FlowHandler.lambda$attachEventHandler$8(FlowHandler.java:304) [flow-8.0.jar:na]
    at io.datafx.controller.flow.FlowHandler$$Lambda$88/186245904.handle(Unknown Source) [flow-8.0.jar:na]
    at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86) [jfxrt.jar:na]
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238) [jfxrt.jar:na]
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191) [jfxrt.jar:na]
    at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59) [jfxrt.jar:na]
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58) [jfxrt.jar:na]
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) [jfxrt.jar:na]
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) [jfxrt.jar:na]
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) [jfxrt.jar:na]
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) [jfxrt.jar:na]
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) [jfxrt.jar:na]
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) [jfxrt.jar:na]
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) [jfxrt.jar:na]
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) [jfxrt.jar:na]
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) [jfxrt.jar:na]
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) [jfxrt.jar:na]
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) [jfxrt.jar:na]
    at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74) [jfxrt.jar:na]
    at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49) [jfxrt.jar:na]
    at javafx.event.Event.fireEvent(Event.java:198) [jfxrt.jar:na]
    at javafx.scene.Node.fireEvent(Node.java:8390) [jfxrt.jar:na]
    at javafx.scene.control.Button.fire(Button.java:185) [jfxrt.jar:na]
    at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:182) [jfxrt.jar:na]
    at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:96) [jfxrt.jar:na]
    at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:89) [jfxrt.jar:na]
    at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218) [jfxrt.jar:na]
    at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80) [jfxrt.jar:na]
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238) [jfxrt.jar:na]
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191) [jfxrt.jar:na]
    at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59) [jfxrt.jar:na]
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58) [jfxrt.jar:na]
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) [jfxrt.jar:na]
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) [jfxrt.jar:na]
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) [jfxrt.jar:na]
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) [jfxrt.jar:na]
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) [jfxrt.jar:na]
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) [jfxrt.jar:na]
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) [jfxrt.jar:na]
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) [jfxrt.jar:na]
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) [jfxrt.jar:na]
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) [jfxrt.jar:na]
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) [jfxrt.jar:na]
    at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74) [jfxrt.jar:na]
    at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54) [jfxrt.jar:na]
    at javafx.event.Event.fireEvent(Event.java:198) [jfxrt.jar:na]
    at javafx.scene.Scene$MouseHandler.process(Scene.java:3758) [jfxrt.jar:na]
    at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3486) [jfxrt.jar:na]
    at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762) [jfxrt.jar:na]
    at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2495) [jfxrt.jar:na]
    at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:350) [jfxrt.jar:na]
    at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:275) [jfxrt.jar:na]
    at java.security.AccessController.doPrivileged(Native Method) [na:1.8.0_45]
    at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$350(GlassViewEventHandler.java:385) [jfxrt.jar:na]
    at com.sun.javafx.tk.quantum.GlassViewEventHandler$$Lambda$364/84707264.get(Unknown Source) [jfxrt.jar:na]
    at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:404) [jfxrt.jar:na]
    at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:384) [jfxrt.jar:na]
    at com.sun.glass.ui.View.handleMouseEvent(View.java:555) [jfxrt.jar:na]
    at com.sun.glass.ui.View.notifyMouse(View.java:927) [jfxrt.jar:na]
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method) [jfxrt.jar:na]
    at com.sun.glass.ui.win.WinApplication.lambda$null$145(WinApplication.java:101) [jfxrt.jar:na]
    at com.sun.glass.ui.win.WinApplication$$Lambda$36/1596000437.run(Unknown Source) [jfxrt.jar:na]
    at java.lang.Thread.run(Thread.java:745) [na:1.8.0_45]
Caused by: java.lang.reflect.InvocationTargetException: null
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_45]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_45]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_45]
    at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_45]
    at io.datafx.controller.flow.action.FlowMethodAction.handle(FlowMethodAction.java:51) ~[flow-8.0.jar:na]
    ... 66 common frames omitted
Caused by: java.lang.reflect.InvocationTargetException: null
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_45]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_45]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_45]
    at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_45]
    at io.datafx.controller.injection.InjectionHandler$1.invoke(InjectionHandler.java:87) ~[injection-8.0.jar:na]
    at ru.com.isbank.adc.adc_front_office_app.loro_nostro.LoroNostroModel_$$_jvstd5e_6.getAddDate(LoroNostroModel_$$_jvstd5e_6.java) ~[classes/:na]
    at ru.com.isbank.adc.adc_front_office_app.loro_nostro.LoroNostroTrController.addTransaction(LoroNostroTrController.java:151) ~[classes/:na]
    ... 71 common frames omitted
Caused by: java.lang.NullPointerException: null
    at ru.com.isbank.adc.adc_front_office_app.loro_nostro.LoroNostroModel.getAddDate(LoroNostroModel.java:195) ~[classes/:na]
    ... 78 common frames omitted

有什么不对?有任何想法吗?感谢

1 个答案:

答案 0 :(得分:0)

首先,回答你上面的评论是的,你应该更改LocalDate,因为jdbc目前不支持(有人告诉我,如果我错了)。使用java.sql.Date代替它是最简单,更快速的溶剂

另一种解决方法是:

如堆栈跟踪所述,问题出在LocalDate中,如果需要使用此类型,我会将其作为对象内的属性而不是持久化。并且还有一个具有java.sql.Date的日期和类型值的属性。给你一个例子我会得到如下(它可能不完全编译,因为我现在不在我的电脑里):

  @Column(name = "VALUE_DATE")
      private  java.sql.Date persistendDate;

      private LocalDate valueDate;

      public void setValueDate(LocalDate valueDate) {
            this.valueDate = valueDate;
            this.persistendDate = java.sql.Date.valueOf(valueDate);
        }