org.hibernate.exception.SQLGrammarException:无法准备语句

时间:2016-06-14 12:14:00

标签: hibernate jpa camunda

使用persistOrder()方法将数据放入数据库时​​,会发生异常“org.hibernate.exception.SQLGrammarException:无法准备语句”。这是怎么造成的,我该如何解决?

org.camunda.bpm.engine.ProcessEngineException: Error while evaluating expression: ${orderBusinessLogic.persistOrder(execution)}. 
Cause: javax.ejb.EJBTransactionRolledbackException: org.hibernate.exception.SQLGrammarException: could not prepare statement
    javax.faces.webapp.FacesServlet.service(FacesServlet.java:671)
    io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)
    io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
    io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
    org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
    io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
    io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
    io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
    io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
    io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)
    io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)
    io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)
    io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
    io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
    io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:284)
    io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:263)
    io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)
    io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:174)
    io.undertow.server.Connectors.executeRootHandler(Connectors.java:202)
    io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:793)
    java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    java.lang.Thread.run(Thread.java:745)

OrderBusinessLogic.java

package org.camunda.bpm.getstarted.construct;

import org.camunda.bpm.engine.cdi.jsf.TaskForm;
import org.camunda.bpm.engine.delegate.DelegateExecution;

import javax.ejb.Stateless;
import javax.inject.Named;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.inject.Inject;


import java.io.IOException;
import java.util.Map;

@Stateless
@Named

public class OrderBusinessLogic {



    @PersistenceContext
    private EntityManager entityManager;

    @Inject
    private TaskForm taskForm;

    public void persistOrder(DelegateExecution delegateExecution)
    {
       OrderEntity orderEntity=new OrderEntity();
       Map<String,Object> variables=delegateExecution.getVariables();

       orderEntity.setFromz((String) variables.get("fromz"));
       orderEntity.setToz((String) variables.get("toz"));
       orderEntity.setAlz((String) variables.get("alz"));
       orderEntity.setRowref((String) variables.get("rowref"));
       orderEntity.setOffset((String) variables.get("offset"));
       orderEntity.setDepth((String) variables.get("depth"));
       orderEntity.setStrata((String) variables.get("strata"));
       orderEntity.setHeight((String) variables.get("height"));
       orderEntity.setRamming((String) variables.get("ramming"));
       orderEntity.setBend((String) variables.get("bend"));
       orderEntity.setSlatitude((String) variables.get("slatitude"));
       orderEntity.setSlongitude((String) variables.get("slongitude"));
       orderEntity.setTop1((String) variables.get("top1"));
       orderEntity.setP1latitude((String) variables.get("p1latitude"));
       orderEntity.setP1longitude((String) variables.get("p1longitude"));
       orderEntity.setTop2((String) variables.get("top2"));
       orderEntity.setP2latitude((String) variables.get("p2latitude"));
       orderEntity.setP2longitude((String) variables.get("p2longitude"));
       orderEntity.setTop3((String) variables.get("top3"));
       orderEntity.setP3latitude((String) variables.get("p3latitude"));
       orderEntity.setP3longitude((String) variables.get("p3longitude"));

       entityManager.persist(orderEntity);
       entityManager.flush();

       delegateExecution.removeVariables(variables.keySet());

       delegateExecution.setVariable("orderId", orderEntity.getId());
       }

    public OrderEntity getOrder(Long orderID){
        return entityManager.find(OrderEntity.class, orderID);
    }

    public void mergeOrderAndCompleteTask(OrderEntity orderEntity){
        entityManager.merge(orderEntity);
        try{
            taskForm.completeTask();
        } catch(IOException e){
            throw new RuntimeException("cannot complete task",e);
        }
    }

}

OrderEntity.java

package org.camunda.bpm.getstarted.construct;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Version;
import java.io.Serializable;


@Entity
public class OrderEntity implements Serializable {
    private static final long serialVersionUID=1L;

    @Id
    @GeneratedValue

    protected Long id;

    @Version
    protected long version;

    protected String fromz;
    protected String toz;
    protected String alz;
    protected String rowref;
    protected String offset;
    protected String depth;
    protected String strata;
    protected String height;
    protected String ramming;
    protected String bend;
    protected String slaitude;
    protected String slongitude;
    protected String top1;
    protected String p1latitude;
    protected String p1longitude;
    protected String top2;
    protected String p2latitude;
    protected String p2longitude;
    protected String top3;
    protected String p3latitude;
    protected String p3longitude;
    protected boolean approved;

    public Long getId(){
        return id;
    }

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

    public long getVersionn(){
        return version; }

    public void setVersion(long version){
        this.version=version;
    }

    public String getFromz(String fromz)
    {
      return fromz;
    }

    public void setFromz(String fromz)
    {
        this.fromz=fromz;
    }

    public String getToz(String toz)
    {
      return toz;
    }

    public void setToz(String toz)
    {
        this.toz=toz;
    }

    public String getAlz(String alz)
    {
      return alz;
    }

    public void setAlz(String alz)
    {
        this.alz=alz;
    }

    public String getRowref(String rowref)
    {
      return rowref;
    }

    public void setRowref(String rowref)
    {
        this.rowref=rowref;
    }

    public String getOffset(String offset)
    {
      return offset;
    }

    public void setOffset(String offset)
    {
        this.offset=offset;
    }

    public String getDepth(String depth)
    {
      return depth;
    }

    public void setDepth(String depth)
    {
        this.depth=depth;
    }

    public String getStrata(String strata)
    {
      return strata;
    }

    public void setStrata(String strata)
    {
        this.strata=strata;
    }

    public String getHeight(String height)
    {
      return height;
    }

    public void setHeight(String height)
    {
        this.height=height;
    }

    public String getRamming(String ramming)
    {
      return ramming;
    }

    public void setRamming(String ramming)
    {
        this.ramming=ramming;
    }

    public String getBend(String bend)
    {
      return bend;
    }

    public void setBend(String bend)
    {
        this.bend=bend;
    }

    public String getSlatitude(String slatitude)
    {
      return slatitude;
    }

    public void setSlatitude(String slatitude)
    {
        this.slaitude=slatitude;
    }

    public String getSlongitude(String slongitude)
    {
      return slongitude;
    }

    public void setSlongitude(String slongitude)
    {
        this.slongitude=slongitude;
    }

    public String getTop1(String top1)
    {
      return top1;
    }

    public void setTop1(String top1)
    {
        this.top1=top1;
    }

    public String getP1latitude(String p1latitude)
    {
      return p1latitude;
    }

    public void setP1latitude(String p1latitude)
    {
        this.p1latitude=p1latitude;
    }

    public String getP1longitue(String p1ongitude)
    {
      return p1longitude;
    }

    public void setP1longitude(String p1longitude)
    {
        this.p1longitude=p1longitude;
    }

    public String getTop2(String top2)
    {
      return top2;
    }

    public void setTop2(String top2)
    {
        this.top2=top2;
    }

    public String getP2latitude(String p2latitude)
    {
      return p2latitude;
    }

    public void setP2latitude(String p2latitude)
    {
        this.p2latitude=p2latitude;
    }

    public String getP2longitue(String p2longitude)
    {
      return p2longitude;
    }

    public void setP2longitude(String p2longitude)
    {
        this.p2longitude=p2longitude;
    }

    public String getTop3(String top3)
    {
      return top3;
    }

    public void setTop3(String top3)
    {
        this.top3=top3;
    }

    public String getP3latitude(String p3latitude)
    {
      return p3latitude;
    }

    public void setP3latitude(String p3latitude)
    {
        this.p3latitude=p3latitude;
    }

    public String getP3longitue(String p3longitude)
    {
      return p3longitude;
    }

    public void setP3longitude(String p3longitude)
    {
        this.p3longitude=p3longitude;
    }

    public boolean isApproved(){
        return approved;
    }

    public void setApproved(boolean approved){
        this.approved=approved;
    }

}

1 个答案:

答案 0 :(得分:0)

尝试将@GeneratedValue(strategy = GenerationType.IDENTITY)添加到您的id字段,并确保您为您的实体创建了数据库主数据。