Skip to main content

Posts

Showing posts from 2016

How could I be so stupid using hibernate criteria with timestamp?

I needed to make a query to find all records valid today for columns with effectiveFrom and effectiveTo range I spent a couple of hours trying to understand why             criteria.add(Restrictions.ge("effectiveFrom",currentDate.getTime()));             criteria.add(Restrictions.le("effectiveTo",currentDate.getTime())); was giving no results. After many trials and attempts with other criteria tricks, I remembered that hibernate is not comparting if  currentDate.getTime is greater than effectiveFrom, but if effectiveFrom is greater than currentDate.getTime So correct sintax for it was the exact opposite             criteria.add(Restrictions.le("effectiveFrom",currentDate.getTime()));             criteria.add(Restrictions.ge("effectiveTo",currentDate.getTime())); This one worked as it should 

Java ALWAYS passes by value (and it is ALWAYS an interesting discussion)

Always good as a refresher. So, when calling a method For primitive arguments ( int ,  long , etc.), the pass by value is  the actual value  of the primitive (for example, 3). For objects, the pass by value is the value of  the reference to the object . http://stackoverflow.com/questions/40480/is-java-pass-by-reference-or-pass-by-value

How I ran Gradle with cntlm

I was behind a corporate firewall and had to run gradlew (gradle) from Cygwin. The system was running a cntlm authentication proxy. I ran the following command export http_proxy=http://127.0.0.1:3128/ export https_proxy=$http_proxy Then I ran ./gradlew -Dhttps.proxyHost=127.0.0.1 -Dhttps.proxyPort=3128 -Dhttp.proxyHost=127.0.0.1 -Dhttp.proxyPort=3128 I hope it helps 

UNION makes ALL the strength

Following the advice from a very expert consultant, I changed my views from an UNION between two select from the same table to UNION ALL and the performance improvements were simply amazing. Before doing so, I had verified that the query were returning different results with the INTERSECT command before doing so. The difference is that UNION verifies that records are unique, while UNION ALL doesn't. The performance gain is very remarkable 

Hibernate Stored Procedure with first parameter not "OUT"

I spent some days trying to call a Stored Procedure through Hibernate. I used CreateSQLQuery  and I made my own custom transformer, but I could not get it work. I keep geeting Wrong Type and Parameter of procedure exception. My procedure was like the following     procedure GET_BY_EMPLOYEE (         P_EMPLOYEE_ID   in       EMPLOYEE_ID%TYPE       , P_DATE_FROM  in       date       , P_DATE_TO    in       date       , P_REF           out      CURSORREFERENCETYPE); After days of searching, I found this http://docs.jboss.org/hibernate/orm/4.2/devguide/en-US/html/ch13.html#sp_query For Oracle the following rules apply: A function must return a result set. The first parameter of a procedure must be an  OUT  that returns a result set. This is done by using a  SYS_REFCURSOR  type in Oracle 9 or 10. In Oracle you need to define a REF CURSOR  type. See Oracle literature for further information. So there is no way to get this procedure to work in hibernate. I will use