我得到一个mappedBy引用一个未知的目标实体属性,我只是没有看到错误

时间:2013-11-25 16:43:55

标签: java spring

我在代码中获取了一个mappedBy引用未知的目标实体属性,但我刚刚看到了问题所在。我看了很多次,我确定它主演我的脸,但我刚看到它。

我的错误是

mappedBy引用一个未知的目标实体属性:com.jms.helloworld.domain.EventMasters.eventType中的com.jms.helloworld.domain.EventType.eventmasters

    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;
}


    }

   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;
}

1 个答案:

答案 0 :(得分:1)

修复您的属性驼峰式命名。

如果您的获取者为getEventType(),那么mappedBy属性应为eventType(类似问题出现在eventmasters =&gt; eventMasters)。