首页 \ 问答 \ 在hibernate中查询?(In query in hibernate?)

在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这样的书籍将会给您更多的方式来思考问题,以便在时候自行实施某些事情的时候,您会有更广泛的观点来解决问题。 在你的情况下,如果在每一种情况下使用单身人士都是有道理的,那么就要走在前面。 如果它“适合”,你必须以一些笨重的方式实现它,那么你需要提出一个新的解决方案。 强制不完美的图案有点像在圆孔中敲一个方形钉。 鉴于你说“ ...
  • 回到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.
  • 由于类遵循单例模式,因此行为应该没有任何差异。 任何引用单例的东西都不会关心如何限制类的构造,只关注类的实例是否存在。 问题可能在于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 。 要了 ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。