title: 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
body: <p>When I trying to log in I have this problem:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>here is entities User and Orders:</p>
  
  <pre><code>@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&lt;Role&gt; roles = new HashSet&lt;Role&gt;(0);
      private Set&lt;Product&gt; products = new HashSet&lt;Product&gt;(0);
      private Set&lt;Order&gt; orders = new HashSet&lt;Order&gt;(0);
  
      public User(){}
  
      ...
  
      @OneToMany(mappedBy = "user", fetch = FetchType.EAGER, cascade = CascadeType.ALL)
      public Set&lt;Order&gt; getOrders() {
          return orders;
      }
  
      public void setOrders(Set&lt;Order&gt; 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&lt;ProductsInOrder&gt; productsInOrders = new HashSet&lt;ProductsInOrder&gt;();
  
      ...
  
      @ManyToOne
      @JoinColumn(name = "user_id")
      public User getUser() {
          return user;
      }
  
      public void setUser(User user) {
          this.user = user;
      }
  
  }
  </code></pre>
  
  <p>When I change <code>FetchType.EAGER</code> on <code>FetchType.LAZY</code> in User Entity on method getOrderds() I can succesfuly log in, but when I trying to get my orders I obtain an error: </p>
  
  <blockquote>
    <p>failed to lazily initialize a collection of role: "ua.sombra.webstore.domain.User.orders, could not initialize proxy - no Session"</p>
  </blockquote>
  
  <p>I can not solve this problem. What i need to do?</p>