We have a system where we make use of the HibernateSession and PersistentRootClass patterns. We have a number of Enum type of objects that we initialize from the database, but we are facing a recursion problem during startup.
Here is an example of one of the Enum classes
Code:
public final class EnumType extends PersistentEnum implements Serializable, Comparable
{
public static final EnumType FOO1= EnumType.findByOID( 1 );
public static final EnumType FOO2= EnumType.findByOID( 2 );
public static final EnumType FOO3= EnumType.findByOID( 3 );
...
We create static instances of these enums so that we can grab handles to them easily, but the problem is that when the app starts up, we call a HibernateSession.startup() method which goes out and creates a new Configuration object, and bootstraps Hibernate. During that bootstrap process, hibernate goes and loads the mapped classes (EnumType), which then during class init tries to create these final static instances - but the problem is that the Hibernate startup process hasn't finished yet, so my HibernateSession class which is used inside the findByOID() method is not yet initialized when it is called to load these static class vars (so it tries to recofigure hibernate...)
I know there are different approaches I can take here to resolve this, but was wondering if anyone else had faced this problem and if they came up with a solution that worked well for them.