假设有一个带有结构的User表:
用户
我想只检索当前公司的用户(公司可以由用户通过UI更改,因此公司是运行时参数)
类似地,还有许多其他表与公共列(公司)具有相似的结构,我想将数据限制为仅当前公司,因此我使用hibernate过滤器来过滤数据.
Hibernate注释:
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">Dialect....</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.generate_statistics">true</prop>
<prop key="hibernate.connection.release_mode">after_transaction</prop>
<prop key="hibernate.cache.use_second_level_cache">false</prop>
</props>
</property>
<property name="annotatedClasses">
<list>
<value>User</value>
.....
</list>
</property>
</bean>
Run Code Online (Sandbox Code Playgroud)
过滤器定义:
@org.hibernate.annotations.FilterDef(name="restrictToCurrentCompany",
parameters = {@org.hibernate.annotations.ParamDef(
name = "currentCompanyNumber", type = "int"
)
}
)
@Entity
@Table(name = "USER")
@org.hibernate.annotations.Filter(
name = "restrictToCurrentCompany",
condition="company = :currentCompanyNumber"
)
public class User implements Serializable {
private int company;
private String userName; … 我在Spring Framework应用程序中使用Hibernate作为JPA提供程序(我使用它EntityManagerFactory而不是它SessionFactory).我设法让Spring Framework的加载时间编织支持工作,所以我已经超越了这个障碍.
我需要在实体上启用延迟加载byte[]和@ManyToOne属性.我理解如何使用Hibernate的ant任务在构建时检测(编织)我的实体,但是我想在运行时检测我的实体(加载时间编织).我已经看到过几个谷歌搜索结果的引用,但没有启用它的实际说明.我需要设置什么属性来指示Hibernate它可以在运行时检测我的实体?
spring hibernate jpa hibernate-entitymanager load-time-weaving
我在我的Web应用程序中使用Spring MVC和Hibernate.我正在寻找一种方法来创建一个全局的hibernate过滤器,它将应用于我的DAO类中的每个查询,而不必在每个DAO方法中显式启用它.
要求是按用户选择的会话变量过滤记录.因此,我们的查询参数将保存在会话中,该会话中的所有DAO查询都需要通过此变量过滤结果.这里的目的是避免每个DAO方法中的所有可重复过滤代码.
欢迎任何和所有的想法!