休眠 - 难以理解的警告

时间:2012-02-07 14:52:32

标签: java hibernate jpa-2.0

我已经构建了一个独立的Java应用程序(批处理),它通过JPA 2使用Hibernate。 它运行正常,但我不断在日志中看到此警告。

我直接用Google搜索并直接阅读了源代码。

WARN    org.hibernate.type.TypeFactory  TypeFactory.java:69     Scoping types to session factory org.hibernate.impl.SessionFactoryImpl@f876ce2 after already scoped org.hibernate.impl.SessionFactoryImpl@3fd7165

我想知道它是什么意思?

2 个答案:

答案 0 :(得分:2)

这是您将会话工厂设置两次(会话工厂已设置)。将日志记录设置为跟踪并查找其中“将类型设置为会话工厂”的位置,然后在某些时候再次设置它,但它似乎不会导致问题,但API在理想情况下看起来像你应该只曾经设置过工厂一次。

答案 1 :(得分:1)

直接来自消息来源:

public final class TypeFactory implements Serializable {
    private static final Logger log = LoggerFactory.getLogger( TypeFactory.class );

    private final TypeScopeImpl typeScope = new TypeScopeImpl();

    public static interface TypeScope extends Serializable {
        public SessionFactoryImplementor resolveFactory();
    }

    private static class TypeScopeImpl implements TypeFactory.TypeScope {
        private SessionFactoryImplementor factory;

        public void injectSessionFactory(SessionFactoryImplementor factory) {
            if ( this.factory != null ) {
                log.warn( "Scoping types to session factory {} after already scoped {}", this.factory, factory );
            }
            else {
                log.trace( "Scoping types to session factory {}", factory );
            }
            this.factory = factory;
        }

...