Hibernate - OGM [PersistenceUnit: person] Unable to build Hibernate SessionFactory

陌路散爱 提交于 2019-12-04 10:41:00

The root exception says it all:

Caused by: org.hibernate.HibernateException: Unanticipated return type [java.lang.Long] for UUID

You are using a UUID id generator on a type which it does not support. You should use String instead of Long in this case.

  1. if you use this deprecated org.hibernate.ejb.HibernatePersistence set new provider like below

<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>

  1. if your value is

<property name="hibernate.hbm2ddl.auto" value="update" />

set "create-drop"

<property name="hibernate.hbm2ddl.auto" value="create-drop" />

  1. XML path: resources/META-INF/persistence.xml
  2. For mysql

<?xml version="1.0" encoding="UTF-8"?>

<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                 xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">

        <persistence-unit name="persistenceUnit" transaction-type="RESOURCE_LOCAL">
            <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
            <properties>
                  <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
                  <property name="hibernate.hbm2ddl.auto" value="create-drop" />
                  <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
                  <property name="hibernate.show_sql" value="true"/>
                  <property name="hibernate.connection.username" value="yourname"/>
                  <property name="hibernate.connection.password" value="yourpassword"/>
                  <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/yourschema"/>
                  <property name="hibernate.max_fetch_depth" value="3"/>
            </properties>
        </persistence-unit>

    </persistence>

Firstly you should share your the complete stacktrace about the exception and the persistence.xml content. Then in my opinion based on what I see the problem could be that you don't have declared a persistence provider in your persistence.xml. In fact if you are developing in a non container managed envirorment you need to declare a persistence provider.

<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="myunit" >
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    //Others properties
</persistence-unit>

I do not know if the problem still exists, but I thought you have to put the persistence.xml file into src/main/META-INF folder. I see you put it into src/META-INF. Maybe that is the Problem? and of course the entities you want to link belong in src/main folder, too :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!