问题描述
当我尝试坚持我的模型时遇到问题。创建EntityManagerFactory时抛出异常:
$ b
I have a problem when I try to persist my model. An exception is thrown when creating the EntityManagerFactory:
这两个实体的代码如下:
The code for the two entities is as follows:
@Entity
public class EntityOne
{
@OneToOne(cascade = CascadeType.ALL, targetEntity = EntityTwo.class)
@JoinColumn(name = "ENTITY_TWO_ID")
private EntityTwo entityTwo;
...
}
@Entity
public class EntityTwo
{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "ELEMENT_ID")
private Long element_id;
...
}
有人可以告诉我我的模型有什么问题?
在此先感谢。
Can someone please tell me what is wrong with my model?Thanks in advance.
推荐答案
嗯,这个消息是自我解释的:列类型不匹配在Java级别使用的类型。如果您想痛斥 Long
,请使用 BIGINT
作为列类型。
Well, the message is self-explaining: the column type doesn't match the type used at the Java level. If you want to sore a Long
, use a BIGINT
as column type.
更新:我使用Hibernate测试了您的代码作为JPA提供程序,并且 ENTITYONE.ENTITY_TWO_ID
生成为 BIGINT
栏。也许你生成了你的表并在以后改变了Java类型而不再生成物理模型。我的建议是放弃表格并重试。
Update: I tested your code with Hibernate as JPA provider and ENTITYONE.ENTITY_TWO_ID
is generated as a BIGINT
column. Maybe you generated your table and changed the Java type later without regenerating the physical model. My suggestion would be to drop the table and to try again.
这篇关于JPA问题映射关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!