Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
303 views
in Technique[技术] by (71.8m points)

java - I'm getting a mappedBy reference an unknown target entity property and I'm just not seeing the error

I am getting a mappedBy reference an unknown target entity property in my code but I just done see where the problem is. Ive looked it over so many times i'm certain its starring me in the face but I just done see it.

My error is

mappedBy reference an unknown target entity property: com.jms.helloworld.domain.EventType.eventmasters in com.jms.helloworld.domain.EventMasters.eventType

    package com.jms.helloworld.domain;

    import static javax.persistence.GenerationType.IDENTITY;

    import java.io.Serializable;
    import java.util.HashSet;
    import java.util.Set;

    import javax.persistence.CascadeType;
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.GeneratedValue;
    import javax.persistence.Id;
    import javax.persistence.JoinColumn;
    import javax.persistence.ManyToOne;
    import javax.persistence.NamedQueries;
    import javax.persistence.NamedQuery;
    import javax.persistence.OneToMany;
    import javax.persistence.Table;


    @Entity
    @Table(name = "EVENTTYPES")
    @NamedQueries({
@NamedQuery(name="EventType.findAllWithDetail", 
            query="select distinct e from EventType e left join fetch e.events n ")
    })
    public class EventType implements Serializable {
private int id;
private String name;
private EventMasters eventmasters;
private Set<Events> events = new HashSet<Events>();

@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "ID")
public int getId() {
    return id;
}
public void setId(int id) {
    this.id = id;
}
public String getName() {
    return name;
}
public void setName(String name) {
    this.name = name;
}

@OneToMany(mappedBy = "eventtype", cascade=CascadeType.ALL, orphanRemoval=true)
public Set<Events> getEvents() {
    return events;
}
public void setEvents(Set<Events> events) {
    this.events = events;
}

@ManyToOne
@JoinColumn(name = "EVENTMASTER_ID")
public EventMasters getEventMasters() {
    return eventmasters;
}
public void setEventMasters(EventMasters eventmasters) {
    this.eventmasters = eventmasters;
}


    }

and

   package com.jms.helloworld.domain;

   import static javax.persistence.GenerationType.IDENTITY;

   import java.io.Serializable;
   import java.util.HashSet;
   import java.util.List;
   import java.util.Set;

   import javax.persistence.CascadeType;
   import javax.persistence.Column;
   import javax.persistence.Entity;
   import javax.persistence.GeneratedValue;
   import javax.persistence.Id;
   import javax.persistence.JoinColumn;
   import javax.persistence.ManyToOne;
   import javax.persistence.NamedQueries;
   import javax.persistence.NamedQuery;
   import javax.persistence.OneToMany;
   import javax.persistence.OneToOne;
   import javax.persistence.Table;

   @Entity
   @Table(name="EVENTMASTERS")
    /*
    @NamedQueries({
@NamedQuery(name="Menus.findAllWithID", 
            query="select distinct c from Menus c left join fetch c.category t left join fetch    t.items h" +
                    " where c.site_id = :id")
    })
    */
    public class EventMasters implements Serializable {

/**
 * 
 */
private static final long serialVersionUID = 1L;
private int id;
private String name;
private Sites sites; 
private Set<EventType> eventtype = new HashSet<EventType>();

@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "ID")
public int getId() {
    return id;
}
public void setId(int id) {
    this.id = id;
}
public String getName() {
    return name;
}
public void setName(String name) {
    this.name = name;
}

@OneToOne
@JoinColumn(name = "SITE_ID")
public Sites getSites() {
    return sites;
}
public void setSites(Sites sites) {
    this.sites = sites;
}

@OneToMany(mappedBy = "eventmasters", cascade=CascadeType.ALL, orphanRemoval=true)
public Set<EventType> getEventType() {
    return eventtype;
}
public void setEventType(Set<EventType> eventtype) {
    this.eventtype = eventtype;
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Fix your property camel-case naming.

If your getter is getEventType() then mappedBy attribute should be eventType (similar problem is in eventmasters => eventMasters).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...