Search code examples
metadatatomcat8spring-4sessionfactoryhibernate-5.x

Migration from Hibernate 3 to Hibernate 5: sessionFactory (MetadataImplementor) is null


    public class EntityMetaData implements SessionFactoryBuilderFactory {

    // private static final ThreadLocal<MetadataImplementor> meta = new ThreadLocal<>();  // previously used, but did not work, so used HashMap

      private static final Map<String, MetadataImplementor> meta = new HashMap<>();
      private static final String METADATAKEY = "M";

    @Override
    public SessionFactoryBuilder getSessionFactoryBuilder(MetadataImplementor metadata, SessionFactoryBuilderImplementor defaultBuilder) {
    //  meta.set(metadata);

        meta.put(METADATAKEY, metadata);
        return defaultBuilder;  
    }

    public static MetadataImplementor getMeta() {
//        return meta.get();

        return meta.get(METADATAKEY);
    }
}

The above code works in tomcat 8 of Local environment, but in tomcat 8 of production environment not working as getMeta() method returns null.

In Local Environment, getSessionFactoryBuilder method is called while server is getting started so that it is working in Local, but in Production environment getSessionFactoryBuilder method not called thus getMeta() returns null.

Any help could be appreciated.

Please help me on this.


Solution

  • Finally I found the answer.

    It's a compiling problem. META-INF folder is not there in classes folder, so metadata is not loading (means getSessionFactoryBuilder method not getting called) during server startup. In Local environment, META-INF is there in classes folder..But in Production environment it is not available, so tried to compile META-INF and available in classes folder, then after it's working.