persistence.xml文件
<?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>
我得到的错误是
[PersistenceUnit: xyz] Unable to build EntityManagerFactory
任何人都可以告诉我错误
答案 0 :(得分:8)
主要问题是entites没有正确生成。所以在堆栈跟踪结束时它给出了这个错误
Caused by: org.hibernate.MappingException: property mapping has wrong number of columns: com......date type: object
一旦正确生成实体,问题就解决了
答案 1 :(得分:1)
如果使用JTA事务类型定义持久性单元,则为 还需要在jta-data-source中定义数据源 属性。
尝试将此添加到您的ApplicationContext.xml
<jee:jndi-lookup id="dataSource" jndi-name="your-jndi-name" />
以及<persistence-unit>
中persistence.xml
元素的以下内容:
<jta-data-source>your-jndi-name</jta-data-source>
答案 2 :(得分:0)
您收到此错误是因为您已将域对象数据类型映射为java.lang.Object。将它映射到更具体的类似String,int,long ......