Java org.hibernate.exception.sqlgrammareexception
我刚刚开始使用SpringMVC。我想玩CRUD操作。我正在使用PostgreSQL 当我试图在数据库中添加用户(对象)时,它会显示 无法提取结果集;SQL[n/a];嵌套异常为 org.hibernate.exception.sqlgrammareexception:无法提取 结果集” 以下是我的代码图像(供参考) User.javaJava org.hibernate.exception.sqlgrammareexception,java,postgresql,spring-mvc,Java,Postgresql,Spring Mvc,我刚刚开始使用SpringMVC。我想玩CRUD操作。我正在使用PostgreSQL 当我试图在数据库中添加用户(对象)时,它会显示 无法提取结果集;SQL[n/a];嵌套异常为 org.hibernate.exception.sqlgrammareexception:无法提取 结果集” 以下是我的代码图像(供参考) User.java package com.example.postgresdemo.model; import javax.persistence.Column; import
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>{
}
我得到的错误
“消息”:“无法提取结果集;SQL[n/a];嵌套异常
是org.hibernate.exception.sqlgrammareexception:无法提取
结果集“
请编辑您的问题。将您得到的错误主体和代码粘贴为问题本身中的文本,而不是图像。已编辑。谢谢。请发布错误的完整堆栈跟踪。同时发布一个示例请求负载。
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);
}
}