我是 JPA 的新手,我在创建一些实体时遇到了一些困难。
在我正在构建的应用程序中,可以根据数据库中定义的某些区域和子区域对某些实体进行分类。
相关的表格是这四个:
1)分类
+-------------+-----------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+-----------------------+------+-----+---------+----------------+
| ID | int(11) unsigned | NO | PRI | NULL | auto_increment |
| pID | int(11) unsigned | NO | MUL | NULL | |
| reference | varchar(300) | NO | | NULL | |
| link | varchar(255) | YES | | NULL | |
+-------------+-----------------------+------+-----+---------+----------------+
2) cls_area_map
+---------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------+------------------+------+-----+---------+----------------+
| class | int(11) unsigned | NO | MUL | NULL | |
| idarea | int(11) unsigned | NO | MUL | NULL | |
| subarea | int(11) unsigned | YES | MUL | NULL | |
| id | int(11) unsigned | NO | PRI | NULL | auto_increment |
+---------+------------------+------+-----+---------+----------------+
3) 面积
+--------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------+------------------+------+-----+---------+----------------+
| idarea | int(11) unsigned | NO | PRI | NULL | auto_increment |
| label | varchar(255) | NO | UNI | NULL | |
+--------+------------------+------+-----+---------+----------------+
4) 分区
+-------------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+------------------+------+-----+---------+----------------+
| area_idarea | int(11) unsigned | NO | MUL | NULL | |
| label | varchar(255) | NO | UNI | NULL | |
| ID | int(11) unsigned | NO | PRI | NULL | auto_increment |
+-------------+------------------+------+-----+---------+----------------+
在classification
我存储一般分类信息,并在cls_area_map
我尝试将一般信息连接到分类区域(在area
和中定义subarea
)。
当我尝试将分类区域映射信息添加到我Classification
和我的Cls_area_map
实体类时,我遇到了麻烦。
我得到错误:
An incompatible mapping has been encountered between [class Entity.Classification] and [class Entity.Cls_area_map]. This usually occurs when the cardinality of a mapping does not correspond with the cardinality of its backpointer..
我不确定我在基数上做错了什么。这是我Classification
为创建关系而添加的内容:
@OneToMany(mappedBy = "id")
private List<Cls_area_map> cls_area;
并在Cls_area_map
:
@JoinColumn(name = "class",referencedColumnName = "ID")
@ManyToOne(optional=false)
private Classification classy;
任何解释/提示?
(这是什么意思backpointer
?)