3
我試圖堅持一個使用我的bean中定義的EntityManagerFactory的實體。功能看起來像這樣:Javax持久性錯誤:未知實體com.samplewebentities.Customer
private BaseMasterEntity saveEntity(BaseMasterEntity entity){
EntityManagerFactory emf = (EntityManagerFactory)context.getBean("entityManagerFactory");
EntityManager sf = emf.createEntityManager();
sf.getTransaction().begin();
sf.persist(entity);
sf.getTransaction().commit();
sf.close();
return entity;
}
這裏的問題是當它持續存在時它找不到實體。該實體具有明確用javax.persistance註釋定義的@Entity。這是我的上下文文件的外觀BTW:
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
<property name="url" value="*my jdbc setting*" />
<property name="username" value="hr" />
<property name="password" value="hr" />
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="jpaVendorAdapter" ref="hibernateJpaVendorAdapter" />
<property name="packagesToScan"
value="classpath*:com.samplewebentities"></property>
<property name="jpaProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop>
<prop key="hibernate.hbm2ddl.auto">create</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
<bean id="hibernateJpaVendorAdapter"
class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
<tx:annotation-driven transaction-manager="transactionManager" />
如果有幫助,在classpath *:com.samplewebentites是一個不同的組件(該應用程序是許多不同的組件/項目的組合:使用SCA這裏)。
的可能的複製[如何自動註冊使用JPA/Hibernate的實體:未知實體(http://stackoverflow.com/questions/4939732/how-to-auto -register-entities-with-jpa-hibernate-unknown-entity) –
我讀過這個問題,實際上他直接列出類,我想做一個包級搜索。 –