gpt4 book ai didi

java - 我收到一个被映射的未知目标实体属性的引用,但我只是没有看到错误

转载 作者:行者123 更新时间:2023-12-01 13:48:02 25 4
gpt4 key购买 nike

我在代码中得到了一个mappedBy引用未知的目标实体属性,但我刚刚看到问题出在哪里。我已经看过它很多次了,我确信它就在我的脸上,但我刚刚看到它。

我的错误是

mappedBy 引用未知目标实体属性: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;
}


}

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

最佳答案

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

如果你的 getter 是 getEventType() 那么 mappedBy 属性应该是 eventType (类似的问题在 eventmasters => eventMasters)。

关于java - 我收到一个被映射的未知目标实体属性的引用,但我只是没有看到错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20198444/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com