Announcement Announcement Module
Collapse
No announcement yet.
org.hibernate.AnnotationException: mappedBy reference an unknown target entity proper Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • org.hibernate.AnnotationException: mappedBy reference an unknown target entity proper

    Hi All
    I did not include all the stack trace in my previous post .
    Its here pl.

    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'mySessionFactory' defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: com.vaanila.domain.User2.User1 in com.vaanila.domain.User1.user2

    User 1

    package com.vaanila.domain;


    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.GeneratedValue;
    import javax.persistence.Id;
    import javax.persistence.Table;
    import javax.persistence.FetchType;
    import java.sql.*;
    import com.vaanila.domain.User2;
    import java.util.*;
    //import org.hibernate.mapping.OneToMany;
    import java.lang.annotation.Annotation;
    import javax.persistence.OneToMany;
    import javax.persistence.CascadeType;
    import javax.persistence.Transient;
    import javax.persistence.JoinColumn;

    @Entity
    @org.hibernate.annotations.NamedNativeQuery(name = "se_user1", query = "call se_user1(?)", callable = true, resultClass = User1.class)
    @Table(name="User1")
    public class User1 implements java.io.Serializable {

    @OneToMany(mappedBy="user1",fetch=FetchType.LAZY, cascade={CascadeType.ALL})

    private Long id;

    private String name;

    private String password;

    private String gender;

    private String country;

    private String aboutYou;

    //private String[] community;

    //private Boolean mailingList;
    private List user2s;

    public User2 user2;
    ..................
    ......................

    ****************
    User2 is


    package com.vaanila.domain;


    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.GeneratedValue;
    import javax.persistence.Id;
    import javax.persistence.Table;
    import java.sql.*;
    import com.vaanila.domain.User1;
    import javax.persistence.ManyToOne;
    import javax.persistence.JoinColumn;

    import javax.persistence.CascadeType;

    @Entity
    @Table(name="User2")
    public class User2 implements java.io.Serializable {

    @ManyToOne(targetEntity = User1.class , cascade={CascadeType.ALL})
    //@JoinColumn(name="User_Name")

    public User1 user1;

    private Long id;

    private String name1;



    //private String[] community;

    //private Boolean mailingList;
    .....................
    ..................

    *****************
    My dispatcher-servlet.xml is


    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://www.springframework.org/schema/p"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

    <bean id="viewResolver" class="org.springframework.web.servlet.view.Intern alResourceViewResolver" prefix="/WEB-INF/jsp/" p:suffix=".jsp" />

    <bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">

    <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
    <property name="url" value="jdbc:oracle:thin:@localhost:1521:XE"/>
    <property name="username" value="system"/>
    <property name="password" value="manager"/>
    </bean>

    <bean id="mySessionFactory" class="org.springframework.orm.hibernate3.annotati on.AnnotationSessionFactoryBean">
    <property name="dataSource" ref="myDataSource" />
    <property name="annotatedClasses">
    <list>
    <value>com.vaanila.domain.User1</value>
    <value>com.vaanila.domain.User2</value>
    </list>
    </property>

    <property name="hibernateProperties">

    <props>


    <prop key="hibernate.dialect">org.hibernate.dialect.Orac le10gDialect</prop>
    <prop key="hibernate.show_sql">true</prop>

    </props>
    </property>
    </bean>

    <bean id="myUserDAO" class="com.vaanila.dao.UserDAOImpl">
    <property name="sessionFactory" ref="mySessionFactory"/>
    </bean>

    <bean name="/user/*.htm" class="com.vaanila.web.UserController" >
    <property name="userDAO" ref="myUserDAO" />
    </bean>

    </beans>


    Pl. tell me what am i doing wrong?

    Thanks & Regards
    Rajesh

  • #2
    Hello Rajesh

    1) use code tags, is more readable for us
    2) Read Hibernate Reference documentation to see how do a correct mapping with annotations. Your problem is not related with Spring.
    3) Do not repeat the same problem in two different posts

    Comment

    Working...
    X