本文介绍了有没有办法给没有persistence.xml Spring的LocalContainerEntityManagerFactoryBean persistenceUnitName?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的spring上下文中定义了多个数据源和多个EntityManagerFactories。

如果仅在EntityManagerFactory上,我们不需要给persistenceUnitName。但要将EntityManager与@PersistenceContext关联来修改EntityManagerFactory,我应该给unitName =somePU属性。



但是,如果我们为persistenceUnitName属性命名,那么Spring将在persistence.xml文件中预期这些persistenceUnitName声明。



有没有办法给Spring的LocalContainerEntityManagerFactoryBean提供persistenceUnitName而不使用persistence.xml?

另外我发现另一个问题,当我用Spring的LocalContainerEntityManagerFactoryBean使用persistence.xml时。 packagesToScan属性不起作用。我需要列出persistence.xml中的所有实体类。



任何想法为什么会发生?



-siva

解决方案指定 LocalContainerEntityManagerFactoryBean 中的属性



 < property name =persistenceUnitNamevalue =MyPersistenceUnit/> 


I have multiple datasources and multiple EntityManagerFactories to be defined in my spring context.

If there is only on EntityManagerFactory we don't need to give persistenceUnitName. But to associate EntityManager to correct EntityManagerFactory with @PersistenceContext I should give unitName="somePU" attribute.

But if we give name for persistenceUnitName attribute then Spring is expecting these persistenceUnitName declarations in persistence.xml file.

Is there a way to give persistenceUnitName for Spring's LocalContainerEntityManagerFactoryBean without persistence.xml?

Also I found another issue when I used persistence.xml with Spring's LocalContainerEntityManagerFactoryBean. The packagesToScan property is not working. I need to list down all the Entity classes in persistence.xml.

Any idea why it is happening?

-siva

解决方案

Specifying property in LocalContainerEntityManagerFactoryBean works for me

    <property name="persistenceUnitName" value="MyPersistenceUnit"/>

这篇关于有没有办法给没有persistence.xml Spring的LocalContainerEntityManagerFactoryBean persistenceUnitName?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-24 16:00