在hibernate中查询?(In query in hibernate?)
我正在使用hibernate,我可以使用这个获得工资为2000的员工列表。
Criteria cr = session.createCriteria(Employee.class); cr.add(Restrictions.eq("salary", 2000)); List results = cr.list();
现在我想让员工的工资分别为2000和3000。
我如何使用标准在hibernate
in query
?I am using hibernate and i am able to get the list of employeees having salary as 2000 using this.
Criteria cr = session.createCriteria(Employee.class); cr.add(Restrictions.eq("salary", 2000)); List results = cr.list();
Now i want to get the employees having salary as 2000 and 3000 .
How i can use
in query
in hibernate using criteria?
原文:https://stackoverflow.com/questions/14355220
更新时间:2022-01-12 12:01
最满意答案
不,因为EntityManager绝对不是线程安全的。 您需要使用提供者。
No, since EntityManager is absolutely not Thread-safe. You need to use providers.
相关问答
更多-
Guice也很容易! 创建两个标注注释,比如@One和@Two ,然后 bind(MySingleton.class).annotatedWith(One.class).toInstance(new MySingleton()); bind(MySingleton.class).annotatedWith(Two.class).toInstance(new MySingleton()); 接着 @Inject public SomethingThatDependsOnSingletons(@One MyS ...
-
要记住的关键是设计模式只是一个帮助您理解抽象概念的工具。 一旦你有了这个理解,把你自己专门限制在一本书中的“食谱”就没有意义了,并且伤害了你编写最适合你目的的代码的能力。 也就是说,阅读GoF这样的书籍将会给您更多的方式来思考问题,以便在时候自行实施某些事情的时候,您会有更广泛的观点来解决问题。 在你的情况下,如果在每一种情况下使用单身人士都是有道理的,那么就要走在前面。 如果它“适合”,你必须以一些笨重的方式实现它,那么你需要提出一个新的解决方案。 强制不完美的图案有点像在圆孔中敲一个方形钉。 鉴于你说“ ...
-
斯威夫特单身人士(Singletons In Swift)[2023-10-30]
回到Swift的一天, static let还没有实现。 解决方法是创建一个包装struct 。 随着Swift 2 ,这不再需要。 Back in Swift 1 days, static let wasn't implemented yet. The workaround was to create a wrapper struct. With Swift 2, this is not needed anymore. -
单身人士和ICommand(Singletons and ICommand)[2023-01-01]
由于类遵循单例模式,因此行为应该没有任何差异。 任何引用单例的东西都不会关心如何限制类的构造,只关注类的实例是否存在。 问题可能在于ViewModel的PropertyChanged事件与Command上的CanExecuteChanged之间缺少正确的链接。 There shouldn't be any difference in the behavior due to the fact that a class follows the singleton pattern. Anything with a ... -
我遇到了这个特殊的问题,我需要从两个不同的数据源中获取数据。 - >当您使用两个数据源时,您可以使用/创建两个SessionFactory。 我不知道myBatis。 你可以做的是创建BaseDao类,由所有dao类扩展它。 自动连接两个SessionFactory和DataSource 。 创建两个不同的getter方法以从两个Session工厂获取会话。 您可以从所有Dao类访问两个SessionFactories。 public class BaseDao { // Declare and a ...
-
您应该使用此绑定: bind(UserManagerImpl.class).in(Singleton.class); bind(UserManager.class).to(UserManagerImpl.class); 这需要注意UserManagerImpl是真正的单例,而不是接口。 那样叫两个 injector.getInstance(UserManager.class); injector.getInstance(UserManagerImpl.class); 将导致相同的实例。 ...
-
你的方法很好。 单例的常见问题(除了全局可变状态,听起来这不是问题)是单例管理它自己的单一(意味着像静态getInstance方法),使得它很难测试。 在春天,通过让工厂控制单身人士的范围来处理。 单身人士的另一个棘手方面是如何从任何地方调用任何东西。 您可以使用规范的分层方法来处理这个问题。 Your approach is fine. The usual problem with singletons (aside from global mutable state, which it sounds l ...
-
如本文所述,您需要与HK2建立联系。 @Inject public ApplicationResource(ServiceLocator locator) { GuiceBridge.getGuiceBridge().initializeGuiceBridge(locator); // add your Guice modules. Injector injector = Guice.createInjector(new GuiceModule()); GuiceIntoHK ...
-
不,因为EntityManager绝对不是线程安全的。 您需要使用提供者。 No, since EntityManager is absolutely not Thread-safe. You need to use providers.
-
如果您想要一个如下注射部位: @Inject public DAOConsumer(DAO
dao) { } 然后注入您的UserDAO类的实例 bind(new TypeLiteral >() {}).to(UserDAO.class); 是正确的语法 。 至于你的其他错误: 1)没有为org.mongodb.morphia.Datastore实现绑定。 这是因为Datastore是一个接口。 您需要将接口绑定到实现,实例或Provider 。 要了 ...