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

发布于 2024-09-15 18:28:59 字数 989 浏览 1 评论 0原文

当我只映射一个表时,我可以使用 JPA 获取值

映射相关表时,我收到错误,

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

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

现在,当我 我有此代码的子表之一,

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

我必须在此代码中进行哪些更改才能使字段只读?

或者是否有更好的解决方法不使这些字段变为只读?

I m able to get values using JPA when i have only mapped one table

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)

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你的心境我的脸 2024-09-22 18:28:59

您有两个使用相同外键字段的多对一关系。这没有道理,它们会是同一个对象吗?

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

您应该有两个不同的外键字段,即 albumImage 和 albumImage1。

You have two ManyToOne relationships using the same foreign key field. 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, i.e. albumImage and albumImage1.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文