【发布时间】:2015-10-27 07:18:58
【问题描述】:
我目前正在使用 JPA 规范从数据库中查询我的对象。
每当我(我的软件实例)进行更改时,项目都会正确刷新。
但是,如果其他人进行了其他更改(其他实例或数据库更改),则项目不会正确刷新。
我正在使用带有“刷新”的简单“查找”
Object found = getManager().find(getModelClass(), id);
getManager().refresh(found);
我正在使用 DAO 层次结构,“getModelClass”返回我的 @Entity 类,如
@Override
protected Class<?> getModelClass() {
return ProductCategory.class;
}
还有我的 Manifest/persistence.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<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_2_0.xsd"
version="2.0" xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="casa" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
<!-- localhost -->
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/database" />
<property name="javax.persistence.jdbc.user" value="root" />
<property name="javax.persistence.jdbc.password" value="root" />
<property name="hibernate.show_sql" value="false" />
<property name="hibernate.format_sql" value="false" />
<property name="hibernate.use_sql_comments" value="false" />
<property name="hibernate.jdbc.wrap_result_sets" value="false" />
<property name="hibernate.hibernate.cache.use_query_cache" value="true" />
<property name="hibernate.hbm2ddl.auto" value="update" />
</properties>
</persistence-unit>
</persistence>
每个“DAO”都有自己的实例和EntityManager。
我可能做错了什么?
感谢您的帮助!
【问题讨论】:
标签: java hibernate jpa hibernate-4.x