Friday, January 11, 2013

NullPointerException with Hibernate 4

java.lang.NullPointerException at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:207) at org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:75) at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:159)

The exception above can be resolved by adding this Hibernate property:
<property name="hibernate.temp.use_jdbc_metadata_defaults">false</property>

Thursday, January 10, 2013

"No runnable methods" when using Maven for a class that shouldn't be Tested

I recently ran into a problem doing a Maven build where I had a utility class to be used for my Test cases. Adding the @Ignore tag didn't seem to help. It turns out the solution was simply to add this plugin entry to my pom.xml file as my file had the suffix Util.java:

<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-surefire-plugin</artifactId>
   <configuration>
      <excludes>
         <exclude>**/*Util.java</exclude>
      </excludes>
   </configuration>
</plugin>

Tuesday, October 9, 2012

ClassNotFoundException: org.hibernate.hql.ast.HqlToken

When using Hibernate to read from a Database using Weblogic 10 and Springframework 2.5.6, I encountered the following error:

ClassNotFoundException: org.hibernate.hql.ast.HqlToken

The reason for this is that it by default will use Weblogic's default classloader to load the antlr jar file and doesn't use the version included within your .war file.

To solve this you need to wrap your .war in an ear file and within the META-INF/weblogic-application.xml file within you .ear file include the following:
 <prefer-application-packages>
    <package-name>antlr.*</package>
 </prefer-application-packages>
 

This should resolve this issue.


Sunday, August 26, 2012

SQL String functions

Some STRING functions in SQL:

select RIGHT(column, chars) from table;
select SUBSTRING_INDEX(column, char, which char (i.e, 1,2...)) from table;
select REVERSE(string);
select LTRIM(string);
select RTRIM(string);
select LENGTH(string);

Monday, July 30, 2012

Java Pitfalls Book


This book "Java™ Puzzlers: Traps, Pitfalls, and Corner Cases" gives insight into some Java "fails" that one needs to watch out for when developing.

It explains what is wrong with this piece of code (It doesn't print out AB as one would expect):

public class PrintingSomeLetters {
  public static void main(String[] args) {
    System.out.println('A' + 'B');
  }
}

Friday, June 22, 2012

Design Patterns Book