IllegalArgumentException: Unknown entity

需要使用persistence.xml进行配置。

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <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">
 3   <persistence-unit name="WebofficeOne" transaction-type="RESOURCE_LOCAL">
 4     <provider>org.hibernate.ejb.HibernatePersistence</provider>
 5 <!--     <jta-data-source>dataSource</jta-data-source> -->
 6     <class>net.etec.ftm.domain.City</class>
 7     <class>net.etec.ftm.domain.Country</class>
 8     <exclude-unlisted-classes>false</exclude-unlisted-classes>
 9     <properties>
10         <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />
11         <property name="hibernate.show_sql" value="true"/>
12         <property name="hibernate.hbm2ddl.auto" value="update"/>
13         <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect"/>
14         <property name="hibernate.connection.username" value="root"/>
15         <property name="hibernate.connection.password" value="801216"/>
16         <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/test?createDatabaseIfNotExist=true"/>
17         <property name="hibernate.c3p0.min_size" value="5"/>
18         <property name="hibernate.c3p0.max_size" value="20"/>
19         <property name="hibernate.c3p0.timeout" value="300"/>
20         <property name="hibernate.c3p0.max_statements" value="50"/>
21         <property name="hibernate.c3p0.idle_test_period" value="3000"/>
22     </properties>
23   </persistence-unit>
24 </persistence>

 

实体工厂配置

 1     <bean id="entityManagerFactory"
 2         class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
 3         <property name="persistenceUnitName" value="WebofficeOne" />
 4 <!--         <property name="dataSource" ref="dataSource" /> -->
 5         <property name="jpaVendorAdapter" ref="hibernateJpaVendorAdapter" />
 6 <!--         <property name="packagesToScan" value="com.etec.ftm.domain" /> -->
 7         <property name="persistenceXmlLocation" value="classpath:META-INF/persistence-instance.xml"/>
 8         <property name="jpaProperties">
 9             <props>
10                 <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
11                 <prop key="hibernate.ejb.naming_strategy">org.hibernate.cfg.ImprovedNamingStrategy</prop>
12                 <prop key="hibernate.show_sql">true</prop>
13                 <prop key="hibernate.hbm2ddl.auto">create</prop>
14             </props>
15         </property>
16     </bean>
posted @ 2014-10-14 15:22  LeonGo  阅读(1085)  评论(0编辑  收藏  举报