Failed to create EntityManagerFactory

persistence.xml file

<?xml version="1.0" encoding="UTF-8"?> <persistence version="1.0" 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_1_0.xsd"> <persistence-unit name="xyz" transaction-type="JTA"> <provider>org.hibernate.ejb.HibernatePersistence</provider> <class>com......</class> </persistence-unit> </persistence> 

applicationContext.xml

 <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> <property name="entityManagerFactory" ref="entityManagerFactory" /> </bean> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" /> <property name="url" value="jdbc:oracle:thin:@localhost:1521:XE" /> <property name="username" value="yyy" /> <property name="password" value="yyy" /> </bean> <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> <property name="persistenceUnitName" value="xyz" /> <property name="dataSource" ref="dataSource" /> <property name="jpaVendorAdapter"> <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"> <property name="databasePlatform" value="org.hibernate.dialect.Oracle10gDialect" /> <property name="showSql" value="true" /> <!-- <property name="generateDdl" value="true" /> --> </bean> </property> </bean> <bean id="theDao" class="com.cin.the.dataaccess.dao.the.TheJPA"> <property name="entityManagerFactory" ref="entityManagerFactory"></property> </bean> 

the error i get is

 [PersistenceUnit: xyz] Unable to build EntityManagerFactory 

can someone tell me a mistake

+4
source share
3 answers

The main problem was that entites were not generated properly. so at the end of stacktrace he was throwing this error

 Caused by: org.hibernate.MappingException: property mapping has wrong number of columns: com......date type: object 

as soon as the object was generated correctly, the problem was resolved.

+8
source

Someone answered here :

If you define a persistence block with a JTA transaction type, you must also define your data source inside the jta data source attribute.

Try adding this to your ApplicationContext.xml

 <jee:jndi-lookup id="dataSource" jndi-name="your-jndi-name" /> 

and the following <persistence-unit> element in persistence.xml :

 <jta-data-source>your-jndi-name</jta-data-source> 
+1
source

You get this error because you have mapped your domain data type as java.lang.Object. map it to more specific ones like String, int, long ...

0
source

Source: https://habr.com/ru/post/1336438/


All Articles