hibernate连接数据库问题(急)

问题描述

从同事哪里把一个工程拷到我的eclipse里面用的是mysql5.1tomcat5.5hibernate3tomcat启动正常,但是只要对数据库进行操作的都报错。。Initializingc3p0pool...com.mchange.v2.c3p0.PoolBackedDataSource@7bc0aa[connectionPoolDataSource->com.mchange.v2.c3p0.WrapperConnectionPoolDataSource@18be602[acquireIncrement->1,acquireRetryAttempts->30,acquireRetryDelay->1000,autoCommitOnClose->false,automaticTestTable->null,breakAfterAcquireFailure->false,checkoutTimeout->0,connectionTesterClassName->com.mchange.v2.c3p0.impl.DefaultConnectionTester,factoryClassLocation->null,forceIgnoreUnresolvedTransactions->false,idleConnectionTestPeriod->3000,initialPoolSize->5,maxIdleTime->50000,maxPoolSize->20,maxStatements->100,maxStatementsPerConnection->0,minPoolSize->5,nestedDataSource->com.mchange.v2.c3p0.DriverManagerDataSource@bcd898[description->null,driverClass->null,factoryClassLocation->null,jdbcUrl->jdbc:mysql://localhost:3306/db_flowershop,properties->{user=******,password=******}],preferredTestQuery->null,propertyCycle->300,testConnectionOnCheckin->false,testConnectionOnCheckout->false,usesTraditionalReflectiveProxies->false],factoryClassLocation->null,numHelperThreads->3,poolOwnerIdentityToken->7bc0aa]Hibernate:selectcategory0_.IDasID,category0_.CateNameasCateName0_,category0_.CateDescasCateDesc0_fromdb_flowershop.categorycategory0_orderbycategory0_.IDHibernate:selectmerchandis0_.IDasID,merchandis0_.MerNameasMerName3_,merchandis0_.PriceasPrice3_,merchandis0_.SPriceasSPrice3_,merchandis0_.MerModelasMerModel3_,merchandis0_.PictureasPicture3_,merchandis0_.MerDescasMerDesc3_,merchandis0_.SpecialasSpecial3_,merchandis0_.numasnum3_,merchandis0_.CategoryasCategory3_fromdb_flowershop.merchandisemerchandis0_where(merchandis0_.Special=0)orderbymerchandis0_.IDdesclimit?org.hibernate.exception.SQLGrammarException:couldnotexecutequeryatorg.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:70)atorg.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)atorg.hibernate.loader.Loader.doList(Loader.java:1596)atorg.hibernate.loader.Loader.list(Loader.java:1577)atorg.hibernate.hql.classic.QueryTranslatorImpl.list(QueryTranslatorImpl.java:890)atorg.hibernate.impl.SessionImpl.list(SessionImpl.java:844)atorg.hibernate.impl.QueryImpl.list(QueryImpl.java:74)atcom.txn.service.MerServiceImpl.browseMer(MerServiceImpl.java:243)atcom.txn.struts.action.MerAction.browseIndexMer(MerAction.java:40)atsun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod)atsun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)atsun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)atjava.lang.reflect.Method.invoke(Method.java:597)atorg.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:270)atorg.apache.struts.actions.DispatchAction.execute(DispatchAction.java:187)atorg.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)atorg.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)atorg.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)atorg.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)atjavax.servlet.http.HttpServlet.service(HttpServlet.java:627)atjavax.servlet.http.HttpServlet.service(HttpServlet.java:729)atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)atcom.txn.filter.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:33)atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)atorg.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)atorg.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)atorg.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)atorg.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)atorg.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)atorg.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)atorg.apache.coyote.http11.Http11Processor.process(Http11Processor.java:875)atorg.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)atorg.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)atorg.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)atorg.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)atjava.lang.Thread.run(Thread.java:619)Causedby:java.sql.SQLException:Unknowncolumn'merchandis0_.num'in'fieldlist'atcom.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2851)atcom.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1534)atcom.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1625)atcom.mysql.jdbc.Connection.execSQL(Connection.java:2297)atcom.mysql.jdbc.Connection.execSQL(Connection.java:2226)atcom.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1812)atcom.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1657)atcom.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeQuery(NewProxyPreparedStatement.java:75)atorg.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:120)atorg.hibernate.loader.Loader.getResultSet(Loader.java:1272)atorg.hibernate.loader.Loader.doQuery(Loader.java:391)atorg.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)atorg.hibernate.loader.Loader.doList(Loader.java:1593)...35more

解决方案

解决方案二:
我的配置文件如下:?xmlversion='1.0'encoding='UTF-8'?><!DOCTYPEhibernate-configurationPUBLIC"-//Hibernate/HibernateConfigurationDTD3.0//EN""http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"><!--GeneratedbyMyEclipseHibernateTools.--><hibernate-configuration><session-factory><!--配置JDBC连接属性--><propertyname="myeclipse.connection.profile">MySQL_JDBC</property><propertyname="connection.url">jdbc:mysql://localhost:3306/db_flowershop?useUnicode=true&amp;characterEncoding=gb2312</property><propertyname="connection.username">root</property><propertyname="connection.password"></property><propertyname="connection.driver_class">com.mysql.jdbc.Driver</property><propertyname="dialect">org.hibernate.dialect.MySQLDialect</property><!--解决HQL查询中直接使用中文的问题--><propertyname="hibernate.query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactory</property><!--配置C3P0连接池属性--><propertyname="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property><propertyname="hibernate.c3p0.max_size">20</property><propertyname="hibernate.c3p0.min_size">5</property><propertyname="hibernate.c3p0.timeout">50000</property><propertyname="hibernate.c3p0.max_statements">100</property><propertyname="hibernate.c3p0.idle_test_period">3000</property><!--在控制台显示SQL语句--><propertyname="show_sql">true</property><!--注册ORM映射文件--><mappingresource="com/txn/entity/Category.hbm.xml"/><mappingresource="com/txn/entity/Admin.hbm.xml"/><mappingresource="com/txn/entity/Orders.hbm.xml"/><mappingresource="com/txn/entity/Merchandise.hbm.xml"/><mappingresource="com/txn/entity/Cart.hbm.xml"/><mappingresource="com/txn/entity/Userlevel.hbm.xml"/><mappingresource="com/txn/entity/User.hbm.xml"/><mappingresource="com/txn/entity/Message.hbm.xml"/><mappingresource="com/txn/entity/Items.hbm.xml"/><mappingresource="com/txn/entity/Announce.hbm.xml"/></session-factory></hibernate-configuration>
解决方案三:
咋没人关注下呢?
解决方案四:
该回复于2010-04-16 17:08:02被版主删除
解决方案五:
ORM文件和表结构字段有差异或者生成的POJO有问题Causedby:java.sql.SQLException:Unknowncolumn'merchandis0_.num'in'fieldlist'
解决方案六:
http://www.codefin.net/2007/05/hibernate-and-mysql-connection-timeouts.html这个是我昨天解决跟你类似数据库问题找的一个英文网站,比起我的问题来,我看更适合于你,可以耐心的看一下
解决方案七:
认同4楼检查下字段映射
解决方案八:
org.hibernate.exception.SQLGrammarException:couldnotexecutequery1.SQL语句出错了...你可以看到输出来的sql,那拿到DB里面跑,能跑成功吗?2.hbm.xml文件中去掉category="DBname";

时间: 2024-10-02 23:09:11

hibernate连接数据库问题(急)的相关文章

刚接触spring和hibernate连接数据库,大神请教啊,谢谢

问题描述 刚接触spring和hibernate连接数据库,大神请教啊,谢谢 type Exception report message Unable to compile class for JSP: description The server encountered an internal error that prevented it from fulfilling this request. exception org.apache.jasper.JasperException: Un

关于Hibernate连接数据库报错?

问题描述 //错误信息java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)at c

Hibernate 连接数据库, oracle jdbc 连接

问题描述 我在配置文件中写明了name为root在我启动服务器的时候,Hibernate报错却是去我的另一个账户下面找表,当然找不到,然后就给我报错.(root账户下是有表的,另一个账户没有)这是什么原因呢?我现在删除了那个账户就好了,他为什么去我那个账户下面找?很不解,我对Hibernate的机制不是很了解,解决办法就是删除那个账户就好了,但是原理一点都不懂.我做过的事:svn进行了项目的整合,所以我就把本地项目删除,然后重新ckeck,数据库中的用户我也删除重新建的,刚开始错误用dba的角色

Hibernate结合MYSQL数据库简单教程

在网上找了很多Hibernate的相关教程,大多数都是结合WEB服务器的,自己写一个单独的示例在Eclipse下直接运行,不需要自己写ANT脚本,不需要结合web服务器.但是需要MYSQL数据库-_- 首先要学会如何使用Eclipse,然后要下载Hibernate需要的所有JAR文件,最后安装好MYSQL 准备开始! 第一步,我们要创建一个表 结构如下 +-----------+--------------+------+-----+---------+----------------+ | F

Hibernate对各数据库的连接方言

<session-factory> <property name="connection.driver_class">net.sourceforge.jtds.jdbc.Driver</property> <property name="connection.url">jdbc:jtds:sqlserver://ALEX:1134/News</property> <!--for oracle 9 &l

hibernate配置文件hibernate.cfg.xml的详细解释

标准的XML文件的起始行,version='1.0'表明XML的版本,encoding='gb2312'表明XML文件的编码方式 <?xml version='1.0' encoding='Utf-8'?> 表明解析本XML文件的DTD文档位置,DTD是Document Type Definition 的缩写,即文档类型的定义,XML解析器使用DTD文档来检查XML文件的合法性.hibernate.sourceforge.net/hibernate-configuration-3.0dtd可以

hibernate-Hibernate问题。急急急。谁能帮帮我。

问题描述 Hibernate问题.急急急.谁能帮帮我. spring MVC整合的hibernate,hibernate只能从数据库里查询,不能插入,更新,删除.每次控制台都打印select max(id) from ....我都不知道错在哪里,求大神指点啊. 解决方案 在@ManyToOne(fetch= FetchType.LAZY)可能需要调试哦.LAZY延迟了你的DB更新处理. 解决方案二: 把异常信息全部贴出来.还有你的实体配置一句hibernate数据库配置信息,不介意的话都贴出来看

Java的Hibernate框架数据库操作中锁的使用和查询类型_java

 Hibernate与数据库锁 一.为什么要使用锁? 要想弄清楚锁机制存在的原因,首先要了解事务的概念. 事务是对数据库一系列相关的操作,它必须具备ACID特征: A(原子性):要么全部成功,要么全部撤销. C(一致性):要保持数据库的一致性. I(隔离性):不同事务操作相同数据时,要有各自的数据空间. D(持久性):一旦事务成功结束,它对数据库所做的更新必须永久保持. 我们常用的关系型数据库RDBMS实现了事务的这些特性.其中,原子性. 一致性和持久性都是采用日志来保证的.而隔离性就是由今天我

spring 连接数据库的问题

问题描述 用的spring+hibernate,那位达人能帮忙解决下,感激不尽.web.xml里:....<context-param>  <param-name>contextConfigLocation</param-name>  <param-value>   /WEB-INF/applicationContext.xml  </param-value> </context-param> <servlet>    &