回滚无法使用hibernate

时间:2013-04-10 07:43:35

标签: hibernate logback c3p0 hibernate-annotations

我试图在hibernate中使用logback,看起来很简单,但我无法让它工作

的hibernate.cfg.xml

    

    <!-- DB Properties -->
    <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
    <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="hibernate.show_sql">true</property>
    <property name="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
    <property name="hibernate.current_session_context_class">thread</property>

    <!-- DB Connection -->
     <property name="hibernate.connection.url"> XXXXXXXXXXXXX</property>
    <property name="connection.username">XXXXXXXXXX</property>
    <property name="connection.password">XXXXXXXXXX</property>


    <!-- c3p0 config  -->

    <property name="connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>     
    <property name="hibernate.c3p0.acquire_increment">1</property>
    <property name="hibernate.c3p0.idle_test_period">100</property>
    <property name="hibernate.c3p0.min_size">10</property>
    <property name="hibernate.c3p0.max_statements">50</property>
    <property name="hibernate.c3p0.timeout">1800</property>


</session-factory>

logback.xml

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
        <Pattern>%d{yyyy-MM-dd_HH:mm:ss.SSS} %-5level %logger{36} - %msg%n
        </Pattern>
    </encoder>
</appender>

<appender name="FILE"
    class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>c:/timesheet.log</file>
    <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
        <Pattern>%d{yyyy-MM-dd_HH:mm:ss.SSS} [%thread] %-5level %logger{36} -
            %msg%n
        </Pattern>
    </encoder>

    <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
        <FileNamePattern>c:/timesheet.%i.log.zip</FileNamePattern>
        <MinIndex>1</MinIndex>
        <MaxIndex>10</MaxIndex>
    </rollingPolicy>

    <triggeringPolicy
        class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
        <MaxFileSize>2MB</MaxFileSize>
    </triggeringPolicy>

</appender>
<logger name="org.hibernate" level="ALL"/>
<root level="INFO">
    <appender-ref ref="FILE" />
    <appender-ref ref="STDOUT" />
</root>

控制台输出

休眠:选择this_.id_utente如id1_2_3_,this_.valido如valido2_3_,aziendagru2_.id_azienda_gruppo如id1_0_0_,aziendagru2_.logo如logo0_0_,aziendagru2_.nome_azienda如nome3_0_0_,aziendagru2_.sottotitolo_due如sottotit4_0_0_,aziendagru2_.sottotitolo_uno如sottotit5_0_0_,livello3_。 id_livello如id1_3_1_,livello3_.descrizione如descrizi2_3_1_,utentianag4_.id_utente_anagrafica如id1_1_2_,utentianag4_.cognome如cognome1_2_,utentianag4_.nome从ts_utenti nome1_2_ THIS_左外连接ts_aziende_gruppo aziendagru2_上this_.id_azienda_gruppo = aziendagru2_.id_azienda_gruppo左外连接上THIS_ ts_livelli livello3_ .id_livello = livello3_.id_livello left outer join ts_utenti_anagrafica utentianag4_ on this_.id_utente_anagrafica = utentianag4_.id_utente_anagrafica where this_.username =?和this_.password =?

2 个答案:

答案 0 :(得分:1)

你看到的控制台输出是因为你在你的hibernate配置中有这个:

<property name="hibernate.show_sql">true</property>

这告诉hibernate将sql准备好的语句记录到控制台。

很难从你的问题中判断出logback日志记录是否正常工作,但如果它不是here非常好(如果有点过时;只需更新版本号关于启动和运行的教程。

修改

如果上面的教程不起作用,那么很可能你使用的是Hibernate 4版本。

在更高版本的hibernate中,日志框架从slf4j切换到JBoss日志记录。这意味着slf4j不再是Hibernate依赖。

您需要将最新的slf4j JAR添加到类路径中。

答案 1 :(得分:1)

如果要记录所有Hibernate内容(这些内容很多,并且会出现真正的性能问题),请使用TRACE日志级别而不是ALL