This blog is mainly about Java...

Thursday, August 20, 2009

Using Enum in your entity beans

It is quite handy to use an Enum, especially with type String. This means that the enum will be translated as a text field in your database.

Imagine the following Entity
public class Simple {
Process process;

public void Process getProcess() {
return process;

public enum Process {

Now, I initally thought, that since you are defining the enum type to be string, then you can simply query the database using string as well like this:
entityManager.createQuery("from Simple s where s.process=:process").setParameter("process","WHAT").getResultList();
However this doesn't work. You will need to use an Enum type. So the solution is to use Enum.valueOf()
entityManager.createQuery("from Simple s where s.process=:process").setParameter("process",Process.valueOf("WHAT")).getResultList();

Now the query will run and return your list :-)

Tuesday, August 4, 2009

Wicket error in Seam test

The Problem

Recently we upgrade to Seam 2.1.x and suddenly our testng test using ant failed with the following message:
No wicket components directory specified to give Seam super powers to
Wicket was added to Seam 2.1.0.BETA1.
This error message doesn't really say anything. Also it said further:
Must set application-class using  in components.xml 

But we where not using wicket and didnt want to add it.

The stacktrace was as following:
WARN  [org.jboss.seam.wicket.web.WicketFilterInstantiator] No wicket components directory specified to give Seam super powers to
[testng] FAILED: getDefaultContacts
[testng] java.lang.IllegalStateException: Must set application-class using in components.xml
[testng] at org.jboss.seam.wicket.web.WicketFilterInstantiator$1.init(
[testng] at org.jboss.seam.web.WicketFilter.doFilter(
[testng] at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(
[testng] at org.jboss.seam.web.HotDeployFilter.doFilter(
[testng] at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(
[testng] at org.jboss.seam.servlet.SeamFilter.doFilter(
[testng] at org.jboss.seam.mock.AbstractSeamTest$
[testng] at no.whatever.test.AddressBookTest.getDefaultContacts(
[testng] ... Removed 22 stack frames
[testng] FAILED: setup

The Solution

It seems like ant will just put all the libraries in the lib folder in the classpath, and eclipse obviously would not. Thus, when the wicket jars where removed, the tests where back online. I believe it is sufficient to remove jboss-seam-wicket.jar and jboss-seam-wicket-ant.jar, however I just removed all jars that included the name wicket.