如何使表只读?

时间:2022-06-01 13:02:30

I have two tables in db with bi-directional many-to-one association. The problem is that I want write datas only in one table. Second must be read only. I searched but didn't find any solutions. I use spring data, jpa, eclipselink, mysql. Maybe someone knows how to solve this issue? Thanks

我在db中有两个表,具有双向多对一关联。问题是我只想在一个表中写入数据。第二个必须是只读的。我搜索但没有找到任何解决方案。我使用spring数据,jpa,eclipselink,mysql。也许有人知道如何解决这个问题?谢谢

2 个解决方案

#1


0  

To limit permissions on a table you need to use REVOKE:

要限制表的权限,您需要使用REVOKE:

The REVOKE statement enables system administrators to revoke privileges from MySQL accounts. Each account name uses the format described in Section 6.2.3, “Specifying Account Names”.

REVOKE语句使系统管理员可以撤消MySQL帐户的权限。每个帐户名称使用第6.2.3节“指定帐户名称”中所述的格式。

#2


0  

Thanks for help. I solved it programmatically. In my entity class for read-only table I inserted @ReadOnly annotation and :

感谢帮助。我以编程方式解决了它。在我的只读表实体类中,我插入了@ReadOnly注释,并且:

@OneToMany(targetEntity=Catalog.class, mappedBy="category", cascade={CascadeType.ALL},   fetch = FetchType.EAGER)
private List<Catalog> catalog;

and in target entity:

在目标实体中:

@ManyToOne()
@JoinColumn(name="cname", referencedColumnName="name")
private Category category;

#1


0  

To limit permissions on a table you need to use REVOKE:

要限制表的权限,您需要使用REVOKE:

The REVOKE statement enables system administrators to revoke privileges from MySQL accounts. Each account name uses the format described in Section 6.2.3, “Specifying Account Names”.

REVOKE语句使系统管理员可以撤消MySQL帐户的权限。每个帐户名称使用第6.2.3节“指定帐户名称”中所述的格式。

#2


0  

Thanks for help. I solved it programmatically. In my entity class for read-only table I inserted @ReadOnly annotation and :

感谢帮助。我以编程方式解决了它。在我的只读表实体类中,我插入了@ReadOnly注释,并且:

@OneToMany(targetEntity=Catalog.class, mappedBy="category", cascade={CascadeType.ALL},   fetch = FetchType.EAGER)
private List<Catalog> catalog;

and in target entity:

在目标实体中:

@ManyToOne()
@JoinColumn(name="cname", referencedColumnName="name")
private Category category;