我在我的实体类中使用了hibernate注释,因此我没有使用hibernate.cfg.xml文件,但是当我尝试生成响应时,它抛出了org.hibernate.HibernateException:/hibernate.cfg.xml未找到异常。任何建议??
答案 0 :(得分:0)
我猜这个问题只是对基本的hibernate知识的误解。当您使用Spring Hibernate时,您需要在项目中添加一个必要的hibernate.cfg.xml,您可以在其中添加hibernate ORM连接参数。 这是cfg.xml的基本示例:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.url">jdbc:"database/url/ip/"</property>
<property name="connection.username">"userlog"</property>
<property name="connection.password">"psw"</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="show_sql">false</property>
<property name="format_sql">false</property>
<property name="use_sql_comments">false</property>
<property name="generate_statistics">false</property>
<property name="hbm2ddl.auto">validate</property>
<property name="connection.pool_size">1</property>
<property name="current_session_context_class">thread</property>
<!-- Mapping files will go here.... -->
<mapping resource="xml mapping"/>
<mapping class="class mapping"/>
</session-factory>
</hibernate-configuration>
我希望这很有用。