问题描述
我目前有此类产品,以这种方式注释(我正在使用软删除):
I currently have this class Product, annotated this way (I´m using soft delete):
@SQLDelete(sql = "UPDATE products SET active = '0' WHERE id_product = ? and last_modification_date = ?")
@Where(clause = "active = '1'" )
@Entity
@Table(name = "products ")
public class Product {
.....
}
如果要使用@Where子句过滤Bean(产品),那么我想要什么,这样一个用户只能看到它自己公司的产品.公司ID位于会话中,并且由于@SQLDelete接收参数,因此我想执行以下操作:
What I want if to FILTER the beans (products), using the @Where clause, so that one user can only see the products from it own company. The company ID is in the session, and since the @SQLDelete receives parameters, I wanted to do something like:
@Where(clause = "active = '1' and id_company = ?" )
以便我可以过滤所有表以根据每个用户获取结果,而不必编辑系统中的所有查询.有什么办法可以做到?
so that i can filter ALL the tables to fetch results according each user, without having to edit all the queries in the system. Is there any way to accomplish this?
任何帮助都会非常感激.
另外,请让我知道是否需要更多信息来理解问题.
Any help will be very aprecciated.
Also, let me know if more info is needed to understand the problem.
推荐答案
在休眠状态下有很多方法,
There are many ways of doing this in hibernate,
String hql = "from Stock s where s.stockCode = :stockCode";
List result = session.createQuery(hql)
.setString("stockCode", "7277")
.list();
您可以从此链接 http://www.mkyong .com/hibernate/hibernate-parameter-binding-examples/
这篇关于Hibernate注释@Where带有参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!