Wednesday, September 11, 2013

Hibernate scalar types deprecated

In earlier versions of Hibernate, you might have had code that looks like this

session.createSQLQuery("select * from person").addScalar("id", Hibernate.INTEGER)


The fully qualified name of that type is org.hibernate.Hibernate.INTEGER.
That entire type class (org.hibernate.Hibernate) was replaced by org.hibernate.type.StandardBasicTypes.


Thus, your new code should look like this:

session.createSQLQuery("select * from person").addScalar("id", StandardBasicTypes.INTEGER)


Note that the documentation on the JBoss website is outdated depending on which version you are looking at.

For example, documentation for Hibernate 3.3 still says this:
sess.createSQLQuery("SELECT * FROM CATS")
 .addScalar("ID", Hibernate.LONG)

Thursday, January 31, 2013

[CODE] Setting the transaction timeout in EJB 3 using annotations

It's annoyingly hard to find this info online, so here it is:

The timeout annotation is provider specific (weblogic, jboss, etc.).  For example, for Weblogic it is @TransactionTimeoutSeconds(value=40)


http://docs.oracle.com/cd/E16764_01/web.1111/e13720/annotations.htm#i1438354

It's a class annotation, and should be put on the same class you have your javax.ejb.Stateless (or Stateful) EJB.

e.g.

@Stateless(mappedName="myClass")
@TransactionTimeoutSeconds(value=50)
public class MyClass implements ...