mysql与hibernate的问题

配置应该是没有问题的。但是我有这样的表user(string username, string password),主键是username;但是在hibernate使用的时候抛出异常,提示Field ‘username’ doesn't have a default value;如果加了默认值,它却提示我的主键重复,查看数据库,它把默认值当了主键,把我在hibernate上当主键的覆盖了。这应该怎么办啊。小弟菜鸟啊,解决不了这个问题~

2个回答

对应的User对象的配置和代码呢?

首先不建议你使用业务相关的列作为主键,一旦有更改,那么关联就会出现问题。
如果你使用“username”做主键,要看看你如何配置的实体的主键生成方式,因为没看到你具体的代码,不好确定。

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
Mysql hibernate 映射问题
在mysql数据库中字段以下划线链接如:goods_namern通过myeclipse工具生成映射文件却变成了goodsName字段,而不是goods_name字段rn这是为什么呢?希望指点一下
关于Hibernate和mysql的问题
我用的是tomcat,每天早上6点钟自动重启....,但是有时候启动之后hibernate连接不上mysql.....rnrn在开发的时候我也发现了这个问题,就是当tomcat正在启动的过程中,点击了和数据库相关的操作,这样hibernate就连接不上mysql了,必须重启tomcat才能解决,不知道有什么其他的办法可以解决这个问题.
MySQL和hibernate问题
在MySQL中,哪个是数据库名?哪个是用户名?如何增加一个数据库?如何增加一个用户?密码是什么的密码?rnrnhibernate.cfg.xml中的标签,如果我用的是MySQL数据库填什么?我数据库在连接上时的欢迎信息是这样的:Your MySQL connection id is 1 to server version:4.1.15-ntrnrnrn
hibernate和mysql的缓存问题
hibernate和mysql的缓存问题 rn 真疯了。。。。。真弄不了了rn刚添加一第数据,返回页面可以看到刚添加的数据,有时候页面刷新好几次后才查询出刚添加的数据,有时候刷新一会是新的数据一会是旧的数据 ...到底怎么回事??rn
MySQL,Hibernate映射问题
数据库中设置主键为自增列,Hibernate中需要设置主键列吗?
hibernate和mysql的问题
mysql中表主键的属性是auto_increment 我该怎么写.hbm.xml?
hibernate 连接mysql问题
hibernate配置文件中如下:rnhibernate.dialect=net.sf.hibernate.dialect.MySQLDialectrnhibernate.connection.driver_class=com.mysql.jdbc.Driverrnhibernate.connection.url=jdbc:mysql:///vms?useUnicode=true&characterEncoding=UTF8rnhibernate.connection.username=rootrnhibernate.connection.password=rnhibernate.connection.pool_size=1rn#hibernate.show_sql=truern#hibernate.dbcp.maxActive=10rn#hibernate.dbcp.whenExhaustedAction=1rn#hibernate.dbcp.maxWait=120000rn#hibernate.dbcp.maxIdle=5rn#hibernate.dbcp.ps.maxActive=100rn#hibernate.dbcp.ps.whenExhaustedAction=1rn#hibernate.dbcp.ps.maxWait=120000rn#hibernate.dbcp.ps.maxIdle=5rn#hibernate.dbcp.validationQuery=select 1 from dualrn#hibernate.dbcp.testOnBorrow=truern#hibernate.dbcp.testOnReturn=falsern错误信息如下:rnCaused by: net.sf.hibernate.JDBCException: Cannot open connectionrn at net.sf.hibernate.impl.BatcherImpl.openConnection(BatcherImpl.java:260)rn at net.sf.hibernate.impl.SessionImpl.connect(SessionImpl.java:3157)rn at net.sf.hibernate.impl.SessionImpl.connection(SessionImpl.java:3140)rn at net.sf.hibernate.impl.BatcherImpl.prepareQueryStatement(BatcherImpl.java:61)rn at net.sf.hibernate.loader.Loader.prepareQueryStatement(Loader.java:703)rn at net.sf.hibernate.loader.Loader.doQuery(Loader.java:184)rn at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:132)rn at net.sf.hibernate.loader.Loader.doList(Loader.java:949)rn at net.sf.hibernate.loader.CriteriaLoader.list(CriteriaLoader.java:109)rn at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:3440)rn at net.sf.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:177)rn at com.intrint.vms.security.data.PartnerPeer.login(PartnerPeer.java:28)rn ... 42 morernCaused by: java.sql.SQLException: Communication link failure: Bad handshakern at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:659)rn at com.mysql.jdbc.Connection.createNewIO(Connection.java:1562)rn at com.mysql.jdbc.Connection.(Connection.java:491)rn at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:346)rn at java.sql.DriverManager.getConnection(DriverManager.java:512)rn at java.sql.DriverManager.getConnection(DriverManager.java:140)rn at net.sf.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:95)rn at net.sf.hibernate.impl.BatcherImpl.openConnection(BatcherImpl.java:257)rn ... 53 morernrnrnrn运行正常但是登陆时访问数据库的地方就会出错,怀疑是没有联上mysql可能是驱动问题,望高手关注,谢谢!另外寻找hibernate志同道合者。wuenming@263.net
hibernate mysql的一个问题
最近学习hibernate,弄一个简单的项目,数据库用的mysqlrn 有一个数据表article,主键id是自增长的,rn 不知道有什么方法(用hibernate),可以在插入一条新的记录进数据表后,然后马上就可以获得数据的自动生成id。rn
hibernate mysql 数据问题
用hibernate往mysql插入了数据但却不能查到该数据 是什么原因 各位爷给指点指点
hibernate连MySql问题!!
我在mysql里建了数据库samplern在mysql.xml里 这样写的:rnrnrnrn但用ant运行时:rnBuildfile: D:\eclipse\workspace\HibernateSample\lib\Middlegen-Hibernate-r5\Middlegen-Hibernate-r5\build.xmlrninit:rnfail-if-no-xdoclet-1.2:rncheck-driver-present:rnpanic-if-driver-not-present:rnmiddlegen:rn [echo] Class path = D:\eclipse\workspace\HibernateSample\lib\Middlegen-Hibernate-r5\Middlegen-Hibernate-r5rn[middlegen] (middlegen.Middlegen 350 ) Registering plugin simple->middlegen.Pluginrn[middlegen] (middlegen.Middlegen 350 ) Registering plugin java->middlegen.javax.JavaPluginrn[middlegen] (middlegen.Middlegen 350 ) Registering plugin plugin->middlegen.Pluginrn[middlegen] (middlegen.Middlegen 350 ) Registering plugin hibernate->middlegen.plugins.hibernate.HibernatePluginrn[middlegen] Database URL:jdbc:mysql://localhost/samplernrnBUILD FAILED//在这里出了错误rnD:\eclipse\workspace\HibernateSample\lib\Middlegen-Hibernate-r5\Middlegen-Hibernate-r5\build.xml:148: middlegen.MiddlegenException: Couldn't connect to database: Access denied for user 'root'@'localhost' (using password: NO)rnrnTotal time: 7 secondsrn请问是怎么回事rnrn
MySql Hibernate 查询语句问题
[code=Java]rnselect rn mem.routId, rn mem.memCode, rn r.routName, rn r.ipaddress, rn min(mem.usedValue) as minUsedValue, rn max(mem.usedValue) as maxUsedValue, rn avg(mem.usedValue) as avgUsedValue rn from Net_Cap_Mem mem, Net_Routinfo r rn where mem.routId=r.routId and recordTime>='2010-03-04 16:56:56' and recordTime<='2010-03-08 15:29:26' rn and mem.routId in (select plan.goId from Net_Gatherpublicobject plan where plan.gmId=2) group by mem.routId order by avgUsedValue descrnrnrn[/code]rnrn上面是一个Mysql+Hibernate查询语句rn 最后我想用 字段 avg(mem.usedValue) as avgUsedValue 排序 rn 问题:rn 我把这语句放入代码中执行就报错!说是找不到 avgUsedValue 这个字段rn 直接放入 数据库中可以正常查询到数据!rnrnrn 这是上面问题,应该怎么解决????
Hibernate与MySQL日期格式问题
数据库produceTime的类型是datetime。如“2011-04-29 17:40:45”rn[code=Java]rnprivate Date produceTime;rn@Column(name = "produceTime", length = 19)rnpublic Date getProduceTime() rn return this.produceTime;rnrnpublic void setProduceTime(Date produceTime) rn this.produceTime = produceTime;rnrn[/code]rn但是我在页面遍历的时候日期格式是“2011-04-29 17:40:45.0”。rn多了一个“.0”。我是用EL表达式获取的。rn哪位高手知道是什么问题?
hibernate连接mysql问题
Exception in thread "main" org.hibernate.exception.JDBCConnectionException: Cannot open connectionrn at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:74)rn at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)rn at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:29)rn at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:426)rn at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:144)rn at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:119)rn at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:57)rn at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1326)rn at com.hibernate.hiber.Base.main(Base.java:24)rnCaused by: java.sql.SQLException: No suitable driverrn at java.sql.DriverManager.getConnection(DriverManager.java:545)rn at java.sql.DriverManager.getConnection(DriverManager.java:140)rn at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:110)rn at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:423)rn ... 5 morernrnrn这两个是什么问题,总是说找不到适合的驱动!!rn配置文件:rnrn org.gjt.mm.mysql.Driverrn jdbc:mysql://localhost:3306;database=webrn MySQLrn 123rn rn rn org.hibernate.dialect.MySQLDialectrn rn rn updatern rn rn rn rn rn没错吧
Hibernate和mysql 中文问题
以前用Hibernate3和mysql4.0 rnjdbc:mysql://localhost/db?useUnicode=true&characterEncoding=GB2312rn数据源这么配置中文没有任何问题rn后来换成mysql5.0就不行了 写入中文没有问题 但是读出来的就是乱码了rn请高手指点一下
hibernate查询mysql问题
select vo from TodayAlert vo where vo.delUserIds not like ? order by CASE status WHEN '已完成' THEN 1 ELSE CASE vo.alertType WHEN 1 THEN CASE TO_DAYS(vo.endTime) > TO_DAYS(now()) WHEN 1 THEN 0 ELSE 1 END WHEN 3 THEN CASE TO_DAYS(vo.endTime) > TO_DAYS(now()) WHEN 1 THEN CASE mod((TO_DAYS(now())-TO_DAYS(vo.startTime)),vo.cycleDay) WHEN 0 THEN 0 ELSE 1 END ELSE 1 END END END asc,vo.endTime descrnrnrn这是输出的语句。大家帮我看看有什么问题没有?rn2010-12-23 17:15:09 ERROR [http-8080-3] PARSER.reportError(56) | line 1:160: unexpected token: >rn2010-12-23 17:15:09 ERROR [http-8080-3] PARSER.reportError(56) | line 1:174: unexpected token: )rn2010-12-23 17:15:09 ERROR [http-8080-3] PARSER.reportError(56) | line 1:175: expecting "end", found ')'rn2010-12-23 17:15:09 ERROR [http-8080-3] PARSER.reportError(56) | line 1:177: unexpected token: WHENrn2010-12-23 17:15:10 WARN [http-8080-3] HqlParser.processEqualityExpression(226) | processEqualityExpression() : No expression to process!rn[LMIC] 2010-12-23 17:15:10 ERROR [http-8080-3] PARSER.reportError(56) | line 1:184: unexpected token: THENrn2010-12-23 17:15:10 org.apache.catalina.core.StandardWrapperValve invokernrn这是控制台输出的错误。我在mysql上运行没有问题。很奇怪。。。
Hibernate连接MySql问题
我用Hibernate连接MySql数据库(今天刚学Hibernate的入门),向里面插入数据后,在控制台和图形化界面查询均不能正常显示,中文字符均以?代替,英文,数字正常.hibernate.cfg.xml ,Person.hbm.xml文件编码都是utf-8,问该如何解决?
hibernate mysql驱动问题
测试是出现这个问题怎么解决rnorg.hibernate.HibernateException: JDBC Driver class not found: com.jdbc.MySQL.Driverrn我已经导入了mysql-connector-java-5.1.13-bin.jar这个包可是还是不行求帮助?
hibernate 连接mysql问题!
hibernate配置文件中如下:rnhibernate.dialect=net.sf.hibernate.dialect.MySQLDialectrnhibernate.connection.driver_class=com.mysql.jdbc.Driverrnhibernate.connection.url=jdbc:mysql:///vms?useUnicode=true&characterEncoding=UTF8rnhibernate.connection.username=rootrnhibernate.connection.password=rnhibernate.connection.pool_size=1rn#hibernate.show_sql=truern#hibernate.dbcp.maxActive=10rn#hibernate.dbcp.whenExhaustedAction=1rn#hibernate.dbcp.maxWait=120000rn#hibernate.dbcp.maxIdle=5rn#hibernate.dbcp.ps.maxActive=100rn#hibernate.dbcp.ps.whenExhaustedAction=1rn#hibernate.dbcp.ps.maxWait=120000rn#hibernate.dbcp.ps.maxIdle=5rn#hibernate.dbcp.validationQuery=select 1 from dualrn#hibernate.dbcp.testOnBorrow=truern#hibernate.dbcp.testOnReturn=falsern错误信息如下:rnCaused by: net.sf.hibernate.JDBCException: Cannot open connectionrn at net.sf.hibernate.impl.BatcherImpl.openConnection(BatcherImpl.java:260)rn at net.sf.hibernate.impl.SessionImpl.connect(SessionImpl.java:3157)rn at net.sf.hibernate.impl.SessionImpl.connection(SessionImpl.java:3140)rn at net.sf.hibernate.impl.BatcherImpl.prepareQueryStatement(BatcherImpl.java:61)rn at net.sf.hibernate.loader.Loader.prepareQueryStatement(Loader.java:703)rn at net.sf.hibernate.loader.Loader.doQuery(Loader.java:184)rn at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:132)rn at net.sf.hibernate.loader.Loader.doList(Loader.java:949)rn at net.sf.hibernate.loader.CriteriaLoader.list(CriteriaLoader.java:109)rn at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:3440)rn at net.sf.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:177)rn at com.intrint.vms.security.data.PartnerPeer.login(PartnerPeer.java:28)rn ... 42 morernCaused by: java.sql.SQLException: Communication link failure: Bad handshakern at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:659)rn at com.mysql.jdbc.Connection.createNewIO(Connection.java:1562)rn at com.mysql.jdbc.Connection.(Connection.java:491)rn at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:346)rn at java.sql.DriverManager.getConnection(DriverManager.java:512)rn at java.sql.DriverManager.getConnection(DriverManager.java:140)rn at net.sf.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:95)rn at net.sf.hibernate.impl.BatcherImpl.openConnection(BatcherImpl.java:257)rn ... 53 morernrnrnrn运行正常但是登陆时访问数据库的地方就会出错,怀疑是没有联上mysql可能是驱动问题,望高手关注,谢谢!另外寻找hibernate志同道合者。wuenming@263.net
hibernate + mysql 的问题!
我接手的一个网站,只有classes类及 hbm.xml配置文件! 现在碰到一个这样的问题rnrn原来他们用的是oracle数据库,现在需要迁移到mysql上。rnrn我把oracle的数据迁移到我本地开发机上的mysql里,版本是5.0.27, 然后运行tomcat,,可以正常运行。。rnrn但是迁到万网的服务器上,它的mysql版本是4.0.20 ,我把数据导过去之后,运行, 就出错了! 出错信息如下:rnrnnet.app.core.exceptions.SysException: null (HibernateException while find:from NewDocumentModel as drnoc where 1=1 and doc.aspID=1 and ( doc.type='51' ) order by doc.docID descrnnet.sf.hibernate.JDBCException: Could not execute query)rnrnrn请问各位大虾知道如何解决吗? 多谢!
Hibernate与mysql的中文问题
Hibernate能否将mysql的默认(latin1)读取成gb2312......rn我的数据库是默认安装的(编码为latin1),也就是说,我数据库的数据全部都是乱码(相对与中文而言),用的是JDBC连接(连接类中输入输出都做了编码转换)rn现在要对网站升级,用Hibernate连接数据库,然后乱码问题出现了。rn也就是说hibernate是直接把数据库里的数据直接读取出来,rn而中间能否进行编码转换?? 我的连接字符串是rnjdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=gb2312rn我想到的解决方案: 将数据库数据进行翻译rnrn请问各位大侠有没有其它办法解决这个问题??(急)
mysql + Hibernate + struts 问题
小弟使用 tomcat + apache + mysql,最近log里出现了下面的问题:rnrn[code="java"]Jan 7, 2009 10:14:38 AM org.apache.catalina.core.StandardWrapperValve invokernSEVERE: Servlet.service() for servlet action threw exceptionrnjava.net.SocketException: Software caused connection abort: socket write errorrn at java.net.SocketOutputStream.socketWrite0(Native Method)rn at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)rn at java.net.SocketOutputStream.write(SocketOutputStream.java:136)rn at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:65)rn at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:123)rn at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3227)rn at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1917)rn at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060)rn at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2542)rn at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1734)rn at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1885)rn at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeQuery(NewProxyPreparedStatement.java:76)rn at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)rn at org.hibernate.loader.Loader.getResultSet(Loader.java:1787)rn at org.hibernate.loader.Loader.doQuery(Loader.java:674)rn at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)rn at org.hibernate.loader.Loader.doList(Loader.java:2220)rn at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)rn at org.hibernate.loader.Loader.list(Loader.java:2099)rn at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:378)rn at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)rn at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)rn at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)rn at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)rn at org.hibernate.impl.AbstractQueryImpl.uniqueResult(AbstractQueryImpl.java:811)rn at com.icait.dao.UserDAOImpl.authenticateByEmail(UserDAOImpl.java:67)rn at com.icait.action.UserLoginAction.execute(UserLoginAction.java:54)rn at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)rn at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)rn at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)rn at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)rn at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)rn at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)rn at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)rn at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)rn at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)rn at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)rn at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:190)rn at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:283)rn at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:767)rn at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:697)rn at org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:889)rn at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:690)rn at java.lang.Thread.run(Thread.java:619)[/code]rnrn用的是hibernate + struts, 我估计问题出在 c3p0 连接上,可是也不可以确定, hibernate.cfg 文件配置如下:rn[code="java"]rn org.hibernate.connection.C3P0ConnectionProviderrn rn 20rn rn 5rn rn 1800rn rn Testrn rn 0rn rn 1500rn rn 1rn rn truern rn truern rn org.hibernate.dialect.MySQLDialectrn rn com.mysql.jdbc.Driverrn rn jdbc:mysql://localhost/dbnamern rn ****rn rn ****rn rn truern rn threadrn rn[/code]rnrn之前有那个8小时的问题,这样配置好象不会出了,可是一旦出现前面的那个bug以后,就又有8小时问题了...rnrn先谢过了!
hibernate +mysql
rnJDBCExceptionReporter - [color=#FF0000]could not execute query [/color][select userinfo0_.USER_ID as USER1_, userinfo0_.USERNAME as USERNAME0_, userinfo0_.PASSWORD as PASSWORD0_, userinfo0_.ENABLED as ENABLED0_ from [color=#FF0000]test__userinfo userinfo0_ [/color]where userinfo0_.USERNAME=?]rnjava.sql.SQLException: [color=#FF0000]Table 'test.test__userinfo' doesn't exist[/color]rn at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2926)rn at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1571)rn at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1666)rn at com.mysql.jdbc.Connection.execSQL(Connection.java:2978)rn at com.mysql.jdbc.Connection.execSQL(Connection.java:2902)rn at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:933)rn at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1027)rn at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:92)rn at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:120)rn at org.hibernate.loader.Loader.getResultSet(Loader.java:1272)rn at org.hibernate.loader.Loader.doQuery(Loader.java:391)rn at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)rn at org.hibernate.loader.Loader.doList(Loader.java:1593)rn at org.hibernate.loader.Loader.list(Loader.java:1577)rn at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:395)rn at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:271)rn at org.hibernate.impl.SessionImpl.list(SessionImpl.java:844)rn at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)rn at com.gg.dao.UserinfoDAO.findByProperty(UserinfoDAO.java:85)rn at com.gg.dao.UserinfoDAO.findByUsername(UserinfoDAO.java:94)rn at com.gg.test.Testa.main(Testa.java:19)rnrn 我的数据库是 这个样子的: 数据库是test 下面有个userinfo表,在通过hibernate 生成的查询语句时出现这样的错误 'test.test__userinfo' ,为什么找不到表?rn rnrn
hibernate + mysql?
hiberante + mysql rn当存储图片加文章的时候rn出现异常 Data truncation: Data too long for column 'Content' at row 1rn但是不是字符乱码问题 而是设置的长度问题rn在中 应该用什么类似 可以保证 图文一起存进库中rn谢谢
关于 MYSQL 和HIBERNATE 的 语句问题
那位大哥 有时间帮忙看一个这个MYSQL 的语句错在哪里了。是HIBERNATE 的。rnselect cg,b.jlhid from ContentGame as cg,(select t.jlhid,count(*) as c from ContentStat as t where t.jltype = 'game' and t.action = '0' group by t.jlhid order by t.c) as b where a.id = b.jlhid and cr.province = ? and cr.city = ? and cr.audited=1 limit 0,10
Hibernate和MYSQL实现更新数据问题!?
部份代码如下:执行在ECLIPSE的控制台里显示结果是更新啦,但我到数据库里看却没有变!rn但插入数据和查询数据都没问题!请各位达人,赐教!多谢!rnrn[code=Java]public class HibernateTest rnpublic static void main(String[] args) throws HibernateException rnrn SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();rn Session session = sessionFactory.openSession(); rnrn List users = session.find("from User");rn // 关闭这个Sessionrn session.close();rnrn User updated = null;rnrn for (ListIterator iterator = users.listIterator(); iterator.hasNext(); ) rn rn User user = (User) iterator.next();rn rn if(updated == null)rn updated = user;rnrn System.out.println(user.getName() +rn "\n\tAge: " + user.getAge() +rn "\n\tSex: " + user.getSex());rn rn rn // 使用者作一些操作,之后储存rnrn updated.setName("volcano");rn rn // 开启一个新的Sessionrn session = sessionFactory.openSession(); rn // 更新数据rn //session.update(updated);rn session.saveOrUpdate(updated);rn users = session.find("from User"); rn session.close();rn sessionFactory.close();rnrn for (ListIterator iterator = users.listIterator(); iterator.hasNext(); ) rn User user = (User) iterator.next(); rn System.out.println(user.getName() +rn "\n\tAge: " + user.getAge() +rn "\n\tSex: " + user.getSex());rn rn rn[/code]rn
Hibernate 连接 Mysql save()问题
spring_ioc.xmlrn[code=XML]rnrnrnrnrnrnrn rn rn rn rn rn rn rn rn rnrnrn[/code]rnhibernate.cfg.xmlrn[code=XML]rnrnrnrnrnrnrn rn rootrn rn jdbc:mysql://localhost:3306/testrn rn rn org.hibernate.dialect.MySQLDialectrn rn mysqlrn rootrn rn com.mysql.jdbc.Driverrn rn rnrn rnrnrn[/code]rnPOrn[code=Java]rnpackage com.po;rnrn/**rn * User generated by MyEclipse Persistence Toolsrn */rnrnpublic class User implements java.io.Serializable rnrn // Fieldsrnrn private Integer userId;rnrn private String userName;rnrn private String userSex;rnrn private Integer userAge;rnrn // Constructorsrnrn /** default constructor */rn public User() rn rnrn /** minimal constructor */rn public User(String userName) rn this.userName = userName;rn rnrn /** full constructor */rn public User(String userName, String userSex, Integer userAge) rn this.userName = userName;rn this.userSex = userSex;rn this.userAge = userAge;rn rnrn // Property accessorsrnrn public Integer getUserId() rn return this.userId;rn rnrn public void setUserId(Integer userId) rn this.userId = userId;rn rnrn public String getUserName() rn return this.userName;rn rnrn public void setUserName(String userName) rn this.userName = userName;rn rnrn public String getUserSex() rn return this.userSex;rn rnrn public void setUserSex(String userSex) rn this.userSex = userSex;rn rnrn public Integer getUserAge() rn return this.userAge;rn rnrn public void setUserAge(Integer userAge) rn this.userAge = userAge;rn rnrnrn[/code]rnDAO通过Hibernate反转过来的rn[code=Java]rnpackage com.po;rnrnimport java.util.List;rnimport org.apache.commons.logging.Log;rnimport org.apache.commons.logging.LogFactory;rnimport org.hibernate.LockMode;rnimport org.springframework.context.ApplicationContext;rnimport org.springframework.orm.hibernate3.support.HibernateDaoSupport;rnrn/**rn * Data access object (DAO) for domain model class User.rn * rn * @see com.po.Userrn * @author MyEclipse Persistence Toolsrn */rnrnpublic class UserDAO extends HibernateDaoSupport rn private static final Log log = LogFactory.getLog(UserDAO.class);rnrn protected void initDao() rn // do nothingrn rnrn public void save(User transientInstance) rn log.debug("saving User instance");rn try rn getHibernateTemplate().save(transientInstance);rn log.debug("save successful");rn catch (RuntimeException re) rn log.error("save failed", re);rn throw re;rn rn rnrn public void delete(User persistentInstance) rn log.debug("deleting User instance");rn try rn getHibernateTemplate().delete(persistentInstance);rn log.debug("delete successful");rn catch (RuntimeException re) rn log.error("delete failed", re);rn throw re;rn rn rnrn public User findById(java.lang.Integer id) rn log.debug("getting User instance with id: " + id);rn try rn User instance = (User) getHibernateTemplate()rn .get("com.po.User", id);rn return instance;rn catch (RuntimeException re) rn log.error("get failed", re);rn throw re;rn rn rnrn public List findByExample(User instance) rn log.debug("finding User instance by example");rn try rn List results = getHibernateTemplate().findByExample(instance);rn log.debug("find by example successful, result size: "rn + results.size());rn return results;rn catch (RuntimeException re) rn log.error("find by example failed", re);rn throw re;rn rn rnrn public List findByProperty(String propertyName, Object value) rn log.debug("finding User instance with property: " + propertyNamern + ", value: " + value);rn try rn String queryString = "from User as model where model."rn + propertyName + "= ?";rn return getHibernateTemplate().find(queryString, value);rn catch (RuntimeException re) rn log.error("find by property name failed", re);rn throw re;rn rn rnrn public List findAll() rn log.debug("finding all User instances");rn try rn String queryString = "from User";rn return getHibernateTemplate().find(queryString);rn catch (RuntimeException re) rn log.error("find all failed", re);rn throw re;rn rn rnrn public User merge(User detachedInstance) rn log.debug("merging User instance");rn try rn User result = (User) getHibernateTemplate().merge(detachedInstance);rn log.debug("merge successful");rn return result;rn catch (RuntimeException re) rn log.error("merge failed", re);rn throw re;rn rn rnrn public void attachDirty(User instance) rn log.debug("attaching dirty User instance");rn try rn getHibernateTemplate().saveOrUpdate(instance);rn log.debug("attach successful");rn catch (RuntimeException re) rn log.error("attach failed", re);rn throw re;rn rn rnrn public void attachClean(User instance) rn log.debug("attaching clean User instance");rn try rn getHibernateTemplate().lock(instance, LockMode.NONE);rn log.debug("attach successful");rn catch (RuntimeException re) rn log.error("attach failed", re);rn throw re;rn rn rnrn public static UserDAO getFromApplicationContext(ApplicationContext ctx) rn return (UserDAO) ctx.getBean("UserDAO");rn rnrn[/code]rnrnrnTestrn[code=Java]rnpackage com.util;rnrnimport org.springframework.context.ApplicationContext;rnimport org.springframework.context.support.ClassPathXmlApplicationContext;rnrnimport com.po.User;rnimport com.po.UserDAO;rnrnpublic class Test rnrn /**rn * @param argsrn */rn public static void main(String[] args) rn rn ApplicationContext app = new ClassPathXmlApplicationContext("spring_ioc.xml");rn UserDAO dao = (UserDAO)app.getBean("UserDAO");rn User user = new User();rn user.setUserName("xiaomaha");rn user.setUserSex("男");rn user.setUserAge(24);rn dao.save(user);rn rnrnrnrn[/code]rnrn我认为我配置没错`用的DAO是通过Hibernate自动生成的看了下代码用的是getHibernateTemplate 所以不需要事物`它的DAO绝对没问题rnrn我运行的时候也不出异常!为什么数据库里没东西!!!!rnrn我Mysql 资料表类型为InnoDB 所以支持事物!rnrn找了半天没找到问题于是我在hibernate.cfg.xml配置文件中加了一句rn[code=XML]true[/code]rn数据库里面就有信息了``但是自动编号变成了6`!!刚好使用了5次`前面的数据去哪儿了?rn请帮我解决下这个问题`我不想用[code=XML]true[/code] rnrn[color=#FF00FF]期盼高手解答我的疑问!!![/color]rn
关于hibernate添加数据到mysql的问题
我在使用hibernate添加数据的时候,如果数据中没有中文字符就没有问题,如果有中文字符就有问题。rn但是我数据库中有2张表,我往第一张表里面添加中文数据就没有问题,向第二张表里面添加数据的时候就报错了。rn我现在把代码贴上来大家帮我看看rnServicelog.hbm.xml代码:rn[code=XML]rnrnrnrnrn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rnrnrn[/code]rn报错信息:rn[code=Java]rn严重: Servlet.service() for servlet action threw exceptionrnjava.sql.SQLException: Data too long for column 'serContent' at row 1rn at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2921)rn at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1570)rn at com.mysql.jdbc.ServerPreparedStatement.serverExecute(ServerPreparedStatement.java:1085)rn at com.mysql.jdbc.ServerPreparedStatement.executeInternal(ServerPreparedStatement.java:670)rn at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1159)rn at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1076)rn at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1061)rn at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:1968)rn at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2405)rn at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:37)rn at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)rn at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:269)rn at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:167)rn at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:101)rn at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:186)rn at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)rn at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:175)rn at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)rn at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)rn at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:530)rn at org.hibernate.impl.SessionImpl.save(SessionImpl.java:518)rn at org.hibernate.impl.SessionImpl.save(SessionImpl.java:514)rn at com.hpxx.hibernate.ServicelogDAO.save(ServicelogDAO.java:38)rn at com.hpxx.dao.ServicelogDao.insertServicelog(ServicelogDao.java:16)rn at com.hpxx.struts.action.update.InsertServiceAction.execute(InsertServiceAction.java:127)rn at org.springframework.web.struts.DelegatingActionProxy.execute(DelegatingActionProxy.java:110)rn at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)rn at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)rn at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)rn at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)rn at com.hpxx.filter.EncodingFilter.doFilter(EncodingFilter.java:31)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)rn at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)rn at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)rn at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)rn at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)rn at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)rn at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)rn at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)rn at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)rn at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)rn at java.lang.Thread.run(Unknown Source)rn[/code]rnrn大大们帮忙看下
MySQL Hibernate分页效率问题
4万多条数据,分页,每页取20条数据。用的MySQL+Hibernate。rn每翻一页居然要两三秒!!!其中有where子句,发现满足条件的总结果数越多,翻页越慢。rn非常想知道怎样提速。rn服务器1G内存 AMD4000+, 这个规模的数据,达到多少秒算正常。rnrn代码如下:http://code.google.com/p/virtual-judge/source/browse/trunk/judge/src/judge/action/ProblemAction.java?r=95#309
hibernate 对mysql 语句问题
[code=SQL]from com.huayiluo.hibernate.pojo.Product where match (uuid,title,intro,color,size,description) against('a' in boolean mode) and status=1 order by hotSale desc[/code]rnrn这是hibernate的语句rnrn问题出现在match against(hibernate 好像不支持。)rnrnrnrnhttps://forum.hibernate.org/viewtopic.php?p=2256280rn国外的人有一个解决方案。可是不太懂。rnrnrn请问有什么办法解决。我搜索百度,好像没有人出现过这种问题。。。
hibernate mysql setFirstResult 方法问题...
1.项目现在从oracle转移到mysql项目.但是里面有一些方法已经不能使用不知道是什么问题.rn 首先是分页.我用的mysql版本是 4.0 配合hibernate进行分页.在没有转移之前 分页是好使.rn 请看代码.rn[code=Java]rnrnpublic List queryObjectsToPages(final HQuery hquery) rn HibernateTemplate hibernateTemplate = new HibernateTemplate(getSessionFactory());rn return (List) hibernateTemplate.execute(new HibernateCallback() rn public Object doInHibernate(Session session) throws HibernateException rn List itr = null;rn try rn StringBuffer query_str = new StringBuffer(hquery.getQueryString());rn if (hquery.getOrderby() != null) rn query_str.append(hquery.getOrderby());rn rn // 是否要分组rn if (hquery.getGroupby() != null) rn query_str.append(hquery.getGroupby());rn rn Query query = session.createQuery(query_str.toString());rn setQueryParams(hquery, query);rn // 是否存在分页,当hquery.getPageStartNo()==0是不分页rn if (hquery.getPageStartNo() != 0) rn long pageno = hquery.getPageStartNo();rn query.setFirstResult(Integer.parseInt(Long.toString(pageno - 1))* hquery.getRowsPerpage());rn query.setMaxResults(hquery.getRowsPerpage());rn rn itr = query.list();//<1>rn catch (Exception e) rn e.printStackTrace();rn rn return itr; rn rn );rnrn[/code]rn---------------------------------------------------rn上边是用oracle的时候进行分页..但是换成mysql后就报错误 在 <1> 这里报错.分析应该是query.setFirstResult这里的错误..后来看sql 她查询后 用的是 rownum方法...mysql没有这个方法.我猜是这里的错误 所以我又改可一下上边的方法..rn[code=Java]rnpublic List queryObjectsToPages(final HQuery hquery) rnHibernateTemplate hibernateTemplate = new HibernateTemplate(getSessionFactory());rnreturn (List) hibernateTemplate.execute(new HibernateCallback() rnpublic Object doInHibernate(Session session) throws HibernateException rnList itr = null;rntry rn StringBuffer query_str = new StringBuffer(hqueryrn .getQueryString());rn // 是否要排序rn if (hquery.getOrderby() != null) rn query_str.append(hquery.getOrderby());rn rn // 是否要分组rn if (hquery.getGroupby() != null) rn query_str.append(hquery.getGroupby());rn rn Query query = session.createQuery(query_str.toString());rn if (hquery.getPageStartNo() != 0) rn long pageno = hquery.getPageStartNo();rn int first = Integer.parseInt(Long.toString(pageno - 1))* hquery.getRowsPerpage();rn int end =hquery.getRowsPerpage();rn query_str.append(" limit ").append(first).append(",").append(end); rn rn rn setQueryParams(hquery, query);rn itr = query.list();//////<2>rn catch (Exception e) rn e.printStackTrace();rnrnreturn itr;rnrn);rnrn[/code]rnrn-------------------------------------rn这个时候返回的 <2>里面把数据库所有数据都返回了..rn但是我用 rn[code=SQL]select * from USERS as a where 1=1 order by a.id desc limit 0,10[/code]rn查询还有好使...rn 请朋友帮我看看是那里出了问题........
Hibernate中配置mysql问题
我在hibernate.cfg.xml中配置如下org.hibernate.dialect.MySQLDialect使用myeclipse配置的,但是运行是却出现HibernateException:Exception in thread "main" org.hibernate.HibernateException: Hibernate Dialect must be explicitly setrn at org.hibernate.dialect.DialectFactory.determineDialect(DialectFactory.java:57)rn at org.hibernate.dialect.DialectFactory.buildDialect(DialectFactory.java:39)rn at org.hibernate.cfg.SettingsFactory.determineDialect(SettingsFactory.java:378)rn at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:110)rn at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1881)rn at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1174)rn at hibernate.TestHibernate.main(TestHibernate.java:19)
hibernate与mysql开发中的问题?
我认为 hibernate生成的POJO是根据mysql关系图建立的?它们之间的关系也是mysql建立关系图时指定的,请问你们一般用什么建立关系图的? rnrn以上是个人观点,不知道正确不,如果不对请指出。
oracle,mysql 和hibernate的问题。。。。。。。急
是这样的,前些天我发了一个oracle改mysql的贴么,现在又遇到了点问题。。。请大家帮帮忙rnoracle里边的long型 映射到hibernate里边是long型的 ,但是到了mysql映射hibernate的时候就没有long型了 ,都是int类型的,除了改程序,还有其他的办法吗???、比如说在数据库里边改一下 或者在哪里写个监听什么的。。。。。谢谢大家了
hibernate使用mysql的date_add问题
是不能使用吗?rnand DATE_ADD(marketInfo.marketBill.createTime,INTERVAL 1 HOUR)>:sendTimern说缺少1这个token?rn好解决吗?
hibernate连接mysql中的问题
程序是一个实现向建好的MySQL数据库里加入一条记录,但是出现下面的错误信息,请高手指教一下,谢谢rnrnrnrnlog4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).rnlog4j:WARN Please initialize the log4j system properly.rnHibernate: insert into myusertable (username, password, email, id) values (?, ?, ?, ?)rnorg.hibernate.exception.GenericJDBCException: could not insert: [hyq03.hibernate.User]rn at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)rn at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)rn at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)rn at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:40)rn at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2158)rn at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2638)rn at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:48)rn at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)rn at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:298)rn at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:181)rn at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:107)rn at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:187)rn at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)rn at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:172)rn at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)rn at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)rn at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:535)rn at org.hibernate.impl.SessionImpl.save(SessionImpl.java:523)rn at org.hibernate.impl.SessionImpl.save(SessionImpl.java:519)rn at hyq03.hibernate.Test.main(Test.java:21)rnCaused by: java.sql.SQLException: Statement parameter 4 not set.rn at com.mysql.jdbc.ServerPreparedStatement.serverExecute(ServerPreparedStatement.java:1031)rn at com.mysql.jdbc.ServerPreparedStatement.executeInternal(ServerPreparedStatement.java:676)rn at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1166)rn at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1082)rn at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1067)rn at org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:73)rn at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:33)rn ... 16 morern配置信息hibernate.cfg.xml如下:rnrnrnrnrn rn rn com.mysql.jdbc.Driverrn jdbc:mysql://localhost:3306/MyProjectrn rootrn rootrn rn 1rn rn org.hibernate.dialect.MySQLDialectrn rn threadrn rn org.hibernate.cache.NoCacheProviderrn rn truern rn creatern rn rn rnrn配置信息user.hbm.xml如下:rnrnrn rnrnrn rn rn rn rn rn rn rn rn rn rn测试程序test.java如下:rnpackage hyq03.hibernate;rnimport org.hibernate.HibernateException;rnimport org.hibernate.Session;rnimport org.hibernate.SessionFactory;rnimport org.hibernate.Transaction;rnimport org.hibernate.cfg.Configuration;rnrnpublic class Testrnrn public static void main(String[] args)rn rn tryrn SessionFactory sf=new Configuration().configure().buildSessionFactory();rn Session session=sf.openSession();rn Transaction tx=session.beginTransaction();rn User user=new User();rn //user.setId(2);rn user.setUsername("hibernate");rn user.setPassword("123");rn //user.setEmail("hibernate@hbnt");rn session.save(user);rn tx.commit();rn session.close();rn rn catch(HibernateException e)rn rn e.printStackTrace();rn rn rnrnrn
Hibernate连接Mysql的8小时问题
这个问题估计是用mysql建立网站都会碰到的。 每天早上起来打开网页, 就会看到这个问题。。 原因是mysql有一个time_out全局值, 这个值是28800, 也就是28800秒,正好是8小时。8个小时之后会断开连接, 然后jdbc的Connection就需要重新连接才行。 在mysql中运行:show global variables like 'wait_timeout';就可以...
hibernate数据查询 mysql timedata 问题
本人新手 在hibernate SQL语句查询timedate时出现了问题rn SQLQuery sqlQuery = session.createSQLQuery("select * from yx_user where DATE_FORMAT(yx_last_login, '%y-%M-%d') = CURDATE()");rn我想取出今天登陆的用户集合 但是集合size始终是0 并且没有报错;rn 但是在mysql中直接输入这条sql语句能查出来 这是什么问题
spring,hibernate,mysql的中文问题?
我用spring,hibernate,mysql4.1,用jsp显示数据库的数据(一个简单例子)。rn在jsp中加了rn<%@ page contentType="text/html; charset=UTF-8"%>rn后页面中中文能正常显示,但是数据库中的中文是乱码,只有用rnnew String(emp.getEmployeeName().getBytes("ISO-8859-1"), "gb2312") 才能在jsp中正常显示中文!!!!!rn而且spring配置datasource是如何加上rnuseUnicode\=true&characterEncoding\=gb2312???rn我加了,spring报错!!!
hibernate和mysql的缓存问题,没辙了!
    各位大侠好,我的hibernate出了很严重的问题,我用的数据库是mysql,大家请看下面这段代码,我每次已经把值正确插入到数据库后,下面的这个方法查询出来的还是旧数据,等页面刷新好几次后才查询出新的数据,有时候刷新一会是新的数据一会是旧的数据。rnrn  上面的方法改为这个后就没问题,就是每次都重新创建新的session工厂rnrn   请问这个是怎么回事呢,程序中好多处都是这个问题,我的二级缓存已经关了rn   rnrn   问题补充: 我的SessionBuilder.getSession();应该没问题的,我曾经也用了hibernate自动生成的得到session的方法,目前用的这个Thread模式 问题补充: 首先感谢大家的回答,我的插入有事物,每次插入完成后都有flush,而且我自己在数据库里面修改一个字段刷新页面好几次才能得到新数据。至于什么数据库隔离级别我不太懂啊,但是应该和那没关系。r 我自己的写的测试方法在类的main方法里面执行的时候,一直不会出现过期数据,很奇怪。
在hibernate里连接mysql的问题
我在点test driver 的时候,蹦出来一个窗口说 rnError while performing database login with the mysqldriver driverrnUnable to create connection. check your URL.rnrn我的connection是这样设置的: jdbc:mysql://localhost:3306:MySQL。哪里出来问题啊?在线等,谢谢拉。
相关热词 c#入门推荐书 c# 解码海康数据流 c# xml的遍历循环 c# 取 查看源码没有的 c#解决高并发 委托 c#日期转化为字符串 c# 显示问号 c# 字典对象池 c#5.0 安装程序 c# 分页算法