我收到以下错误
Exception in thread “main” javax.persistence.PersistenceException: [PersistenceUnit: person] Unable to build Hibernate SessionFactory at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.persistenceException(EntityManagerFactoryBuilderImpl.java:1249) at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.access$600(EntityManagerFactoryBuilderImpl.java:120) at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:860) at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:850) at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:425) at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:849) at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:75) at org.hibernate.ogm.jpa.HibernateOgmPersistence.createEntityManagerFactory(HibernateOgmPersistence.java:63) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39) at com.ihappyk.utility.Utility.setUpEntityManagerFactory(Utility.java:11) at com.ihappyk.work.PersonWorker.main(PersonWorker.java:14) Caused by: org.hibernate.MappingException: Could not instantiate id generator [entity-name=com.ihappyk.model.Person] at org.hibernate.id.factory.internal.DefaultIdentifierGeneratorFactory.createIdentifierGenerator(DefaultIdentifierGeneratorFactory.java:123) at org.hibernate.mapping.SimpleValue.createIdentifierGenerator(SimpleValue.java:225) at org.hibernate.internal.SessionFactoryImpl.(SessionFactoryImpl.java:323) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1859) at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:857) … 9 more Caused by: org.hibernate.HibernateException: Unanticipated return type [java.lang.Long] for UUID conversion at org.hibernate.id.UUIDGenerator.configure(UUIDGenerator.java:111) at org.hibernate.id.factory.internal.DefaultIdentifierGeneratorFactory.createIdentifierGenerator(DefaultIdentifierGeneratorFactory.java:117) … 13 more
实用工具
public class Utility {
private static EntityManagerFactory entityManagerFactory;
//@BeforeClass
public static EntityManagerFactory setUpEntityManagerFactory() {
entityManagerFactory = Persistence.createEntityManagerFactory( "person" );
return entityManagerFactory;
}
//@AfterClass
public static void closeEntityManagerFactory() {
entityManagerFactory.close();
}
}
坚持班
@Entity
public class Person {
@Id
@GeneratedValue(generator = "uuid")
@GenericGenerator(name = "uuid", strategy = "uuid2")
private long id;
private String firstName;
private String lastName;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public Person(){
}
public Person(String firstName, String lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
}
主班
public class PersonWorker {
public static void main(String[] args) {
// TODO Auto-generated method stub
EntityManagerFactory emf = Utility.setUpEntityManagerFactory();
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
// create a Person
Person bob = new Person( "Bob", "McRobb" );
em.persist( bob );
em.getTransaction().commit();
em.close();
emf.close();
}
}
persistance.xml
<?xml version="1.0"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="person" transaction-type="JTA">
<provider>org.hibernate.ogm.jpa.HibernateOgmPersistence</provider>
<class>com.ihappyk.model.Person</class>
<properties>
<property name="hibernate.ogm.datastore.provider" value="mongodb" />
<property name="hibernate.ogm.datastore.database" value="hibernateOGM" />
<property name="hibernate.ogm.datastore.host" value="127.0.0.1" />
<property name="hibernate.ogm.datastore.port" value="27017" />
<property name="hibernate.ogm.datastore.provider" value="org.hibernate.ogm.datastore.mongodb.impl.MongoDBDatastoreProvider"/>
<property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.JBossStandAloneJtaPlatform"/>
</properties>
</persistence-unit>
</persistence>
根本异常说明了一切:
Caused by: org.hibernate.HibernateException: Unanticipated return type [java.lang.Long] for UUID
您正在使用不支持的UUID ID生成器。在这种情况下,应使用String
代替Long
。
我得到以下错误 persistance.xml
Hibernate 团队对外宣布了一个新的家族成员,Hibernate OGM, OGM 是 Object Grid Mapping的缩写,它的目标是试图使用 JPA 来操作 NoSQL数据库。 示例代码: @PersistenceContext EntityManager em;// the transaction boundary is really here to express the f
是否可以使用Hibernate ORM和OGM创建单个应用程序?我创建了一个应用程序,我在一个应用程序中遇到了多个JPA的问题。我通过更改两个JPA的名称解决了这个问题,但两个JPA之间仍然存在冲突。以下是例外情况: 原因:org.springframework.beans.factory.无法将类型[org.hibernate.internal.SessionFactoryImpl]的参数值转换
问题内容: 我们使用spring,jpa,tomcat,maven等开发应用程序。 在我的开发人员机器本地,一切正常,但是当我们在Linux服务器上部署应用程序时,出现以下异常: 当我调用此方法时,初始化数据库后,异常出现在我的代码中: 找不到问题。感谢帮助!谢谢 问题答案: 多亏了master-slave,我发现了问题,因为他描述了与javassist的不兼容Java 8库存在冲突。 就我而言,
我正在使用Hibernate和spring boot。我注意到,如果我从包中包含注释和 并尝试运行spring启动应用程序。我的应用程序启动失败,出现以下错误。 当我删除这些注释并尝试运行应用程序时。应用程序启动良好。 审计实体。JAVA 波姆。xml 我将审计实体嵌入到userentity中。 下面是userEntity的代码。JAVA 我相信这是因为我引入了一些与hibernate相关的类,这
我刚开始使用hibernate,总是会遇到这样的错误: 错误:HHH000388:不成功:创建表用户(id bigint not null auto_increment,mail varchar(255),passwort varchar(255),primary key(id))错误:从存储引擎获取错误-1 这是我的映射类: