我是使用Maven和JBOSS处理JPA的初学者,通过Restful使我的应用程序出现以下问题,我在进行DEPLOY
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代码。
我有三个表( 活动 , 事件 和 照片 ),其中一个表( 照片 )引用了另外两个表( 活动 和 事件 ),但是在一个列中( 照片.fid_module )
SQL代码(工程师数据库-> 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 clean install和 mvn jboss-as:部署 几个使我进入hibernate依赖关系)有人可以告诉我我的错误是什么,或者可以解决此问题。谢谢。
如另一个答案所述,您的Java代码为两个字段指定了相同的联接列名称,这是行不通的。
如果此Java代码是由netbeans映射工具生成的,如您的注释所示
现在,我在Netbenas的帮助下进行了映射,并给了我以下代码…
错误的Java映射可能是由于SQL中约束的错误组合引起的。
您在photo表的定义中有:
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
试图使列fid_module成为外键引用activity以及外键引用event,这是行不通的。
fid_module
activity
event
如果您需要photo这两个表的外键,则需要使用两个不同的列。