org.hibernate.exception.SQLGrammarException

时间:2018-07-05 08:35:21

标签: java postgresql spring-mvc

我刚开始使用Spring MVC。我想玩CRUD操作。我正在使用PostgreSQL。

当我尝试在数据库中添加用户(对象)时,它会显示

  

“无法提取ResultSet; SQL [n / a];嵌套异常为   org.hibernate.exception.SQLGrammarException:无法提取   ResultSet”。

以下是我的代码的图片(供参考)

User.java

package com.example.postgresdemo.model;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.xml.soap.Text;

@Entity
@Table(name = "All Emplyess")
public class User {
    @Id
    //@Column(name = "Id", unique = true, nullable = false)
    private Long id;

    //@Column(name = "Names", nullable = false, columnDefinition = "text")
    @Column(columnDefinition = "text")
    private String name;

    public User(){}

    public User(Long id, String name){
        this.id = id;
        this.name = name;
    }

    public Long getId() {
        return id;
    }

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

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

我的存储库

package com.example.postgresdemo.repository;

import com.example.postgresdemo.model.User;
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.stereotype.Repository;
import java.util.Optional;

@Repository
public interface UserRepo extends JpaRepository<User, Long>{

}

我的控制器

package com.example.postgresdemo.controller;

import com.example.postgresdemo.model.User;
import com.example.postgresdemo.repository.UserRepo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping("/api")
public class ControllerUser {

    @Autowired
    private UserRepo userRepo;

    @RequestMapping(value = "/testing", method = RequestMethod.POST, produces = "application/json")
    public User getTested(@RequestBody User u){
        return u;
    }

    //@RequestMapping(value = "/addUser", method = RequestMethod.POST, produces = "application/json")
    @PostMapping("/addUser")
    public User addUser(@Valid @RequestBody User u){
        return userRepo.save(u);
    }
}

我遇到的错误

  

“ message”:“无法提取ResultSet; SQL [n / a];嵌套异常   是org.hibernate.exception.SQLGrammarException:无法提取   ResultSet”

0 个答案:

没有答案