applicationContext.xml里的配置如下:
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="com.mysql.jdbc.Driver">
</property>
<property name="url" value="jdbc:mysql://localhost:3306/test"></property>
<property name="username" value="root"></property>
<property name="password" value="admin"></property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">create</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/wenruijie/dao/Users.hbm.xml</value>
</list>
</property>
com/wenruijie/dao/Users.hbm.xml里的配置如下:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
<class name="com.wenruijie.dao.Users" table="usersb" catalog="health">
<id name="id" type="java.lang.String">
<column name="id" />
<generator class="native"></generator>
</id>
<property name="name" type="java.lang.String">
<column name="Name" />
</property>
<property name="password" type="java.lang.String">
<column name="Password" />
</property>
</class>
</hibernate-mapping>
访问时不能自动生成table表,还出现如下错误
org.springframework.dao.InvalidDataAccessResourceUsageException: could not insert: [com.wenruijie.dao.Users]; SQL [insert into health.usersb (Name, Password) values (?, ?)]; nested exception is org.hibernate.exception.SQLGrammarException: could not insert: [com.wenruijie.dao.Users]
org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:629)
org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412)
org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:411)
org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
org.springframework.orm.hibernate3.HibernateTemplate.save(HibernateTemplate.java:683)
com.wenruijie.dao.UsersDaoImp.save(UsersDaoImp.java:22)
com.wenruijie.service.UserServiceImp.addUser(UserServiceImp.java:20)
com.wenruijie.action.UserAction.addUser(UserAction.java:31)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:601)
com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:452)
com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:291)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:254)
com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
到底哪配置错了????
相关解决方案
- hibernate 存入数据库当前时间
- Hibernate 投射文件中length属性无法改变integer字段的默认长度
- Spring MVC开发模式,怎么取得新增的id
- spring 表单对象绑定有关问题 String与Long的转换
- Exception in thread "main" org.hibernate.HibernateException: /hibernate.cfg.xml解决办法
- spring+quartz定时器有关问题
- hibernate DAO中加了局物,未提交
- hibernate 字段lazy 的兑现原理
- Hibernate 的query.list()的有关问题
- Hibernate 关联表字段赋值有关问题
- 零配置的有关问题(struts2+Hibernate)
- spring @Scope("prototype")注解更新有关问题,寻求帮助
- Spring MVC是不是可以完全取代Struts
- spring+quartz的错误,不能正常启动
- hibernate 连接 oracle session 有关问题
- hibernate 中没有做一对多 , 那种关联映射的关联的话如何做连接查询
- spring mvc +ibatis+db2连接数据库的配置如何写啊小弟我链接不下
- spring MVC cvc-complex-type.2.4.c解决方案
- Spring + Mybatis 组合报错
- hibernate 联接mysql出错
- Spring 中 packagesToScan有关问题
- 大神们开始觅错啦!org.hibernate.exception.SQLGrammarException: could not execute query
- Spring MVC中点击旋钮没反应
- spring aop这个跳转异常是咋回事
- spring security3的一个小疑点。加急
- struts2,hibernate,spring3 常用框架的API CHM版本,该怎么处理
- spring 事务 aop transactionManager,该怎么解决
- Spring 事务管理,该怎么处理
- 关于 Spring 声明式事务管理!解决办法
- struts2,hibernate,spring3 惯用框架的API CHM版本