例如,我有这个实体:
public class MessageComment implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column
private String creator;
private List<OtherComments> otherComments = new ArrayList<OtherComments>();
}
在这段代码中,notwhing用OneToMany和Column注解,或者没有其他注解。我不确定JPA将如何在数据库中存储此案例。怎样才能帮助我呢?
private List<OtherComments> otherComments = new ArrayList<OtherComments>();
非常感谢!麦子
发布于 2014-03-31 16:53:45
JPA类只是一个用于对象到关系映射的类,一旦类是JPA
,其中的每个成员在默认情况下都是*Java Persistence Architecture *的一部分。
因此,您不能在其中创建一组变量,如果您在JPA中创建变量,则必须指定这样创建的变量不是任何数据库关系的一部分。
您可以使用@Transient
来完成此操作,此注释将用于指示某个字段不会持久保存在数据库中。
发布于 2014-04-01 01:35:14
List<OtherComments> otherComments
是一个集合值字段,数据库模型取决于列表中列的类型:
MESSAGECOMMENT_OTHERCOMMENTS
,其中包含
MESSAGECOMMENT_OTHERCOMMENTS
,其中包含与<代码>D28表
相关的列的
OTHERCOMMENTS
- _join table_ with name defaulted to `MESSAGECOMMENT_OTHERCOMMENTS` containing
- the foreign key columns of `MESSAGECOMMENT` and `OTHERCOMMENTS` tables
我希望它能帮上忙。
https://stackoverflow.com/questions/22757028
复制相似问题