我正在尝试在我的Hibernate映射中设置默认架构,如下所示:
<persistence-unit name="store">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jar-file>store-data-0.0.4-SNAPSHOT.jar</jar-file>
<properties>
<property
name="hibernate.show_sql"
value="true" />
<property
name="hibernate.format_sql"
value="true" />
<property
name="hibernate.default_schema"
value="Store"></property>
<property
name="hibernate.archive.autodetection"
value="class" />
</properties>
</persistence-unit>
但是,当我运行一个简单的测试查询时:
@PersistenceContext
private EntityManager manager;
@Transactional
public List<Person> listPeople() {
return manager.createQuery("SELECT p FROM Person p", Person.class).getResultList();
}
我明白了:
无效的对象名称“人物”。
当我运行本机查询时:
manager.createNativeQuery("SELECT * FROM Store.Person", Person.class).getResultList();
一切正常。
我正在使用Spring运行SE应用程序。我之前在Web应用程序中使用过hibernate.default_schema
,它运行得很好。
这是我声明实体映射的方式:
<bean
id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property
name="dataSource"
ref="mysqlDataSource" />
<property
name="packagesToScan"
value="com.base.package" /> <!-- base package for all my entities -->
<property name="jpaVendorAdapter">
<bean
class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
</property>
</bean>
有什么想法吗?
答案 0 :(得分:4)
我可以通过直接在Spring上下文文件中设置默认架构来解决问题:
<bean
id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property
name="dataSource"
ref="mysqlDataSource" />
<property
name="packagesToScan"
value="com.base.package" /> <!-- base package for all my entities -->
<property name="jpaVendorAdapter">
<bean
class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
</property>
<property name="jpaProperties">
<props>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.default_schema">Store</prop>
</props>
</property>
</bean>