title: Hibernate Bidirectional relationships
body: <p>How is the correct way to establish bidirectional relation @OneToMany in hibernate?</p>
  
  <p>I have 3 tables useraccount, category, and item. In my item table, it holds foreign keys for useraccount and category. If I establish unidirection, it compiles with the code like this in item class:</p>
  
  <pre><code>@ManyToOne
  @JoinColumn(name="cat_id")
  public Category getCategory() { return category;    }
  public void setCategory(Category category) {this.category = category; }
  private Category category;
  
  @ManyToOne
  @JoinColumn(name="user_id")
  public UserAccount getItemOwner() { return itemOwner;   }
  public void setItemOwner(UserAccount itemOwner) {   this.itemOwner = itemOwner; }
  private UserAccount itemOwner;
  </code></pre>
  
  <p>But when I try to define bidirection by adding those mapping in useraccount and category:</p>
  
  <pre><code>@OneToMany(mappedBy="USERACCOUNTS", targetEntity=Item.class, cascade=CascadeType.ALL)
  public Set&lt;Item&gt; getOwnedItems() {  return ownedItems;  }
  public void setOwnedItems(Set&lt;Item&gt; ownedItems) {   this.ownedItems = ownedItems;   }
  private Set&lt;Item&gt; ownedItems;
  
  @OneToMany(mappedBy="CATEGORIES", targetEntity=Item.class, cascade=CascadeType.ALL)
  public Set&lt;Item&gt; getListOfItem() {  return listOfItem;  }
  public void setListOfItem(Set&lt;Item&gt; listOfItem) {   this.listOfItem = listOfItem;   }
  private Set&lt;Item&gt;listOfItem; 
  </code></pre>
  
  <p>it gives me this error:</p>
  
  <pre><code>SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
  org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/spring-servlet.xml]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: com.isad.model.Item.CATEGORIES in com.isad.model.Category.listOfItem
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1553)
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
  at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)
  at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
  at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)
  at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
  at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:684)
  at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)
  at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
  at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)
  at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
  at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
  at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4973)
  at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5467)
  at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
  at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
  at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
  at java.util.concurrent.FutureTask.run(FutureTask.java:262)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
  at java.lang.Thread.run(Thread.java:744)
  Caused by: org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: com.isad.model.Item.CATEGORIES in com.isad.model.Category.listOfItem
  at org.hibernate.cfg.annotations.CollectionBinder.bindStarToManySecondPass(CollectionBinder.java:768)
  at org.hibernate.cfg.annotations.CollectionBinder$1.secondPass(CollectionBinder.java:728)
  at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:70)
  at org.hibernate.cfg.Configuration.originalSecondPassCompile(Configuration.java:1695)
  at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1424)
  at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1844)
  at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1928)
  at org.springframework.orm.hibernate4.LocalSessionFactoryBuilder.buildSessionFactory(LocalSessionFactoryBuilder.java:343)
  at org.springframework.orm.hibernate4.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:431)
  at org.springframework.orm.hibernate4.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:416)
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1612)
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1549)
  ... 21 more
  </code></pre>
  
  <p>I looked at the document but couldnt find out where caused the problem. Can any one give me suggestion to fix this problem. thanks</p>