JPA映射关系的问题

时间:2010-03-26 08:51:14

标签: java hibernate orm jpa

当我尝试坚持我的模型时,我遇到了问题。创建EntityManagerFactory时抛出异常:

  

块引用   javax.persistence.PersistenceException:[PersistenceUnit:ASD]无法构建EntityManagerFactory       在org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:677)       在org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:126)       在javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:52)       在javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:34)       在project.serealization.util.PersistentManager.createSession(PersistentManager.java:24)       在project.serealization.SerializationTest.testProject(SerializationTest.java:25)       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)       at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)       at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)       at java.lang.reflect.Method.invoke(Unknown Source)       在junit.framework.TestCase.runTest(TestCase.java:168)       在junit.framework.TestCase.runBare(TestCase.java:134)       在junit.framework.TestResult $ 1.protect(TestResult.java:110)       在junit.framework.TestResult.runProtected(TestResult.java:128)       在junit.framework.TestResult.run(TestResult.java:113)       在junit.framework.TestCase.run(TestCase.java:124)       在junit.framework.TestSuite.runTest(TestSuite.java:232)       在junit.framework.TestSuite.run(TestSuite.java:227)       在org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:79)       在org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)       在org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)       在org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)       在org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)       在org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)       在org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)   引起:org.hibernate.HibernateException:列ENTITY_TWO_ID的asd.entity_one中的列类型错误。发现:双倍,预期:bigint       在org.hibernate.mapping.Table.validateColumns(Table.java:284)       在org.hibernate.cfg.Configuration.validateSchema(Configuration.java:1116)       在org.hibernate.tool.hbm2ddl.SchemaValidator.validate(SchemaValidator.java:139)       在org.hibernate.impl.SessionFactoryImpl。(SessionFactoryImpl.java:349)       在org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1327)       在org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:867)       在org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:669)       ......还有24个

两个实体的代码如下:

@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;

...
}

有人可以告诉我我的模特有什么问题吗? 提前谢谢。

1 个答案:

答案 0 :(得分:2)

嗯,该消息是自我解释的:列类型与Java级别使用的类型不匹配。如果您想感染Long,请使用BIGINT作为列类型。

更新:我使用Hibernate作为JPA提供程序测试了您的代码,ENTITYONE.ENTITY_TWO_ID生成为BIGINT列。也许您生成了表并在以后更改了Java类型而不重新生成物理模型。我的建议是放下桌子再试一次。