简体   繁体   English

在JPA中将实体类行设为只读

[英]make a entity class rows read-only in JPA

I m able to get values using JPA when i have only mapped one table 当我仅映射一个表时,我可以使用JPA获取值

Now when i have gone for mapping related tables i get the error 现在,当我去映射相关表时,我得到了错误

  Only one may be defined as writable, all others must be specified read-only.
  Mapping: org.eclipse.persistence.mappings.OneToOneMapping[userId1]

I m using [EclipseLink-0] (Eclipse Persistence Services - 2.0.1.v20100213-r6600) 我正在使用[EclipseLink-0](Eclipse Persistence Services-2.0.1.v20100213-r6600)

In one of the child tables i have this code 在其中一个子表中,我有此代码

@OneToMany(cascade = CascadeType.ALL, mappedBy = "albumId")
private Collection<Images> imagesCollection;
@JoinColumn(name = "user_id", referencedColumnName = "User_ID")
@ManyToOne(optional = false)
private Roleuser userId;
@JoinColumn(name = "album_image", referencedColumnName = "image_id")
@ManyToOne
private Images albumImage;
@JoinColumn(name = "album_image", referencedColumnName = "image_id")
@ManyToOne
private Images albumImage1;
@JoinColumn(name = "user_id", referencedColumnName = "User_ID")
@ManyToOne(optional = false)
private Roleuser userId1;

What changes i have to do in this code to make the fields read-only? 我必须在此代码中进行哪些更改才能使字段为只读?

or are there any better workaround for not making these fields read only? 还是有一些更好的解决方法可以使这些字段不只读?

You have two ManyToOne relationships using the same foreign key field. 您有两个使用相同外键字段的ManyToOne关系。 This does not make sense, they will be the same object? 这没有道理,它们将是同一个对象吗?

@JoinColumn(name = "album_image", referencedColumnName = "image_id")
@ManyToOne
private Images albumImage;
@JoinColumn(name = "album_image", referencedColumnName = "image_id")
@ManyToOne
private Images albumImage1;

You should have two different foreign key fields, ie albumImage and albumImage1. 您应该有两个不同的外键字段,即AlbumImage和albumImage1。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM