How to avoid defining each Hibernate mapping in Spring

A better option than defining each mapping resource using the mappingResources property of LocalSessionFactoryBean is using mappingDirectoryLocations with something like the following, only needed once for all the system.

<bean id="sessionFactory">
 <property name="dataSource">
   <ref bean="dataSource">
   <property name="mappingDirectoryLocations">
   <property name="hibernateProperties">
     <ref bean="hibernateProperties">

But be careful, this doesn’t allow you to use classpath locations, they have to be in the filesystem. AFAIK there’s no way to use all mapping files in the classpath under some package, that would be the best solution, e.g. I wanna use all *.hbm.xml in the classpath under net/sf/oness

Enabling transactions in MySQL the easy way

If you want to use transactions (trust me, you want) you have to use InnoDB tables, so add default-table-type=InnoDB to your mysql configuration file (my.cnf or my.ini). This solution is Hibernate friendly.

For example in windows you can use the following my.ini in the windows dir:

# Uncomment the following if you want to log updates
# Uncomment the following if you are NOT using BDB tables
# Uncomment the following if you are using Innobase tables
innodb_data_file_path = ibdata1:20M:autoextend

If you are using a MySQL version previous to 4.0 you should check InnoDB configuration to enable InnoDB.

Does Sun test its webapps?

I was taking a look to the JUG section of and went to the search form . I just clicked the Search button without entering form data and voil! I got an exception, not only telling the system was not througly tested but also that the underlying database is Oracle (see the “ORA” code)
java.sql.SQLException: ORA-00936: missing expression

This made me recall a conference about search engines where I was told that the most searched word was… the empty string! So don’t underestimate user dumbness 😉

Maven ibiblio repository mirrors

There are some mirrors of the main maven repository at ibiblio that you can use for faster

Just change your maven.repo.remote property to any of these.

Spring transactions and Hibernate session

When using Spring transaction proxy org.springframework.transaction.interceptor.TransactionProxyFactoryBean with an Hibernate transaction manager org.springframework.orm.hibernate.HibernateTransactionManager you should know that Hibernate session will be opened at the start of the transaction and closed at the end. Any modification to persistent objects will be flushed to database, so be careful when in service managers (aka business delegates or facades) you touch Hibernate persisted objects. What I’ve done is return clones of them in my DAOs so they can be used as Transfer Objects, changing its state will not change database state.

Be sure that in the TransactionProxyFactoryBean bean definition you add transactionAttributes for every method in the facade or the session will be closed every time a DAO call spring HibernateTemplate.execute method. I forgot this for get* methods and got errors difficult to debug.

Displaying a graph of Spring beans

Mike Thomas has developed SpringGraph a stylesheet to generate a graph from Spring beans in application context.
I took it and developed the maven-springgraph-plugin, check the sample output. I think spring users will find it useful.
The main drawback is the need to install Graphviz, so if anyone knows a Java implementation to make graphs, please tell me.