当我试图登录时,我遇到了这个问题:
WARN : org.hibernate.engine.jdbc.spi.SqlExceptionHelper - SQL Error: 1064, SQLState: 42000
ERROR: org.hibernate.engine.jdbc.spi.SqlExceptionHelper - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'order orders0_ where orders0_.user_id=10' at line 1
ERROR: org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter - An internal error occurred while trying to authenticate the user.
org.springframework.security.authentication.InternalAuthenticationServiceException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'order orders0_ where orders0_.user_id=10' at line 1
以下是实体用户和订单:
@Entity
@Table(name = "user")
public class User {
private int id;
private String firstname;
private String lastname;
private String email;
private String telephone;
private String sex;
private String password;
private String confirmPassword;
private String login;
private Set<Role> roles = new HashSet<Role>(0);
private Set<Product> products = new HashSet<Product>(0);
private Set<Order> orders = new HashSet<Order>(0);
public User(){}
...
@OneToMany(mappedBy = "user", fetch = FetchType.EAGER, cascade = CascadeType.ALL)
public Set<Order> getOrders() {
return orders;
}
public void setOrders(Set<Order> orders) {
if(orders!=null){
this.orders = orders;
}
}
}
@Entity
@Table(name="order")
public class Order {
private int id;
private OrderStatus status;
private DeliveryType deliveryType;
private Date date;
private PaymentType paymentType;
private String receiver;
private String phone;
private String email;
private BigDecimal deliveryPrice;
private String address;
private String cardNumber;
private String cardTermOf;
private int cardThreeNumbers;
public Order(){}
private User user;
private Set<ProductsInOrder> productsInOrders = new HashSet<ProductsInOrder>();
...
@ManyToOne
@JoinColumn(name = "user_id")
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
}
当我在方法getOrderds()的用户实体中更改fetchtype.eager
上的fetchtype.lazy
时,我可以成功登录,但是当我试图获取订单时,我得到了一个错误:
未能懒惰地初始化角色集合:“Ua.sombra.webstore.domain.user.Orders,无法初始化代理-没有会话”
我不能解决这个问题。我需要做什么?
您的问题是order
是SQL中的保留字,您不能将其用作表的名称。将其重命名为orders
或SMTH。
首先,我想道歉,因为我的英语不好。我正在学习Spring框架,我正在使用Spring Boot、Spring Data、Spring MVC制作一个简单的应用程序。
我得到了一个错误。您的SQL语法中有一个错误;请查看与您的MySQL服务器版本相对应的手册,以便在第1行'order(id)'附近使用正确的语法,但不确定原因。有人能帮忙吗?下面是实体。订单可以有很多产品。产品可以与许多订单相关联,餐馆与产品有一对一的关系
该项目使用MS SQL,但我想切换到MySQL,而我有一个查询问题: ...引发异常[请求处理失败;嵌套异常为org.hibernate.exception.sqlgrammarexception:无法提取ResultSet],根本原因为com.mysql.jdbc.exceptions.jdbc4.mysqlsyntaxerrorexception: 您的SQL语法有错误;查看与您的MySQL
我正在phpMyAdmin中的存储过程下面运行: Mariadb/MySQL创建过程中的神秘错误 但这些答案都无济于事!
我在MySQL5.7.19版本中尝试执行查询视图时遇到了一个错误