由以下原因引起:org.hibernate.MappingException:实体映射中的重复列
2022-09-03 06:08:08
我是使用maven和JBOSS处理JPA的初学者,使用Restful使我的应用程序我有以下问题出现,我在做DEVAL
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: com.company.test_resources_war_1.0-SNAPSHOTPU] Unable to build EntityManagerFactory
Caused by: org.hibernate.MappingException: Repeated column in mapping for entity: database.Photo column: fid_module (should be mapped with insert = \ "false \" update = \ "false \") "}}
不是那一步,检查所有posles解决方案,但没有找到任何东西,有人可以帮助我吗?
提前致谢
下面我在postgres中显示了我拥有的SQL代码,并进行了映射。
我有三个表格(活动,事件和照片),其中一个(照片)指的是另外两个(活动和事件),但在一列中(photo.fid_module)
SQL Code (enginer database-->Postgresql):
CREATE TABLE activity (
id_activity integer not null,
name character varying(150),
description text,
CONSTRAINT id_activity_pk PRIMARY KEY (id_activity)
)
CREATE TABLE event (
id_event integer not null,
name character varying(150),
description text,
date timestamp without time zone,
CONSTRAINT id_event_pk PRIMARY KEY (id_event)
)
CREATE TABLE photo(
id_photo integer not null,
path character varying(150),
fid_module integer not null,
CONSTRAINT id_photo_pk PRIMARY KEY (id_photo),
CONSTRAINT fk_photo_activity FOREIGN KEY (fid_module)
REFERENCE activity (id_activity) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT fk_photo_event FOREIGN KEY (fid_module)
REFERENCE event (id_event) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
)
现在,我在Netbenas的帮助下进行了映射,并给了我以下代码(我为三个表进行了映射,但是在向我展示时,问题出在Photo.java类中)。
@Entity
@Table(name = "photo")
@XmlRootElement
@NamedQueries({
@NamedQuery(name = "photo.findAll", query = "SELECT p FROM Photo p"),
@NamedQuery(name = "photo.findByFidPhoto", query = "SELECT p FROM Photo p WHERE p.fidphoto = :fidphoto"),
@NamedQuery(name = "photo.findByIdPhoto", query = "SELECT p FROM Photo p WHERE p.idphoto = :idphoto")})
public class Photo implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "id_photo")
private Integer idPhoto;
@Column(name = "path")
private Recurso fidPath;
@JoinColumn(name = "fid_module", referencedColumnName = "id_activity")
@ManyToOne(optional = false, fetch = FetchType.LAZY)
private SliderWebHome fidModule;
@JoinColumn(name = "fid_module", referencedColumnName = "id_event")
@ManyToOne(optional = false, fetch = FetchType.LAZY)
private Publicacion fidModule1;
public ModuloRecurso() {
}
.......
}
我正在使用JPA进行持久性(但是做mvn干净安装和mvn jboss-as:部署几个拉我休眠依赖关系),任何人都可以告诉我我的错误是什么或者可以解决这个问题。谢谢。