Announcement Announcement Module
Collapse
No announcement yet.
mappedBy reference an unknown target entity property: com.vaanila.domain.User2.User1 Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • mappedBy reference an unknown target entity property: com.vaanila.domain.User2.User1

    Hi All

    I am doing parent child save in spring 3 mvc hibernate 3

    I am getting this error

    org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: com.vaanila.domain.User2.User1 in com.vaanila.domain.User1.user2


    My User1 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 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;

    @Id

    @GeneratedValue

    @Column(name="USER_ID")

    public Long getId() {

    return id;

    }

    public void setId(Long id) {

    this.id = id;

    }



    @Column(name="USER_NAME")

    public String getName() {

    return name;

    }

    public void setName(String name) {

    this.name = name;

    }



    @Column(name="USER_PASSWORD")

    public String getPassword() {

    return password;

    }

    public void setPassword(String password) {

    this.password = password;

    }



    @Column(name="USER_GENDER")

    public String getGender() {

    return gender;

    }

    public void setGender(String gender) {

    this.gender = gender;

    }



    @Column(name="USER_COUNTRY")

    public String getCountry() {

    return country;

    }

    public void setCountry(String country) {

    this.country = country;

    }



    @Column(name="USER_ABOUT_YOU")

    public String getAboutYou() {

    return aboutYou;

    }

    public void setAboutYou(String aboutYou) {

    this.aboutYou = aboutYou;

    }


    //@JoinColumn(name="User_Name")
    public List<User2> getUser2() {
    return user2s;
    }
    /*
    @Transient
    public void saveUser2(User2 user2) {
    this.user2=user2;
    user2.setUser1(this);
    user2s.add(user2);
    }
    */
    public void setUser2(User2 user2){
    this.user2=user2;
    }
    *************************
    and 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;



    @Id
    @GeneratedValue
    @Column(name="USER_ID")
    public Long getId() {
    return id;
    }
    public void setId(Long id) {
    this.id = id;
    }



    @Column(name="USER_NAME")

    public String getName() {

    return name1;

    }
    public void setName(String name1) {

    this.name1 = name1;

    }



    public User1 getUser1() {
    return user1;
    }
    public void setUser1(User1 user1){
    this.user1=user1;
    }
    }


    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.

    Comment

    Working...
    X