数据库: Mysql 5.0
创表SQL:
create table `testonline`.`teacher`(
`ID` bigint(13) PRIMARY KEY not null,
`TeacherID` bigint(8) not null,
`TeacherName` varchar(20),
`Password` varchar(20),
`Authory` varchar(1))
Sprint配置文件applicationContext.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="url">
<value>jdbc:mysql://localhost:3306/testonline</value>
</property>
<property name="username">
<value>root</value>
</property>
<property name="password">
<value></value>
</property>
</bean>
<bean id="mySessionFactory" 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>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/hexin/qm4/bean/Teacher.hbm.xml</value>
</list>
</property>
</bean>
7 个解决方案
#1
TeacherDAO用于写数据库:
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
public void save(Teacher transientInstance) {
log.debug("saving Teacher instance");
try {
getHibernateTemplate().saveOrUpdate(transientInstance);
log.debug("save successful");
} catch (RuntimeException re) {
log.error("save failed", re);
throw re;
}
业务处理:TeacherService.java
package com.hexin.qm4.business.impl;
import com.hexin.qm4.bean.Teacher;
import com.hexin.qm4.business.ITeacherService;
import com.hexin.qm4.dao.ITeacherDAO;
public class TeacherService implements ITeacherService {
private ITeacherDAO teacherDAO;
public void saveTeacher(Teacher teacher) {
getTeacherDAO().save(teacher);
}
public ITeacherDAO getTeacherDAO() {
return teacherDAO;
}
public void setTeacherDAO(ITeacherDAO teacherDAO) {
this.teacherDAO = teacherDAO;
}
}
View层上一个Login.jsp,有teacherid, password属性。
struts的LoginAction如下:
public class LoginAction extends BaseAction {
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
LoginForm loginForm = (LoginForm) form;
Teacher teacher = new Teacher();
teacher.setTeacherId(Long.parseLong(loginForm.getTeacherid()));
teacher.setPassword(loginForm.getPassword());
super.getTeacherService().saveTeacher(teacher);
return mapping.findForward("success");
}
}
BaseAction.java如下:
public class BaseAction extends Action {
protected ITeacherService getTeacherService(){
return (ITeacherService)AppContext.getInstance().getAppContext().getBean("teacherService");
}
}
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
public void save(Teacher transientInstance) {
log.debug("saving Teacher instance");
try {
getHibernateTemplate().saveOrUpdate(transientInstance);
log.debug("save successful");
} catch (RuntimeException re) {
log.error("save failed", re);
throw re;
}
业务处理:TeacherService.java
package com.hexin.qm4.business.impl;
import com.hexin.qm4.bean.Teacher;
import com.hexin.qm4.business.ITeacherService;
import com.hexin.qm4.dao.ITeacherDAO;
public class TeacherService implements ITeacherService {
private ITeacherDAO teacherDAO;
public void saveTeacher(Teacher teacher) {
getTeacherDAO().save(teacher);
}
public ITeacherDAO getTeacherDAO() {
return teacherDAO;
}
public void setTeacherDAO(ITeacherDAO teacherDAO) {
this.teacherDAO = teacherDAO;
}
}
View层上一个Login.jsp,有teacherid, password属性。
struts的LoginAction如下:
public class LoginAction extends BaseAction {
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
LoginForm loginForm = (LoginForm) form;
Teacher teacher = new Teacher();
teacher.setTeacherId(Long.parseLong(loginForm.getTeacherid()));
teacher.setPassword(loginForm.getPassword());
super.getTeacherService().saveTeacher(teacher);
return mapping.findForward("success");
}
}
BaseAction.java如下:
public class BaseAction extends Action {
protected ITeacherService getTeacherService(){
return (ITeacherService)AppContext.getInstance().getAppContext().getBean("teacherService");
}
}
#2
现在在Jsp页面中按submit,我想把数据存到数据中,老是出现下面的异常:
信息: Server startup in 22141 ms
2006-02-08 16:31:49,671 [org.springframework.beans.factory.xml.XmlBeanDefinitionReader]-[INFO] Loading XML bean definitions from class path resource [applicationContext.xml]
2006-02-08 16:31:50,562 [org.springframework.context.support.ClassPathXmlApplicationContext]-[INFO] Bean factory for application context [org.springframework.context.support.ClassPathXmlApplicationContext;hashCode=9550256]: org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans [dataSource,mySessionFactory,transactionManager,teacherDAO,teacherService]; root of BeanFactory hierarchy
2006-02-08 16:31:50,609 [org.springframework.context.support.ClassPathXmlApplicationContext]-[INFO] 5 beans defined in application context [org.springframework.context.support.ClassPathXmlApplicationContext;hashCode=9550256]
2006-02-08 16:31:50,671 [org.springframework.core.CollectionFactory]-[INFO] JDK 1.4+ collections available
2006-02-08 16:31:50,765 [org.springframework.core.CollectionFactory]-[INFO] Commons Collections 3.x available
2006-02-08 16:31:50,796 [org.springframework.context.support.ClassPathXmlApplicationContext]-[INFO] Unable to locate MessageSource with name 'messageSource': using default [org.springframework.context.support.DelegatingMessageSource@1eb1db2]
2006-02-08 16:31:50,796 [org.springframework.context.support.ClassPathXmlApplicationContext]-[INFO] Unable to locate ApplicationEventMulticaster with name 'applicationEventMulticaster': using default [org.springframework.context.event.SimpleApplicationEventMulticaster@779959]
2006-02-08 16:31:50,812 [org.springframework.beans.factory.support.DefaultListableBeanFactory]-[INFO] Pre-instantiating singletons in factory [org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans [dataSource,mySessionFactory,transactionManager,teacherDAO,teacherService]; root of BeanFactory hierarchy]
2006-02-08 16:31:51,281 [org.hibernate.cfg.Environment]-[INFO] Hibernate 3.0.5
2006-02-08 16:31:51,296 [org.hibernate.cfg.Environment]-[INFO] hibernate.properties not found
2006-02-08 16:31:51,312 [org.hibernate.cfg.Environment]-[INFO] using CGLIB reflection optimizer
2006-02-08 16:31:51,328 [org.hibernate.cfg.Environment]-[INFO] using JDK 1.4 java.sql.Timestamp handling
2006-02-08 16:31:52,656 [org.hibernate.cfg.HbmBinder]-[INFO] Mapping class: com.hexin.qm4.bean.Teacher -> teacher
2006-02-08 16:31:52,750 [org.springframework.orm.hibernate3.LocalSessionFactoryBean]-[INFO] Building new Hibernate SessionFactory
2006-02-08 16:31:52,750 [org.hibernate.cfg.Configuration]-[INFO] processing extends queue
2006-02-08 16:31:52,750 [org.hibernate.cfg.Configuration]-[INFO] processing collection mappings
2006-02-08 16:31:52,750 [org.hibernate.cfg.Configuration]-[INFO] processing association property references
信息: Server startup in 22141 ms
2006-02-08 16:31:49,671 [org.springframework.beans.factory.xml.XmlBeanDefinitionReader]-[INFO] Loading XML bean definitions from class path resource [applicationContext.xml]
2006-02-08 16:31:50,562 [org.springframework.context.support.ClassPathXmlApplicationContext]-[INFO] Bean factory for application context [org.springframework.context.support.ClassPathXmlApplicationContext;hashCode=9550256]: org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans [dataSource,mySessionFactory,transactionManager,teacherDAO,teacherService]; root of BeanFactory hierarchy
2006-02-08 16:31:50,609 [org.springframework.context.support.ClassPathXmlApplicationContext]-[INFO] 5 beans defined in application context [org.springframework.context.support.ClassPathXmlApplicationContext;hashCode=9550256]
2006-02-08 16:31:50,671 [org.springframework.core.CollectionFactory]-[INFO] JDK 1.4+ collections available
2006-02-08 16:31:50,765 [org.springframework.core.CollectionFactory]-[INFO] Commons Collections 3.x available
2006-02-08 16:31:50,796 [org.springframework.context.support.ClassPathXmlApplicationContext]-[INFO] Unable to locate MessageSource with name 'messageSource': using default [org.springframework.context.support.DelegatingMessageSource@1eb1db2]
2006-02-08 16:31:50,796 [org.springframework.context.support.ClassPathXmlApplicationContext]-[INFO] Unable to locate ApplicationEventMulticaster with name 'applicationEventMulticaster': using default [org.springframework.context.event.SimpleApplicationEventMulticaster@779959]
2006-02-08 16:31:50,812 [org.springframework.beans.factory.support.DefaultListableBeanFactory]-[INFO] Pre-instantiating singletons in factory [org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans [dataSource,mySessionFactory,transactionManager,teacherDAO,teacherService]; root of BeanFactory hierarchy]
2006-02-08 16:31:51,281 [org.hibernate.cfg.Environment]-[INFO] Hibernate 3.0.5
2006-02-08 16:31:51,296 [org.hibernate.cfg.Environment]-[INFO] hibernate.properties not found
2006-02-08 16:31:51,312 [org.hibernate.cfg.Environment]-[INFO] using CGLIB reflection optimizer
2006-02-08 16:31:51,328 [org.hibernate.cfg.Environment]-[INFO] using JDK 1.4 java.sql.Timestamp handling
2006-02-08 16:31:52,656 [org.hibernate.cfg.HbmBinder]-[INFO] Mapping class: com.hexin.qm4.bean.Teacher -> teacher
2006-02-08 16:31:52,750 [org.springframework.orm.hibernate3.LocalSessionFactoryBean]-[INFO] Building new Hibernate SessionFactory
2006-02-08 16:31:52,750 [org.hibernate.cfg.Configuration]-[INFO] processing extends queue
2006-02-08 16:31:52,750 [org.hibernate.cfg.Configuration]-[INFO] processing collection mappings
2006-02-08 16:31:52,750 [org.hibernate.cfg.Configuration]-[INFO] processing association property references
#3
2006-02-08 16:31:52,750 [org.hibernate.cfg.Configuration]-[INFO] processing foreign key constraints
2006-02-08 16:31:53,281 [org.hibernate.connection.ConnectionProviderFactory]-[INFO] Initializing connection provider: org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider
2006-02-08 16:31:54,187 [org.hibernate.cfg.SettingsFactory]-[INFO] RDBMS: MySQL, version: 5.0.18-nt
2006-02-08 16:31:54,187 [org.hibernate.cfg.SettingsFactory]-[INFO] JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-3.1.12 ( $Date: 2005-11-17 15:53:48 +0100 (Thu, 17 Nov 2005) $, $Revision$ )
2006-02-08 16:31:54,312 [org.hibernate.dialect.Dialect]-[INFO] Using dialect: org.hibernate.dialect.MySQLDialect
2006-02-08 16:31:54,343 [org.hibernate.transaction.TransactionFactoryFactory]-[INFO] Using default transaction strategy (direct JDBC transactions)
2006-02-08 16:31:54,343 [org.hibernate.transaction.TransactionManagerLookupFactory]-[INFO] No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
2006-02-08 16:31:54,343 [org.hibernate.cfg.SettingsFactory]-[INFO] Automatic flush during beforeCompletion(): disabled
2006-02-08 16:31:54,343 [org.hibernate.cfg.SettingsFactory]-[INFO] Automatic session close at end of transaction: disabled
2006-02-08 16:31:54,343 [org.hibernate.cfg.SettingsFactory]-[INFO] JDBC batch size: 15
2006-02-08 16:31:54,343 [org.hibernate.cfg.SettingsFactory]-[INFO] JDBC batch updates for versioned data: disabled
2006-02-08 16:31:54,375 [org.hibernate.cfg.SettingsFactory]-[INFO] Scrollable result sets: enabled
2006-02-08 16:31:54,375 [org.hibernate.cfg.SettingsFactory]-[INFO] JDBC3 getGeneratedKeys(): enabled
2006-02-08 16:31:54,375 [org.hibernate.cfg.SettingsFactory]-[INFO] Connection release mode: on_close
2006-02-08 16:31:54,375 [org.hibernate.cfg.SettingsFactory]-[INFO] Maximum outer join fetch depth: 2
2006-02-08 16:31:54,375 [org.hibernate.cfg.SettingsFactory]-[INFO] Default batch fetch size: 1
2006-02-08 16:31:54,375 [org.hibernate.cfg.SettingsFactory]-[INFO] Generate SQL with comments: disabled
2006-02-08 16:31:54,375 [org.hibernate.cfg.SettingsFactory]-[INFO] Order SQL updates by primary key: disabled
2006-02-08 16:31:54,375 [org.hibernate.cfg.SettingsFactory]-[INFO] Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
2006-02-08 16:31:54,406 [org.hibernate.hql.ast.ASTQueryTranslatorFactory]-[INFO] Using ASTQueryTranslatorFactory
2006-02-08 16:31:54,406 [org.hibernate.cfg.SettingsFactory]-[INFO] Query language substitutions: {}
2006-02-08 16:31:54,406 [org.hibernate.cfg.SettingsFactory]-[INFO] Second-level cache: enabled
2006-02-08 16:31:54,406 [org.hibernate.cfg.SettingsFactory]-[INFO] Query cache: disabled
2006-02-08 16:31:54,406 [org.hibernate.cfg.SettingsFactory]-[INFO] Cache provider: org.hibernate.cache.EhCacheProvider
2006-02-08 16:31:54,421 [org.hibernate.cfg.SettingsFactory]-[INFO] Optimize cache for minimal puts: disabled
2006-02-08 16:31:54,437 [org.hibernate.cfg.SettingsFactory]-[INFO] Structured second-level cache entries: disabled
2006-02-08 16:31:54,484 [org.hibernate.cfg.SettingsFactory]-[INFO] Statistics: disabled
2006-02-08 16:31:54,484 [org.hibernate.cfg.SettingsFactory]-[INFO] Deleted entity synthetic identifier rollback: disabled
2006-02-08 16:31:54,484 [org.hibernate.cfg.SettingsFactory]-[INFO] Default entity-mode: pojo
2006-02-08 16:31:55,000 [org.hibernate.impl.SessionFactoryImpl]-[INFO] building session factory
2006-02-08 16:31:55,031 [net.sf.ehcache.config.Configurator]-[WARN] No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/I:/Tomcat%205.5/webapps/Qm4/WEB-INF/lib/ehcache-1.1.jar!/ehcache-failsafe.xml
2006-02-08 16:31:56,468 [org.hibernate.impl.SessionFactoryObjectFactory]-[INFO] Not binding factory to JNDI, no JNDI name configured
2006-02-08 16:31:56,468 [org.hibernate.impl.SessionFactoryImpl]-[INFO] Checking 0 named queries
2006-02-08 16:31:56,656 [org.springframework.orm.hibernate3.HibernateTransactionManager]-[INFO] Using DataSource [org.apache.commons.dbcp.BasicDataSource@1e8614a] of Hibernate SessionFactory for HibernateTransactionManager
2006-02-08 16:31:56,781 [org.springframework.beans.factory.xml.XmlBeanDefinitionReader]-[INFO] Loading XML bean definitions from class path resource [org/springframework/jdbc/support/sql-error-codes.xml]
2006-02-08 16:31:56,859 [org.springframework.jdbc.support.SQLErrorCodesFactory]-[INFO] SQLErrorCodes loaded: [DB2, HSQL, MS-SQL, MySQL, Oracle, Informix, PostgreSQL, Sybase]
2006-02-08 16:31:57,234 [org.hibernate.util.JDBCExceptionReporter]-[WARN] SQL Error: 1146, SQLState: 42S02
2006-02-08 16:31:57,234 [org.hibernate.util.JDBCExceptionReporter]-[ERROR] Table 'testonline.testonline__teacher' doesn't exist
2006-02-08 16:31:57,250 [com.hexin.qm4.dao.impl.TeacherDAO]-[ERROR] save failed
org.springframework.jdbc.BadSqlGrammarException: Hibernate operation: could not insert: [com.hexin.qm4.bean.Teacher]; bad SQL grammar [insert into testonline__teacher (TeacherID, TeacherName, Password, Authory) values (?, ?, ?, ?)]; nested exception is java.sql.SQLException: Table 'testonline.testonline__teacher' doesn't exist
java.sql.SQLException: Table 'testonline.testonline__teacher' doesn't exist
2006-02-08 16:31:53,281 [org.hibernate.connection.ConnectionProviderFactory]-[INFO] Initializing connection provider: org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider
2006-02-08 16:31:54,187 [org.hibernate.cfg.SettingsFactory]-[INFO] RDBMS: MySQL, version: 5.0.18-nt
2006-02-08 16:31:54,187 [org.hibernate.cfg.SettingsFactory]-[INFO] JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-3.1.12 ( $Date: 2005-11-17 15:53:48 +0100 (Thu, 17 Nov 2005) $, $Revision$ )
2006-02-08 16:31:54,312 [org.hibernate.dialect.Dialect]-[INFO] Using dialect: org.hibernate.dialect.MySQLDialect
2006-02-08 16:31:54,343 [org.hibernate.transaction.TransactionFactoryFactory]-[INFO] Using default transaction strategy (direct JDBC transactions)
2006-02-08 16:31:54,343 [org.hibernate.transaction.TransactionManagerLookupFactory]-[INFO] No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
2006-02-08 16:31:54,343 [org.hibernate.cfg.SettingsFactory]-[INFO] Automatic flush during beforeCompletion(): disabled
2006-02-08 16:31:54,343 [org.hibernate.cfg.SettingsFactory]-[INFO] Automatic session close at end of transaction: disabled
2006-02-08 16:31:54,343 [org.hibernate.cfg.SettingsFactory]-[INFO] JDBC batch size: 15
2006-02-08 16:31:54,343 [org.hibernate.cfg.SettingsFactory]-[INFO] JDBC batch updates for versioned data: disabled
2006-02-08 16:31:54,375 [org.hibernate.cfg.SettingsFactory]-[INFO] Scrollable result sets: enabled
2006-02-08 16:31:54,375 [org.hibernate.cfg.SettingsFactory]-[INFO] JDBC3 getGeneratedKeys(): enabled
2006-02-08 16:31:54,375 [org.hibernate.cfg.SettingsFactory]-[INFO] Connection release mode: on_close
2006-02-08 16:31:54,375 [org.hibernate.cfg.SettingsFactory]-[INFO] Maximum outer join fetch depth: 2
2006-02-08 16:31:54,375 [org.hibernate.cfg.SettingsFactory]-[INFO] Default batch fetch size: 1
2006-02-08 16:31:54,375 [org.hibernate.cfg.SettingsFactory]-[INFO] Generate SQL with comments: disabled
2006-02-08 16:31:54,375 [org.hibernate.cfg.SettingsFactory]-[INFO] Order SQL updates by primary key: disabled
2006-02-08 16:31:54,375 [org.hibernate.cfg.SettingsFactory]-[INFO] Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
2006-02-08 16:31:54,406 [org.hibernate.hql.ast.ASTQueryTranslatorFactory]-[INFO] Using ASTQueryTranslatorFactory
2006-02-08 16:31:54,406 [org.hibernate.cfg.SettingsFactory]-[INFO] Query language substitutions: {}
2006-02-08 16:31:54,406 [org.hibernate.cfg.SettingsFactory]-[INFO] Second-level cache: enabled
2006-02-08 16:31:54,406 [org.hibernate.cfg.SettingsFactory]-[INFO] Query cache: disabled
2006-02-08 16:31:54,406 [org.hibernate.cfg.SettingsFactory]-[INFO] Cache provider: org.hibernate.cache.EhCacheProvider
2006-02-08 16:31:54,421 [org.hibernate.cfg.SettingsFactory]-[INFO] Optimize cache for minimal puts: disabled
2006-02-08 16:31:54,437 [org.hibernate.cfg.SettingsFactory]-[INFO] Structured second-level cache entries: disabled
2006-02-08 16:31:54,484 [org.hibernate.cfg.SettingsFactory]-[INFO] Statistics: disabled
2006-02-08 16:31:54,484 [org.hibernate.cfg.SettingsFactory]-[INFO] Deleted entity synthetic identifier rollback: disabled
2006-02-08 16:31:54,484 [org.hibernate.cfg.SettingsFactory]-[INFO] Default entity-mode: pojo
2006-02-08 16:31:55,000 [org.hibernate.impl.SessionFactoryImpl]-[INFO] building session factory
2006-02-08 16:31:55,031 [net.sf.ehcache.config.Configurator]-[WARN] No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/I:/Tomcat%205.5/webapps/Qm4/WEB-INF/lib/ehcache-1.1.jar!/ehcache-failsafe.xml
2006-02-08 16:31:56,468 [org.hibernate.impl.SessionFactoryObjectFactory]-[INFO] Not binding factory to JNDI, no JNDI name configured
2006-02-08 16:31:56,468 [org.hibernate.impl.SessionFactoryImpl]-[INFO] Checking 0 named queries
2006-02-08 16:31:56,656 [org.springframework.orm.hibernate3.HibernateTransactionManager]-[INFO] Using DataSource [org.apache.commons.dbcp.BasicDataSource@1e8614a] of Hibernate SessionFactory for HibernateTransactionManager
2006-02-08 16:31:56,781 [org.springframework.beans.factory.xml.XmlBeanDefinitionReader]-[INFO] Loading XML bean definitions from class path resource [org/springframework/jdbc/support/sql-error-codes.xml]
2006-02-08 16:31:56,859 [org.springframework.jdbc.support.SQLErrorCodesFactory]-[INFO] SQLErrorCodes loaded: [DB2, HSQL, MS-SQL, MySQL, Oracle, Informix, PostgreSQL, Sybase]
2006-02-08 16:31:57,234 [org.hibernate.util.JDBCExceptionReporter]-[WARN] SQL Error: 1146, SQLState: 42S02
2006-02-08 16:31:57,234 [org.hibernate.util.JDBCExceptionReporter]-[ERROR] Table 'testonline.testonline__teacher' doesn't exist
2006-02-08 16:31:57,250 [com.hexin.qm4.dao.impl.TeacherDAO]-[ERROR] save failed
org.springframework.jdbc.BadSqlGrammarException: Hibernate operation: could not insert: [com.hexin.qm4.bean.Teacher]; bad SQL grammar [insert into testonline__teacher (TeacherID, TeacherName, Password, Authory) values (?, ?, ?, ?)]; nested exception is java.sql.SQLException: Table 'testonline.testonline__teacher' doesn't exist
java.sql.SQLException: Table 'testonline.testonline__teacher' doesn't exist
#4
表名应该和hibernate里的那个对应的xml文件名相同才可以
#5
2006-02-08 16:31:52,656 [org.hibernate.cfg.HbmBinder]-[INFO] Mapping class: com.hexin.qm4.bean.Teacher -> teacher
应该已经可以的啊
应该已经可以的啊
#6
我的表明明是testonline.teacher,怎么这里出现的是'testonline.testonline__teacher' 啊?
Table 'testonline.testonline__teacher' doesn't exist,达人相救!
Table 'testonline.testonline__teacher' doesn't exist,达人相救!
#7
applicationContext.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="url">
<value>jdbc:mysql://localhost:3306/testonline</value>
</property>
<property name="username">
<value>root</value>
</property>
<property name="password">
<value>todobetter</value>
</property>
</bean>
<bean id="mySessionFactory" 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>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/hexin/qm4/bean/Teacher.hbm.xml</value>
</list>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="mySessionFactory" />
</property>
</bean>
<bean id="teacherDAO" class="com.hexin.qm4.dao.impl.TeacherDAO">
<property name="sessionFactory">
<ref bean="mySessionFactory" />
</property>
</bean>
<bean id="teacherService" class="com.hexin.qm4.business.impl.TeacherService">
<property name="teacherDAO">
<ref local="teacherDAO"/>
</property>
</bean>
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="url">
<value>jdbc:mysql://localhost:3306/testonline</value>
</property>
<property name="username">
<value>root</value>
</property>
<property name="password">
<value>todobetter</value>
</property>
</bean>
<bean id="mySessionFactory" 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>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/hexin/qm4/bean/Teacher.hbm.xml</value>
</list>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="mySessionFactory" />
</property>
</bean>
<bean id="teacherDAO" class="com.hexin.qm4.dao.impl.TeacherDAO">
<property name="sessionFactory">
<ref bean="mySessionFactory" />
</property>
</bean>
<bean id="teacherService" class="com.hexin.qm4.business.impl.TeacherService">
<property name="teacherDAO">
<ref local="teacherDAO"/>
</property>
</bean>
</beans>
#1
TeacherDAO用于写数据库:
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
public void save(Teacher transientInstance) {
log.debug("saving Teacher instance");
try {
getHibernateTemplate().saveOrUpdate(transientInstance);
log.debug("save successful");
} catch (RuntimeException re) {
log.error("save failed", re);
throw re;
}
业务处理:TeacherService.java
package com.hexin.qm4.business.impl;
import com.hexin.qm4.bean.Teacher;
import com.hexin.qm4.business.ITeacherService;
import com.hexin.qm4.dao.ITeacherDAO;
public class TeacherService implements ITeacherService {
private ITeacherDAO teacherDAO;
public void saveTeacher(Teacher teacher) {
getTeacherDAO().save(teacher);
}
public ITeacherDAO getTeacherDAO() {
return teacherDAO;
}
public void setTeacherDAO(ITeacherDAO teacherDAO) {
this.teacherDAO = teacherDAO;
}
}
View层上一个Login.jsp,有teacherid, password属性。
struts的LoginAction如下:
public class LoginAction extends BaseAction {
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
LoginForm loginForm = (LoginForm) form;
Teacher teacher = new Teacher();
teacher.setTeacherId(Long.parseLong(loginForm.getTeacherid()));
teacher.setPassword(loginForm.getPassword());
super.getTeacherService().saveTeacher(teacher);
return mapping.findForward("success");
}
}
BaseAction.java如下:
public class BaseAction extends Action {
protected ITeacherService getTeacherService(){
return (ITeacherService)AppContext.getInstance().getAppContext().getBean("teacherService");
}
}
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
public void save(Teacher transientInstance) {
log.debug("saving Teacher instance");
try {
getHibernateTemplate().saveOrUpdate(transientInstance);
log.debug("save successful");
} catch (RuntimeException re) {
log.error("save failed", re);
throw re;
}
业务处理:TeacherService.java
package com.hexin.qm4.business.impl;
import com.hexin.qm4.bean.Teacher;
import com.hexin.qm4.business.ITeacherService;
import com.hexin.qm4.dao.ITeacherDAO;
public class TeacherService implements ITeacherService {
private ITeacherDAO teacherDAO;
public void saveTeacher(Teacher teacher) {
getTeacherDAO().save(teacher);
}
public ITeacherDAO getTeacherDAO() {
return teacherDAO;
}
public void setTeacherDAO(ITeacherDAO teacherDAO) {
this.teacherDAO = teacherDAO;
}
}
View层上一个Login.jsp,有teacherid, password属性。
struts的LoginAction如下:
public class LoginAction extends BaseAction {
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
LoginForm loginForm = (LoginForm) form;
Teacher teacher = new Teacher();
teacher.setTeacherId(Long.parseLong(loginForm.getTeacherid()));
teacher.setPassword(loginForm.getPassword());
super.getTeacherService().saveTeacher(teacher);
return mapping.findForward("success");
}
}
BaseAction.java如下:
public class BaseAction extends Action {
protected ITeacherService getTeacherService(){
return (ITeacherService)AppContext.getInstance().getAppContext().getBean("teacherService");
}
}
#2
现在在Jsp页面中按submit,我想把数据存到数据中,老是出现下面的异常:
信息: Server startup in 22141 ms
2006-02-08 16:31:49,671 [org.springframework.beans.factory.xml.XmlBeanDefinitionReader]-[INFO] Loading XML bean definitions from class path resource [applicationContext.xml]
2006-02-08 16:31:50,562 [org.springframework.context.support.ClassPathXmlApplicationContext]-[INFO] Bean factory for application context [org.springframework.context.support.ClassPathXmlApplicationContext;hashCode=9550256]: org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans [dataSource,mySessionFactory,transactionManager,teacherDAO,teacherService]; root of BeanFactory hierarchy
2006-02-08 16:31:50,609 [org.springframework.context.support.ClassPathXmlApplicationContext]-[INFO] 5 beans defined in application context [org.springframework.context.support.ClassPathXmlApplicationContext;hashCode=9550256]
2006-02-08 16:31:50,671 [org.springframework.core.CollectionFactory]-[INFO] JDK 1.4+ collections available
2006-02-08 16:31:50,765 [org.springframework.core.CollectionFactory]-[INFO] Commons Collections 3.x available
2006-02-08 16:31:50,796 [org.springframework.context.support.ClassPathXmlApplicationContext]-[INFO] Unable to locate MessageSource with name 'messageSource': using default [org.springframework.context.support.DelegatingMessageSource@1eb1db2]
2006-02-08 16:31:50,796 [org.springframework.context.support.ClassPathXmlApplicationContext]-[INFO] Unable to locate ApplicationEventMulticaster with name 'applicationEventMulticaster': using default [org.springframework.context.event.SimpleApplicationEventMulticaster@779959]
2006-02-08 16:31:50,812 [org.springframework.beans.factory.support.DefaultListableBeanFactory]-[INFO] Pre-instantiating singletons in factory [org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans [dataSource,mySessionFactory,transactionManager,teacherDAO,teacherService]; root of BeanFactory hierarchy]
2006-02-08 16:31:51,281 [org.hibernate.cfg.Environment]-[INFO] Hibernate 3.0.5
2006-02-08 16:31:51,296 [org.hibernate.cfg.Environment]-[INFO] hibernate.properties not found
2006-02-08 16:31:51,312 [org.hibernate.cfg.Environment]-[INFO] using CGLIB reflection optimizer
2006-02-08 16:31:51,328 [org.hibernate.cfg.Environment]-[INFO] using JDK 1.4 java.sql.Timestamp handling
2006-02-08 16:31:52,656 [org.hibernate.cfg.HbmBinder]-[INFO] Mapping class: com.hexin.qm4.bean.Teacher -> teacher
2006-02-08 16:31:52,750 [org.springframework.orm.hibernate3.LocalSessionFactoryBean]-[INFO] Building new Hibernate SessionFactory
2006-02-08 16:31:52,750 [org.hibernate.cfg.Configuration]-[INFO] processing extends queue
2006-02-08 16:31:52,750 [org.hibernate.cfg.Configuration]-[INFO] processing collection mappings
2006-02-08 16:31:52,750 [org.hibernate.cfg.Configuration]-[INFO] processing association property references
信息: Server startup in 22141 ms
2006-02-08 16:31:49,671 [org.springframework.beans.factory.xml.XmlBeanDefinitionReader]-[INFO] Loading XML bean definitions from class path resource [applicationContext.xml]
2006-02-08 16:31:50,562 [org.springframework.context.support.ClassPathXmlApplicationContext]-[INFO] Bean factory for application context [org.springframework.context.support.ClassPathXmlApplicationContext;hashCode=9550256]: org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans [dataSource,mySessionFactory,transactionManager,teacherDAO,teacherService]; root of BeanFactory hierarchy
2006-02-08 16:31:50,609 [org.springframework.context.support.ClassPathXmlApplicationContext]-[INFO] 5 beans defined in application context [org.springframework.context.support.ClassPathXmlApplicationContext;hashCode=9550256]
2006-02-08 16:31:50,671 [org.springframework.core.CollectionFactory]-[INFO] JDK 1.4+ collections available
2006-02-08 16:31:50,765 [org.springframework.core.CollectionFactory]-[INFO] Commons Collections 3.x available
2006-02-08 16:31:50,796 [org.springframework.context.support.ClassPathXmlApplicationContext]-[INFO] Unable to locate MessageSource with name 'messageSource': using default [org.springframework.context.support.DelegatingMessageSource@1eb1db2]
2006-02-08 16:31:50,796 [org.springframework.context.support.ClassPathXmlApplicationContext]-[INFO] Unable to locate ApplicationEventMulticaster with name 'applicationEventMulticaster': using default [org.springframework.context.event.SimpleApplicationEventMulticaster@779959]
2006-02-08 16:31:50,812 [org.springframework.beans.factory.support.DefaultListableBeanFactory]-[INFO] Pre-instantiating singletons in factory [org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans [dataSource,mySessionFactory,transactionManager,teacherDAO,teacherService]; root of BeanFactory hierarchy]
2006-02-08 16:31:51,281 [org.hibernate.cfg.Environment]-[INFO] Hibernate 3.0.5
2006-02-08 16:31:51,296 [org.hibernate.cfg.Environment]-[INFO] hibernate.properties not found
2006-02-08 16:31:51,312 [org.hibernate.cfg.Environment]-[INFO] using CGLIB reflection optimizer
2006-02-08 16:31:51,328 [org.hibernate.cfg.Environment]-[INFO] using JDK 1.4 java.sql.Timestamp handling
2006-02-08 16:31:52,656 [org.hibernate.cfg.HbmBinder]-[INFO] Mapping class: com.hexin.qm4.bean.Teacher -> teacher
2006-02-08 16:31:52,750 [org.springframework.orm.hibernate3.LocalSessionFactoryBean]-[INFO] Building new Hibernate SessionFactory
2006-02-08 16:31:52,750 [org.hibernate.cfg.Configuration]-[INFO] processing extends queue
2006-02-08 16:31:52,750 [org.hibernate.cfg.Configuration]-[INFO] processing collection mappings
2006-02-08 16:31:52,750 [org.hibernate.cfg.Configuration]-[INFO] processing association property references
#3
2006-02-08 16:31:52,750 [org.hibernate.cfg.Configuration]-[INFO] processing foreign key constraints
2006-02-08 16:31:53,281 [org.hibernate.connection.ConnectionProviderFactory]-[INFO] Initializing connection provider: org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider
2006-02-08 16:31:54,187 [org.hibernate.cfg.SettingsFactory]-[INFO] RDBMS: MySQL, version: 5.0.18-nt
2006-02-08 16:31:54,187 [org.hibernate.cfg.SettingsFactory]-[INFO] JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-3.1.12 ( $Date: 2005-11-17 15:53:48 +0100 (Thu, 17 Nov 2005) $, $Revision$ )
2006-02-08 16:31:54,312 [org.hibernate.dialect.Dialect]-[INFO] Using dialect: org.hibernate.dialect.MySQLDialect
2006-02-08 16:31:54,343 [org.hibernate.transaction.TransactionFactoryFactory]-[INFO] Using default transaction strategy (direct JDBC transactions)
2006-02-08 16:31:54,343 [org.hibernate.transaction.TransactionManagerLookupFactory]-[INFO] No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
2006-02-08 16:31:54,343 [org.hibernate.cfg.SettingsFactory]-[INFO] Automatic flush during beforeCompletion(): disabled
2006-02-08 16:31:54,343 [org.hibernate.cfg.SettingsFactory]-[INFO] Automatic session close at end of transaction: disabled
2006-02-08 16:31:54,343 [org.hibernate.cfg.SettingsFactory]-[INFO] JDBC batch size: 15
2006-02-08 16:31:54,343 [org.hibernate.cfg.SettingsFactory]-[INFO] JDBC batch updates for versioned data: disabled
2006-02-08 16:31:54,375 [org.hibernate.cfg.SettingsFactory]-[INFO] Scrollable result sets: enabled
2006-02-08 16:31:54,375 [org.hibernate.cfg.SettingsFactory]-[INFO] JDBC3 getGeneratedKeys(): enabled
2006-02-08 16:31:54,375 [org.hibernate.cfg.SettingsFactory]-[INFO] Connection release mode: on_close
2006-02-08 16:31:54,375 [org.hibernate.cfg.SettingsFactory]-[INFO] Maximum outer join fetch depth: 2
2006-02-08 16:31:54,375 [org.hibernate.cfg.SettingsFactory]-[INFO] Default batch fetch size: 1
2006-02-08 16:31:54,375 [org.hibernate.cfg.SettingsFactory]-[INFO] Generate SQL with comments: disabled
2006-02-08 16:31:54,375 [org.hibernate.cfg.SettingsFactory]-[INFO] Order SQL updates by primary key: disabled
2006-02-08 16:31:54,375 [org.hibernate.cfg.SettingsFactory]-[INFO] Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
2006-02-08 16:31:54,406 [org.hibernate.hql.ast.ASTQueryTranslatorFactory]-[INFO] Using ASTQueryTranslatorFactory
2006-02-08 16:31:54,406 [org.hibernate.cfg.SettingsFactory]-[INFO] Query language substitutions: {}
2006-02-08 16:31:54,406 [org.hibernate.cfg.SettingsFactory]-[INFO] Second-level cache: enabled
2006-02-08 16:31:54,406 [org.hibernate.cfg.SettingsFactory]-[INFO] Query cache: disabled
2006-02-08 16:31:54,406 [org.hibernate.cfg.SettingsFactory]-[INFO] Cache provider: org.hibernate.cache.EhCacheProvider
2006-02-08 16:31:54,421 [org.hibernate.cfg.SettingsFactory]-[INFO] Optimize cache for minimal puts: disabled
2006-02-08 16:31:54,437 [org.hibernate.cfg.SettingsFactory]-[INFO] Structured second-level cache entries: disabled
2006-02-08 16:31:54,484 [org.hibernate.cfg.SettingsFactory]-[INFO] Statistics: disabled
2006-02-08 16:31:54,484 [org.hibernate.cfg.SettingsFactory]-[INFO] Deleted entity synthetic identifier rollback: disabled
2006-02-08 16:31:54,484 [org.hibernate.cfg.SettingsFactory]-[INFO] Default entity-mode: pojo
2006-02-08 16:31:55,000 [org.hibernate.impl.SessionFactoryImpl]-[INFO] building session factory
2006-02-08 16:31:55,031 [net.sf.ehcache.config.Configurator]-[WARN] No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/I:/Tomcat%205.5/webapps/Qm4/WEB-INF/lib/ehcache-1.1.jar!/ehcache-failsafe.xml
2006-02-08 16:31:56,468 [org.hibernate.impl.SessionFactoryObjectFactory]-[INFO] Not binding factory to JNDI, no JNDI name configured
2006-02-08 16:31:56,468 [org.hibernate.impl.SessionFactoryImpl]-[INFO] Checking 0 named queries
2006-02-08 16:31:56,656 [org.springframework.orm.hibernate3.HibernateTransactionManager]-[INFO] Using DataSource [org.apache.commons.dbcp.BasicDataSource@1e8614a] of Hibernate SessionFactory for HibernateTransactionManager
2006-02-08 16:31:56,781 [org.springframework.beans.factory.xml.XmlBeanDefinitionReader]-[INFO] Loading XML bean definitions from class path resource [org/springframework/jdbc/support/sql-error-codes.xml]
2006-02-08 16:31:56,859 [org.springframework.jdbc.support.SQLErrorCodesFactory]-[INFO] SQLErrorCodes loaded: [DB2, HSQL, MS-SQL, MySQL, Oracle, Informix, PostgreSQL, Sybase]
2006-02-08 16:31:57,234 [org.hibernate.util.JDBCExceptionReporter]-[WARN] SQL Error: 1146, SQLState: 42S02
2006-02-08 16:31:57,234 [org.hibernate.util.JDBCExceptionReporter]-[ERROR] Table 'testonline.testonline__teacher' doesn't exist
2006-02-08 16:31:57,250 [com.hexin.qm4.dao.impl.TeacherDAO]-[ERROR] save failed
org.springframework.jdbc.BadSqlGrammarException: Hibernate operation: could not insert: [com.hexin.qm4.bean.Teacher]; bad SQL grammar [insert into testonline__teacher (TeacherID, TeacherName, Password, Authory) values (?, ?, ?, ?)]; nested exception is java.sql.SQLException: Table 'testonline.testonline__teacher' doesn't exist
java.sql.SQLException: Table 'testonline.testonline__teacher' doesn't exist
2006-02-08 16:31:53,281 [org.hibernate.connection.ConnectionProviderFactory]-[INFO] Initializing connection provider: org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider
2006-02-08 16:31:54,187 [org.hibernate.cfg.SettingsFactory]-[INFO] RDBMS: MySQL, version: 5.0.18-nt
2006-02-08 16:31:54,187 [org.hibernate.cfg.SettingsFactory]-[INFO] JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-3.1.12 ( $Date: 2005-11-17 15:53:48 +0100 (Thu, 17 Nov 2005) $, $Revision$ )
2006-02-08 16:31:54,312 [org.hibernate.dialect.Dialect]-[INFO] Using dialect: org.hibernate.dialect.MySQLDialect
2006-02-08 16:31:54,343 [org.hibernate.transaction.TransactionFactoryFactory]-[INFO] Using default transaction strategy (direct JDBC transactions)
2006-02-08 16:31:54,343 [org.hibernate.transaction.TransactionManagerLookupFactory]-[INFO] No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
2006-02-08 16:31:54,343 [org.hibernate.cfg.SettingsFactory]-[INFO] Automatic flush during beforeCompletion(): disabled
2006-02-08 16:31:54,343 [org.hibernate.cfg.SettingsFactory]-[INFO] Automatic session close at end of transaction: disabled
2006-02-08 16:31:54,343 [org.hibernate.cfg.SettingsFactory]-[INFO] JDBC batch size: 15
2006-02-08 16:31:54,343 [org.hibernate.cfg.SettingsFactory]-[INFO] JDBC batch updates for versioned data: disabled
2006-02-08 16:31:54,375 [org.hibernate.cfg.SettingsFactory]-[INFO] Scrollable result sets: enabled
2006-02-08 16:31:54,375 [org.hibernate.cfg.SettingsFactory]-[INFO] JDBC3 getGeneratedKeys(): enabled
2006-02-08 16:31:54,375 [org.hibernate.cfg.SettingsFactory]-[INFO] Connection release mode: on_close
2006-02-08 16:31:54,375 [org.hibernate.cfg.SettingsFactory]-[INFO] Maximum outer join fetch depth: 2
2006-02-08 16:31:54,375 [org.hibernate.cfg.SettingsFactory]-[INFO] Default batch fetch size: 1
2006-02-08 16:31:54,375 [org.hibernate.cfg.SettingsFactory]-[INFO] Generate SQL with comments: disabled
2006-02-08 16:31:54,375 [org.hibernate.cfg.SettingsFactory]-[INFO] Order SQL updates by primary key: disabled
2006-02-08 16:31:54,375 [org.hibernate.cfg.SettingsFactory]-[INFO] Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
2006-02-08 16:31:54,406 [org.hibernate.hql.ast.ASTQueryTranslatorFactory]-[INFO] Using ASTQueryTranslatorFactory
2006-02-08 16:31:54,406 [org.hibernate.cfg.SettingsFactory]-[INFO] Query language substitutions: {}
2006-02-08 16:31:54,406 [org.hibernate.cfg.SettingsFactory]-[INFO] Second-level cache: enabled
2006-02-08 16:31:54,406 [org.hibernate.cfg.SettingsFactory]-[INFO] Query cache: disabled
2006-02-08 16:31:54,406 [org.hibernate.cfg.SettingsFactory]-[INFO] Cache provider: org.hibernate.cache.EhCacheProvider
2006-02-08 16:31:54,421 [org.hibernate.cfg.SettingsFactory]-[INFO] Optimize cache for minimal puts: disabled
2006-02-08 16:31:54,437 [org.hibernate.cfg.SettingsFactory]-[INFO] Structured second-level cache entries: disabled
2006-02-08 16:31:54,484 [org.hibernate.cfg.SettingsFactory]-[INFO] Statistics: disabled
2006-02-08 16:31:54,484 [org.hibernate.cfg.SettingsFactory]-[INFO] Deleted entity synthetic identifier rollback: disabled
2006-02-08 16:31:54,484 [org.hibernate.cfg.SettingsFactory]-[INFO] Default entity-mode: pojo
2006-02-08 16:31:55,000 [org.hibernate.impl.SessionFactoryImpl]-[INFO] building session factory
2006-02-08 16:31:55,031 [net.sf.ehcache.config.Configurator]-[WARN] No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/I:/Tomcat%205.5/webapps/Qm4/WEB-INF/lib/ehcache-1.1.jar!/ehcache-failsafe.xml
2006-02-08 16:31:56,468 [org.hibernate.impl.SessionFactoryObjectFactory]-[INFO] Not binding factory to JNDI, no JNDI name configured
2006-02-08 16:31:56,468 [org.hibernate.impl.SessionFactoryImpl]-[INFO] Checking 0 named queries
2006-02-08 16:31:56,656 [org.springframework.orm.hibernate3.HibernateTransactionManager]-[INFO] Using DataSource [org.apache.commons.dbcp.BasicDataSource@1e8614a] of Hibernate SessionFactory for HibernateTransactionManager
2006-02-08 16:31:56,781 [org.springframework.beans.factory.xml.XmlBeanDefinitionReader]-[INFO] Loading XML bean definitions from class path resource [org/springframework/jdbc/support/sql-error-codes.xml]
2006-02-08 16:31:56,859 [org.springframework.jdbc.support.SQLErrorCodesFactory]-[INFO] SQLErrorCodes loaded: [DB2, HSQL, MS-SQL, MySQL, Oracle, Informix, PostgreSQL, Sybase]
2006-02-08 16:31:57,234 [org.hibernate.util.JDBCExceptionReporter]-[WARN] SQL Error: 1146, SQLState: 42S02
2006-02-08 16:31:57,234 [org.hibernate.util.JDBCExceptionReporter]-[ERROR] Table 'testonline.testonline__teacher' doesn't exist
2006-02-08 16:31:57,250 [com.hexin.qm4.dao.impl.TeacherDAO]-[ERROR] save failed
org.springframework.jdbc.BadSqlGrammarException: Hibernate operation: could not insert: [com.hexin.qm4.bean.Teacher]; bad SQL grammar [insert into testonline__teacher (TeacherID, TeacherName, Password, Authory) values (?, ?, ?, ?)]; nested exception is java.sql.SQLException: Table 'testonline.testonline__teacher' doesn't exist
java.sql.SQLException: Table 'testonline.testonline__teacher' doesn't exist
#4
表名应该和hibernate里的那个对应的xml文件名相同才可以
#5
2006-02-08 16:31:52,656 [org.hibernate.cfg.HbmBinder]-[INFO] Mapping class: com.hexin.qm4.bean.Teacher -> teacher
应该已经可以的啊
应该已经可以的啊
#6
我的表明明是testonline.teacher,怎么这里出现的是'testonline.testonline__teacher' 啊?
Table 'testonline.testonline__teacher' doesn't exist,达人相救!
Table 'testonline.testonline__teacher' doesn't exist,达人相救!
#7
applicationContext.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="url">
<value>jdbc:mysql://localhost:3306/testonline</value>
</property>
<property name="username">
<value>root</value>
</property>
<property name="password">
<value>todobetter</value>
</property>
</bean>
<bean id="mySessionFactory" 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>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/hexin/qm4/bean/Teacher.hbm.xml</value>
</list>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="mySessionFactory" />
</property>
</bean>
<bean id="teacherDAO" class="com.hexin.qm4.dao.impl.TeacherDAO">
<property name="sessionFactory">
<ref bean="mySessionFactory" />
</property>
</bean>
<bean id="teacherService" class="com.hexin.qm4.business.impl.TeacherService">
<property name="teacherDAO">
<ref local="teacherDAO"/>
</property>
</bean>
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="url">
<value>jdbc:mysql://localhost:3306/testonline</value>
</property>
<property name="username">
<value>root</value>
</property>
<property name="password">
<value>todobetter</value>
</property>
</bean>
<bean id="mySessionFactory" 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>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/hexin/qm4/bean/Teacher.hbm.xml</value>
</list>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="mySessionFactory" />
</property>
</bean>
<bean id="teacherDAO" class="com.hexin.qm4.dao.impl.TeacherDAO">
<property name="sessionFactory">
<ref bean="mySessionFactory" />
</property>
</bean>
<bean id="teacherService" class="com.hexin.qm4.business.impl.TeacherService">
<property name="teacherDAO">
<ref local="teacherDAO"/>
</property>
</bean>
</beans>