Order By

I have currently the below criteria :- Criteria addr = criteria.createCriteria("location.address"); addr.add((Restrictions.and(Restrictions.between("latitude", latmin, latmax), Restrictions.between("longitude", truelongmin, truelongmax)))); String sql = "SQRT( POW( 69.1 * ( {alias}.latitude - " + point[1]

排序依据

我目前有以下标准: - Criteria addr = criteria.createCriteria("location.address"); addr.add((Restrictions.and(Restrictions.between("latitude", latmin, latmax), Restrictions.between("longitude", truelongmin, truelongmax)))); String sql = "SQRT( POW( 69.1 * ( {alias}.latitude - " + point[1] +" ) , 2 ) + P

Hibernate Criteria and row count restriction

i have two entities named Parent and Child , linked in a one-to-many relationship. The Child entity has a boolean isStudent property. How do i get, using the Hibernate Criteria API, all the Parent entities that have at least one Child with isStudent = true ? I was trying to use a Projection object to count all the parents that have at least one Child with the property correctly set, and then

Hibernate标准和行数限制

我有两个名为父和子的实体, 以一对多的关系链接。 Child实体具有布尔isStudent属性。 我如何使用Hibernate Criteria API获得至少一个具有isStudent = true Child的所有Parent实体? 我试图使用Projection对象来计算所有至少有一个属性正确设置的Child的父对象,然后返回那些行计数大于零的父对象,如下面的一段代码(这不起作用,虽然): Criteria criteria = getCurrentSession().createCriteria(Parent.class); criter

Criteria vs. JPQL or HQL

What are the pros and cons of using Criteria or HQL? The Criteria API is a nice object-oriented way to express queries in Hibernate, but sometimes Criteria Queries are more difficult to understand/build than HQL. When do you use Criteria and when HQL? What do you prefer in which use cases? Or is it just a matter of taste? I mostly prefer Criteria Queries for dynamic queries. For example i

标准与JPQL或HQL

使用Criteria或HQL有什么优点和缺点? Criteria API是在Hibernate中表达查询的一种很好的面向对象的方式,但有时候Criteria Queries比HQL更难理解/构建。 您何时使用Criteria和何时使用HQL? 你更喜欢哪些用例? 或者这只是一个品味问题? 我大多更喜欢Criteria Queries查询动态查询。 例如,动态添加某些排序或者根据某些参数留下一些部分(例如限制)会更容易。 另一方面,我使用HQL进行静态和复杂查询,因为它更容

SQL Exception while connecting to oracle 11g from web application using jdbc

I am getting SQL Exception. The following is my code, public DBConnect() { try { // Load the Oracle JDBC driver DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver()); // connect through driver conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","system","system123"); // conn = DriverMa

使用jdbc从Web应用程序连接到Oracle 11g时的SQL异常

我正在获取SQL异常。 以下是我的代码, public DBConnect() { try { // Load the Oracle JDBC driver DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver()); // connect through driver conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","system","system123"); // conn = DriverManager.getConnecti

separated string but ignoring commas in quotes

I have a string vaguely like this: foo,bar,c;qual="baz,blurb",d;junk="quux,syzygy" that I want to split by commas -- but I need to ignore commas in quotes. How can I do this? Seems like a regexp approach fails; I suppose I can manually scan and enter a different mode when I see a quote, but it would be nice to use preexisting libraries. (edit: I guess I meant libraries that are already part

分隔字符串,但忽略引号中的逗号

我有一个像这样的字符串: foo,bar,c;qual="baz,blurb",d;junk="quux,syzygy" 我想用逗号分割 - 但我需要忽略引号中的逗号。 我怎样才能做到这一点? 似乎正则表达式的方法失败; 我想我可以手动扫描并在看到报价时进入不同的模式,但使用预先存在的库会很好。 (编辑:我想我是指已经是JDK一部分的库,或者已经是Apache Commons等常用库的一部分)。 上面的字符串应该分成: foo bar c;qual="baz,blurb" d;junk="quux,sy

HashMap get/put complexity

We are used to saying that HashMap get/put operations are O(1). However it depends on the hash implementation. The default object hash is actually the internal address in the JVM heap. Are we sure it is good enough to claim that the get/put are O(1) ? Available memory is another issue. As I understand from the javadocs, the HashMap load factor should be 0.75. What if we do not have enough

HashMap获取/放置复杂性

我们习惯于说HashMap get/put操作是O(1)。 但它取决于散列实现。 默认对象散列实际上是JVM堆中的内部地址。 我们确定它是否足以说明get/put是O(1)? 可用内存是另一个问题。 正如我从javadocs了解到的, HashMap load factor应该是0.75。 如果我们在JVM中没有足够的内存并且load factor超出限制会怎么样? 所以,看起来O(1)不能保证。 它有意义还是我错过了什么? 这取决于很多事情。 它通常是O(1),它有一

How do I print my Java object without getting "SomeType@2f92e0f4"?

I have a class defined as follows: public class Person { private String name; // constructor and getter/setter omitted } I tried to print an instance of my class: System.out.println(myPerson); but I got the following output: com.foo.Person@2f92e0f4 . A similar thing happened when I tried to print an array of Person objects: Person[] people = //... System.out.println(people); I got t

如何在不显示“SomeType @ 2f92e0f4”的情况下打印我的Java对象?

我有一个类定义如下: public class Person { private String name; // constructor and getter/setter omitted } 我试图打印我的课程的一个实例: System.out.println(myPerson); 但我得到了以下输出: com.foo.Person@2f92e0f4 。 当我尝试打印Person对象的数组时,发生了类似的情况: Person[] people = //... System.out.println(people); 我得到了输出: [Lcom.foo.Person;@28a418fc 这个输出是什么意思?

Threads on different Hardware

When I fist learned about Java threads, I've been told that, the multi threading is not real. That is, there is a single CPU and the OS does a context switch between threads to simulate multi threading. Nowdays, we have i3, i5 i7, dual core, core2dou and etc... So when I have a Java program that uses a thread pool in size 10 (for example), Assuming the thread pool is full with threads re

线程在不同的硬件上

当我第一次了解Java线程时,我被告知,多线程并不是真实的。 也就是说,只有一个CPU,OS在线程之间进行上下文切换以模拟多线程。 现在,我们有i3,i5 i7,双核,core2dou等等...... 因此,当我有一个Java程序使用10号线程池(例如)时,假设线程池已满,线程准备运行,多少个线程将在同一时间运行核心? 最多会有2个线程同时执行(2个核心),但还有更多的线程可能会被安排执行(等待cpu) 在开始时,Java有'绿色'

Access session of another web application

Is it possible to configure two separate web apps (WAR) in a J2EE application (EAR) to access a shared session context? Further info: I ended up creating a shared class from the EAR which stored the required information in static members. This did the trick, even if it seemed like a dirty hack. Not directly. Most containers put each WAR in a separate classloader with the EAR classloader a

访问另一个Web应用程序的会话

是否可以在J2EE应用程序(EAR)中配置两个独立的Web应用程序(WAR)来访问共享会话上下文? 更多信息: 我最终从EAR创建了一个共享类,它将所需的信息存储在静态成员中。 这样做的伎俩,即使它看起来像一个肮脏的黑客。 不直接。 大多数容器将每个WAR放在一个单独的类加载器中,并将EAR类加载器作为其父类。 每个应用的会话都是分开的。 您可以在每个会话中放置父EAR提供的内容。 如果您需要他们分享某些内容,请将其

slf4j logback custom output

I am using logback in a following way Logger log = LoggerFactory.getLogger(HomeController.class); log.debug("Lynas debug"); and this gives me output as following 15:12:21.070 [http-nio-8080-exec-1] DEBUG o.ipvision.controller.HomeController - Lynas debug Now I just want the time, class name and the message like below 15:12:21.070 DEBUG HomeController - Lynas debug As far as I know I need a

slf4j logback自定义输出

我以下面的方式使用logback Logger log = LoggerFactory.getLogger(HomeController.class); log.debug("Lynas debug"); 这给我输出如下 15:12:21.070 [http-nio-8080-exec-1] DEBUG o.ipvision.controller.HomeController - Lynas debug 现在我只想要时间,班级名称和下面的消息 15:12:21.070 DEBUG HomeController - Lynas debug 据我所知我需要一个属性文件来设置,但我不知道如何正确设置。 那么有人可以告诉我如何做