关键在于spring的配置
1、applicationcontext.xml
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="com.mysql.jdbc.Driver" />
<property name="jdbcUrl" value="jdbc:mysql://localhost/***?useUnicode=true&characterEncoding=gbk" />
<property name="user" value="root" />
<property name="password" value="mysql" />
<property name="minPoolSize" value="5" />
<property name="maxPoolSize" value="30" />
<property name="initialPoolSize" value="10" />
<property name="maxIdleTime" value="60" />
<property name="acquireIncrement" value="5" />
<property name="maxStatements" value="0" />
<property name="idleConnectionTestPeriod" value="60" />
<property name="acquireRetryAttempts" value="30" />
<property name="breakAfterAcquireFailure" value="true" />
<property name="testConnectionOnCheckout" value="false" />
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="configLocation" value="classpath:hibernate.cfg.xml"/>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
</props>
</property>
</bean>
2、hibernate.cfg.xml
<hibernate-configuration>
<session-factory>
<!-- Show and print nice SQL on stdout -->
<property name="show_sql">false</property>
<property name="format_sql">true</property>
<mapping class="com.model.Host" />
<mapping class="com.model.VmPerf" />
<mapping class="com.model.UspVm" />
</session-factory>
</hibernate-configuration>