title: Hibernate One-To-Many
body: <p>Have a problem with hibernate. I have Entity User</p>
  
  <pre><code>@Entity
  @Table(name = "user")
  
  public class User {
  @Id
  @Column(name = "user_id")
  @GeneratedValue
  private Long userId;
  
  @Column
  @NotBlank(message = "Fill login")
  private String login;
  
  @OneToMany(fetch=FetchType.LAZY,mappedBy="user")
  private List&lt;Order&gt; orders;
  
  public List&lt;Order&gt; getOrders() {
      return orders;
  }
  public void addOrders(Order order) {
      this.orders.add(order);
  }
  </code></pre>
  
  <p>Also like u can see user have orders. So in ORDER table i have FK that point to USER_ID so here it is my entity Order</p>
  
  <pre><code>@Entity
  @Table(name = "order")
  public class Order {
  
      @Id
      @Column(name="order_id")
      @GeneratedValue
      private long orderId;   
      @Column 
      private long user_id;
      @Column
      private Date dateBegin;
      private Date dateEnd;
  
  }
  </code></pre>
  
  <p>and here my Unit Test</p>
  
  <pre><code>public class HibernateTutorial extends BaseTest{
  
      @Autowired
      SessionFactory sessionFactory;
      @Test
      public void hibernateTutorial(){        
          System.out.print(sessionFactory);       
  
          List&lt;User&gt; users =  sessionFactory.getCurrentSession().createQuery("from User").list();
          List&lt;Order&gt; orders = users.get(0).getOrders(); 
  
          System.out.print(orders);   
          Assert.assertNotNull(users);    
  
      }
  
  }
  </code></pre>
  
  <p>I have Exception when i run it:</p>
  
  <pre><code>Caused by: org.hibernate.AnnotationException: mappedBy reference an unknown target entity property  entity.Order.user in entity.User.orders
  at org.hibernate.cfg.annotations.CollectionBinder.bindStarToManySecondPass(CollectionBinder.java:576)
  at org.hibernate.cfg.annotations.CollectionBinder$1.secondPass(CollectionBinder.java:541)
  at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:66)
  at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1177)
  at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:324)
  at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1162)
  at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:717)
  at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211)
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477)
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)
  ... 38 more
  </code></pre>
  
  <p>What i do wrong?    </p>