Not strictly Java related but I thought I could post it here. I was getting the error
Unknown runtime error Line: 120 Char: 1 Code: 0 URI: 3_3_3.Finalorg.ajax4jsf.javascript.AjaxScript
on I.E. (FF and Chrome worked fine) when I included a form within a form in RichFaces. As soon as I got rid of the second form (in the included file) the problem went away.

Java Tips and Tricks
This is weird, I am not sure why I am getting it. I have an application that makes some calculations that take some considerable time, and I persist the results. I run my application with 100 records from the database and everything works fine. I run my application with 60.000 records from the database and I am getting the above error message. The exception happens when the flush() method is called on the EntityManager. If I am to have a wild guess I’d say that there is a transaction time out (it is set to 30 seconds in the weblogic console) and therefore when the flush() method is called there is no active transaction.
Anyway I managed to overcome this issue by explicitly defining a user transaction
import org.jboss.seam.transaction.Transaction;
import org.jboss.seam.transaction.UserTransaction;
...
...
UserTransaction ut = Transaction.instance();
ut.begin();
...
...
ut.commit();
If you have any idea why this is happening please leave a comment.
UPDATE: Now the first transaction (the one with 100 records) fails. It complains that there is already one transaction active when I try to start a new one. I guess I need to revert my code and to increase the transaction timeout on the weblogic console, this would solve both issues.

Java Tips and Tricks
I got this exception when i tried to define a mail session in WebLogic’s console. I defined the JNDI name to be java:/Mail but it seems that WebLogic does not like the java:/ prefix, so I had to remove it (both from the console and the calling code), and it worked.

Java Tips and Tricks
I got this error when I tried to map a child element by using its parent’s foreign key. I had a parent element with a region id (as foreign key) and I needed to get the child element whose primary key was this region id (and a language id). My child element (Region.hbm.xml) had a composite primary key
<composite-id>
<key-property name="regionCode" type="integer" column="RGNCDE"/>
<key-property name="languageCode" type="integer" column="LNGCDE"/>
</composite-id>
and in my parent I did
<property name="regionCode" column="REGCDE" type="integer"/>
<many-to-one name="region" class="my.package.hbm.Region">
but this resulted in “org.hibernate.MappingException: broken column mapping for” error.
I had to split the child’s composite key
<id name="regionCode" type="integer" column="RGNCDE">
<generator class="assigned"/>
</id>
<property name="languageCode" column="LNGCDE" type="integer"/>
and add a formula property in my parent’s class mapping
<property name="regionCode" column="REGCDE" type="integer"/>
<many-to-one name="region" class="my.package.hbm.Region" formula="REGCDE"/>
so that hibernate could link the region id of the parent to the region id of the child. And since I needed a record based also on the language code (but my parent didn’t have any language code column) I had to manually add search criteria
crit.createCriteria("region").add(Restrictions.eq("languageCode", 1));

Java Tips and Tricks
Let’s say you have a list of duplicate (and non-duplicate) items, and you want a new collection with only the duplicate items in there. The easiest way is to extend the HashSet.
public class DuplicatesOnlySet<E> extends HashSet<E>
{
private final Set<E> uniques = new HashSet<E>();
public DuplicatesOnlySet(Collection<? extends E> c)
{
super.addAll(c);
}
@Override
public boolean add(E e)
{
if(!this.uniques.add(e))
return super.add(e);
return false;
}
}
Call it like
List<String> duplicates = new ArrayList<String>(new DuplicatesOnlySet<String>(original)) ;
where original is the Collection with the duplicate items.
Compliments to Markos for his implementation.

Java Tips and Tricks
This error is related to this post, and is solved by the exact same manner.
1) Edit your application.xml and move the jboss-seam.jar module to the top.
2) Edit each MANIFEST.MF file of the rest of your modules defined in the application.xml and remove the jboss-seam.jar entry.
3) Rebuild and redeploy your ear.

Java Tips and Tricks
I am not sure why I get this error since I can connect to the current SID by using sqlplus but I cannot connect to it by using jdbc with the following url:
jdbc:oracle:thin:@aHost:1521:theSID
After searching for about an hour I found out that you can also use the full blown jdbc url protocol to connect to oracle
jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=aHost) (PORT=1521))(CONNECT_DATA=(SERVICE_NAME=theSID)))
This does not explain why the issue happens but at least for now it solves the problem. I will post an update if I find anything else.

Java Tips and Tricks
Another classloading issue. While jasper reports work fine on JBoss, on WebLogic they fail with the exception
net.sf.jasperreports.engine.JRException: Error loading expression class : MYREPORT_1290416522329_455758
…
Caused by: java.lang.ClassCastException: MYREPORT_1290416522329_455758 cannot be cast to net.sf.jasperreports.engine.fill.JREvaluator
at net.sf.jasperreports.engine.design.JRAbstractJavaCompiler.loadEvaluator(JRAbstractJavaCompiler.java:101)
This is easily resolved. In my configuration it was just a matter of moving my jasper jar file from the root of ear to the WEB-INF/lib folder of my web app, in order to be picked up by a different classloader. If this does not work try moving the jasper jar file around in different locations, one of them will work.

Java Tips and Tricks
Another exception under WebLogic server. This exception occurs because the default query factory class in persistence.xml is the org.hibernate.hql.ast.ASTQueryTranslatorFactory. As the name suggests this is a classpath issue. You might wondering why you get it since you have the hibernate jar file (the file that contains the HqlToken class) in your classpath. The reason is that the weblogic.jar contains a version of antlr.jar which is loaded by a classloader, while the hibernate stuff are loaded by another classloader. So when the server runs it’s using the version of antlr bundled with weblogic which cannot see the hibernate classes. There are two solutions to this problem
1) Use a
<property name="hibernate.query.factory_class" value="org.hibernate.hql.classic.ClassicQueryTranslatorFactory"/>
instead of a
<property name="hibernate.query.factory_class" value="org.hibernate.hql.ast.ASTQueryTranslatorFactory"/>
in your persistence.xml. This will solve the problem but you will have additional issues if you use Enums as parameters to queries (like I do) since I found out the the ClassicQueryTranslatorFactory has problems translating Enum data types to parameters (instead it translates them as bytes, unless you pass the actual value itself and not the Enum object).
2)
Add Hibernate’s antlr jar file as first entry in the classpath (in your startWeblogic script of your domain’s bin folder) and force weblogic to use this instead. I copied it into the common/lib folder and used
set CLASSPATH=%WL_HOME%\common\lib\antlr-2.7.6.jar;%SAVE_CLASSPATH%
There is another solution suggested, to add the following
<prefer-application-packages>
<package-name>antlr.*</package-name>
</prefer-application-packages>
in your weblogic-application.xml, but for some reason this did not work for me.

Java Tips and Tricks