<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.SQLServerDialect
</prop>
<prop key="hibernate.connection.autocommit">true</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="connection.useUnicode">true</prop>
<prop key="connection.characterEncoding">utf-8</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.order_updates">true</prop>
<prop key="hibernate.connection.release_mode">
after_transaction
</prop>
<prop key="hibernate.hbm2ddl.auto">create</prop>
</props>
</property>
<property name="annotatedClasses">
<list>
<value>entity.User</value>
</list>
</property>
</bean>
public static void main(String[] args) { Configuration config = new Configuration().configure(); SchemaExport export = new SchemaExport(config); export.create(true, true);
}
beans.xml和创建表的类如上
为什么这时候报错是Exception in thread "main" org.hibernate.HibernateException: /hibernate.cfg.xml not found
冰天雪地全裸跪求大大们给点答案
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.SQLServerDialect
</prop>
<prop key="hibernate.connection.autocommit">true</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="connection.useUnicode">true</prop>
<prop key="connection.characterEncoding">utf-8</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.order_updates">true</prop>
<prop key="hibernate.connection.release_mode">
after_transaction
</prop>
<prop key="hibernate.hbm2ddl.auto">create</prop>
</props>
</property>
<property name="annotatedClasses">
<list>
<value>entity.User</value>
</list>
</property>
</bean>
public static void main(String[] args) { Configuration config = new Configuration().configure(); SchemaExport export = new SchemaExport(config); export.create(true, true);
}
beans.xml和创建表的类如上
为什么这时候报错是Exception in thread "main" org.hibernate.HibernateException: /hibernate.cfg.xml not found
冰天雪地全裸跪求大大们给点答案
这个应该是写hibernate与数据库连接的吧,你有吗?每个类也得有个配置文件写相关属性
就不用那个文件了
内容都在bean.xml里面呢
在你bean.xml里根本没发现这些啊、
<bean id="dataSource"
class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="jdbcUrl">
<value>jdbc:mysql://localhost:3306/XXXXX?useUnicode=true&characterEncoding=UTF-8</value>
</property>
<property name="user">
<value>root</value>
</property>
<property name="password">
<value>123456</value>
</property>
</bean>
第二种方法,将包含hibernate.cfg.xml的目录,加到工程的classpath下。
<property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"></property>
<property name="url" value="jdbc:sqlserver://localhost:1433;databasename=mytest1"></property>
<property name="username" value="sa"></property>
<property name="password" value="sa"></property>
<property name="maxActive" value="100"></property>
<property name="maxIdle" value="30"></property>
<property name="maxWait" value="500"></property>
</bean>
你要配置一个 dataSource 啊!!