在 JPA 中将实体类行设置为只读
当我只映射一个表时,我可以使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您有两个使用相同外键字段的多对一关系。这没有道理,它们会是同一个对象吗?
您应该有两个不同的外键字段,即 albumImage 和 albumImage1。
You have two ManyToOne relationships using the same foreign key field. This does not make sense, they will be the same object?
You should have two different foreign key fields, i.e. albumImage and albumImage1.