简体   繁体   English

org.springframework.web.util.NestedServletException:嵌套的异常是org.hibernate.exception.SQLGrammarException:无法执行语句

[英]org.springframework.web.util.NestedServletException: nested exception is org.hibernate.exception.SQLGrammarException: could not execute statement

Here are two entities, one is Customer and the other is Order, and one customer can obtain multiple Order, finally i return a Customer object in the controller using springmvc, but it always gave me sqlgrammer error, does jackson-bind can deal one-to-many problem? 这是两个实体,一个是Customer,另一个是Order,一个客户可以获取多个Order,最后我使用springmvc在控制器中返回一个Customer对象,但是它总是给我sqlgrammer错误,jackson-bind可以处理一个-多对多的问题? here is the code snippet in the controller: 这是控制器中的代码片段:

@RequestMapping(value = "/getCustomer", method = RequestMethod.GET)
public @ResponseBody Customer getCustomer(){

    Customer customer = new Customer();
    customer.setRecord("Crabime");
    customer.setGender("male");
    Order order = new Order("vegitable", 12.1);
    Order order1 = new Order("fruit", 3.2);
    Set<Order> set = new HashSet<Order>();
    set.add(order);
    set.add(order1);
    customer.setOrders(set);

    customerService.save(customer);
    return customer;
}

and error trace 错误跟踪

org.springframework.web.util.NestedServletException: Request processing failed; org.springframework.web.util.NestedServletException:请求处理失败; nested exception is org.hibernate.exception.SQLGrammarException: could not execute statement 嵌套的异常是org.hibernate.exception.SQLGrammarException:无法执行语句

Customer Entity 客户实体

     @Entity
    @Table(name = "customer")
    public class Customer {
        @Id
        @GeneratedValue(strategy = GenerationType.IDENTITY)
        private Integer id;
        private String record;
        private String gender;
        @OneToMany(fetch = FetchType.EAGER,cascade = {CascadeType.ALL}, mappedBy = "customer")
        private Set<Order> orders;
        public Customer(){}
...omit setter and getter...

here is the Order : 这是命令:

 @Entity
@Table(name = "order")
public class Order {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;
    private String name;
    private double price;
    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "customer_id")
    private Customer customer;

    public Order() {
    }

    public Order(String name, double price) {
        this.name = name;
        this.price = price;
    }
...omit setter and getter...

**UPDATE:**maybe it's tomcat cache problem, i remember having restarted server at that time and without anything changed, but after closing the project for few hours and reopen it, ok! **更新:**也许是tomcat缓存问题,我记得当时已经重新启动了服务器,没有做任何更改,但是在关闭项目几个小时并重新打开它之后,确定!

For this error, the suggest way is add spring.jpa.show-sql=true to print the sql statement, then you can check the sql. 对于此错误,建议的方法是添加spring.jpa.show-sql=true以打印sql语句,然后可以检查sql。 Typical it contains the keywords, eg "order" 典型地,它包含关键字,例如“ order”

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 嵌套的异常是org.hibernate.exception.SQLGrammarException:无法执行查询 - nested exception is org.hibernate.exception.SQLGrammarException: could not execute query org.hibernate.exception.SQLGrammarException:无法执行语句 - org.hibernate.exception.SQLGrammarException: could not execute statement org.hibernate.exception.SQLGrammarException:无法执行语句 - org.hibernate.exception.SQLGrammarException: could not execute statement org.springframework.web.util.NestedServletException:处理程序调度失败; 嵌套异常是 java.lang.StackOverflowError - org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exception is java.lang.StackOverflowError 如何解决“无法执行语句;SQL [n/a];嵌套异常是 org.hibernate.exception.SQLGrammarException:无法执行语句”? - How to resolve "could not execute statement; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not execute statement"? org.hibernate.exception.SQLGrammarException:无法执行 JDBC 批量更新 - org.hibernate.exception.SQLGrammarException:Could not execute JDBC batch update org.hibernate.exception.SQLGrammarException:无法再次执行查询 - org.hibernate.exception.SQLGrammarException: could not execute query again 如何解决 org.hibernate.exception.SQLGrammarException: 无法执行查询 - How to solve org.hibernate.exception.SQLGrammarException: could not execute query RuntimeException:org.hibernate.exception.SQLGrammarException:无法执行查询 - RuntimeException: org.hibernate.exception.SQLGrammarException: could not execute query org.hibernate.exception.SQLGrammarException:无法执行查询 - org.hibernate.exception.SQLGrammarException: could not execute query
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM