Hibernate错误

1

Exception in thread "main" org.hibernate.HibernateException: 'hibernate.dialect' must be set when no Connection available

	at org.hibernate.dialect.resolver.DialectFactory.buildDialect(DialectFactory.java:106)
	at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:152)
	at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2833)
	at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2829)
	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1840)
	at Test.main(Test.java:17)

解决:Configuration con =  new Configuration();改为:

  Configuration con =  new Configuration().configure();

因为configure()指定一个cfg.xml文件,从文件中加载hibernate配置

2

 

Exception in thread "main" org.hibernate.MappingException: Could not instantiate id generator [entity-name=com.hsp.domain.Employee]
	at org.hibernate.id.factory.DefaultIdentifierGeneratorFactory.createIdentifierGenerator(DefaultIdentifierGeneratorFactory.java:118)
	at org.hibernate.mapping.SimpleValue.createIdentifierGenerator(SimpleValue.java:193)
	at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:246)
	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1842)
	at Test.main(Test.java:17)
Caused by: org.hibernate.MappingException: Could not interpret id generator strategy [Increment]
	at org.hibernate.id.factory.DefaultIdentifierGeneratorFactory.getIdentifierGeneratorClass(DefaultIdentifierGeneratorFactory.java:137)
	at org.hibernate.id.factory.DefaultIdentifierGeneratorFactory.createIdentifierGenerator(DefaultIdentifierGeneratorFactory.java:108)
	... 4 more

 因为数据库方言不支持Increment这样用,如果在Oracle中使用Sequence即可,MySQL中应该改为 native

3.

 

xxx is not mapped

说明HQL中写错了,或者hbm.xml中写错了

需要把HQL中from后面的列名改为hbm.xml映射的对象名称

4.

org.hibernate.exception.GenericJDBCException: could not execute query
	at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
	at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
	at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
	at org.hibernate.loader.Loader.doList(Loader.java:2223)
	at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
	at org.hibernate.loader.Loader.list(Loader.java:2099)
	at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:378)
	at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
	at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
	at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
	at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
	at org.ds.dao.SourcedirDAO.getRoot(SourcedirDAO.java:226)
	at org.ds.util.XMLHandler.createXMLDocument(XMLHandler.java:72)
	at org.ds.util.XMLHandler.createXMLFile(XMLHandler.java:119)
	at org.ds.util.GenXMLPlugin.init(GenXMLPlugin.java:48)
	at org.apache.struts.action.ActionServlet.initModulePlugIns(ActionServlet.java:869)
	at org.apache.struts.action.ActionServlet.init(ActionServlet.java:336)
	at javax.servlet.GenericServlet.init(GenericServlet.java:258)
	at weblogic.servlet.internal.ServletStubImpl$ServletInitAction.run(ServletStubImpl.java:1099)
	at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
	at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
	at weblogic.servlet.internal.ServletStubImpl.createServlet(ServletStubImpl.java:975)
	at weblogic.servlet.internal.ServletStubImpl.createInstances(ServletStubImpl.java:954)
	at weblogic.servlet.internal.ServletStubImpl.prepareServlet(ServletStubImpl.java:893)
	at weblogic.servlet.internal.ServletStubImpl.reloadServlet(ServletStubImpl.java:804)
	at weblogic.servlet.internal.ServletStubImpl.checkForReload(ServletStubImpl.java:762)
	at weblogic.servlet.internal.ServletStubImpl.getServlet(ServletStubImpl.java:602)
	at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:406)
	at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:28)
	at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:27)
	at org.ds.util.MyFilter.doFilter(MyFilter.java:121)
	at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:27)
	at org.ds.util.SysLogFilter.doFilter(SysLogFilter.java:56)
	at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:27)
	at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:7053)
	at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
	at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
	at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3902)
	at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2773)
	at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:224)
	at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:183)
Caused by: java.sql.SQLException: Io 异常: Software caused connection abort: recv failed
	at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
	at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
	at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:255)
	at oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreparedStatement.java:977)
	at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1060)
	at oracle.jdbc.driver.T4CPreparedStatement.executeMaybeDescribe(T4CPreparedStatement.java:839)
	at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1132)
	at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3316)
	at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3361)
	at weblogic.jdbc.wrapper.PreparedStatement.executeQuery(PreparedStatement.java:131)
	at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)
	at org.hibernate.loader.Loader.getResultSet(Loader.java:1787)
	at org.hibernate.loader.Loader.doQuery(Loader.java:674)
	at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
	at org.hibernate.loader.Loader.doList(Loader.java:2220)
	... 37 more
 间隔时间太长了,session关闭了,重新运行程序就可以了
5.
org.hibernate.QueryParameterException: could not locate named parameter [mdfileid]java.lang.NullPointerException	
	at org.ds.dao.MetadataDAO.findByMdFileId(MetadataDAO.java:233)
	at org.ds.directoryView.action.DirectoryContent.buildContent(DirectoryContent.java:84)
	at org.ds.directoryView.service.DirectoryQuery.search(DirectoryQuery.java:131)
	at org.ds.directoryView.action.DirectoryAction.execute(DirectoryAction.java:55)
	at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
	at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
	at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
	at org.ds.util.MyActionServlet.process(MyActionServlet.java:17)
	at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
	at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:1077)
	at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:465)
	at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:28)
	at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:27)
	at org.ds.util.MyFilter.doFilter(MyFilter.java:121)
	at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:27)
	at org.ds.util.SysLogFilter.doFilter(SysLogFilter.java:56)
	at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:27)
	at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:7053)
	at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
	at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
	at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3902)
	at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2773)
	at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:224)
	at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:183)

 写错了,应该把mdfiled改为id,因为占位符是id来占位的

 

String hql = "from Metadata where mdfileid= :id";
		Metadata metadata = null;
		Session session = getHibernateTemplate().getSessionFactory().openSession();
		try {
			Query query = session.createQuery(hql);
			query.setParameter("mdfileid",id);

6. No CurrentSessionContext configured!

web应用添加:
<property name="current_session_context_class">jta</property>  
java应用添加:
<property name="current_session_context_class">thread</property>  

 

7. org.hibernate.InvalidMappingException: Could not parse mapping document from resource

 解决:Domain与hbm.xml映射错误!

8.com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

解决:其实这个问题是由于mysql空闲导致断开连接的,netstat -nao查看到果然有占用着mysql的进程

关闭进程,在执行一次程序,成功解决该问题!

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值