国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

java - 為什么hibernate查詢(xún)表集報(bào)錯(cuò)?

瀏覽:195日期:2024-01-09 13:11:04

問(wèn)題描述

import java.util.List;import org.hibernate.Query;import org.hibernate.Session;import org.hibernate.SessionFactory;import org.hibernate.Transaction;import org.hibernate.cfg.Configuration;import qiye.Impl.ServiceDaoImpl;import qiye.entity.Contact;import qiye.entity.Service;public class TestJava { private static SessionFactory sessionFactory; static{Configuration configuraction = new Configuration().configure();sessionFactory = configuraction.buildSessionFactory(); } public static Session getSession(){return sessionFactory.openSession(); } public static List<Contact> getContactList(){Session s = null;List<Contact> list = null;try{ s = TestJava.getSession(); Query query = s.createQuery('from Service'); list = query.list(); for(Contact contact : list){System.out.println(contact.getAddress()); }}catch(Exception e){ e.printStackTrace();}finally{ if(s!=null){ s.close(); }}return list; }public static void main(String[] arg){TestJava.getContactList();System.out.println('hello'); }}

報(bào)錯(cuò)信息:

三月 29, 2017 4:49:54 下午 org.hibernate.Version logVersionINFO: HHH000412: Hibernate Core {5.2.7.Final}三月 29, 2017 4:49:54 下午 org.hibernate.cfg.Environment <clinit>INFO: HHH000206: hibernate.properties not found三月 29, 2017 4:49:54 下午 org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>INFO: HCANN000001: Hibernate Commons Annotations {5.0.1.Final}三月 29, 2017 4:49:54 下午 org.hibernate.boot.jaxb.internal.stax.LocalXmlResourceResolver resolveEntityWARN: HHH90000012: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/hibernate-mapping. Use namespace http://www.hibernate.org/dtd/hibernate-mapping instead. Support for obsolete DTD/XSD namespaces may be removed at any time.三月 29, 2017 4:49:55 下午 org.hibernate.boot.jaxb.internal.stax.LocalXmlResourceResolver resolveEntityWARN: HHH90000012: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/hibernate-mapping. Use namespace http://www.hibernate.org/dtd/hibernate-mapping instead. Support for obsolete DTD/XSD namespaces may be removed at any time.三月 29, 2017 4:49:55 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configureWARN: HHH10001002: Using Hibernate built-in connection pool (not for production use!)三月 29, 2017 4:49:55 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreatorINFO: HHH10001005: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost:3306/qiye?useUnicode=true&characterEncoding=UTF-8]三月 29, 2017 4:49:55 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreatorINFO: HHH10001001: Connection properties: {user=root, password=****}三月 29, 2017 4:49:55 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreatorINFO: HHH10001003: Autocommit mode: false三月 29, 2017 4:49:55 下午 org.hibernate.engine.jdbc.connections.internal.PooledConnections <init>INFO: HHH000115: Hibernate connection pool size: 20 (min=1)三月 29, 2017 4:49:55 下午 org.hibernate.dialect.Dialect <init>INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect三月 29, 2017 4:49:56 下午 org.hibernate.resource.transaction.backend.jdbc.internal.DdlTransactionIsolatorNonJtaImpl getIsolatedConnectionINFO: HHH10001501: Connection obtained from JdbcConnectionAccess [org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess@345c5f] for (non-JTA) DDL execution was not in auto-commit mode; the Connection ’local transaction’ will be committed and the Connection will be set into auto-commit mode.三月 29, 2017 4:49:56 下午 org.hibernate.hql.internal.QueryTranslatorFactoryInitiator initiateServiceINFO: HHH000397: Using ASTQueryTranslatorFactoryHibernate: selectservice0_.ID as ID1_1_,service0_.TITLE as TITLE2_1_ fromSERVICE service0_java.lang.ClassCastException: qiye.entity.Service cannot be cast to qiye.entity.Contact at TestJava.getContactList(TestJava.java:33) at TestJava.main(TestJava.java:47)hello

這是怎么回事啊?

問(wèn)題解答

回答1:

List<Contact> list = null;

Query query = s.createQuery('from Service');list = query.list();

你的list里面是Contact,但是你查詢(xún)的是Service,類(lèi)型不匹配造成的,如果你確認(rèn)查詢(xún)的就是Service,改成List<Service>就行了

回答2:

集合泛型List<Contact>,在擦除之后就沒(méi)有類(lèi)型了,因此,在這里定義的集合類(lèi)型需要與結(jié)果類(lèi)型一致,泛型之間不存在多態(tài)

標(biāo)簽: java
相關(guān)文章:
主站蜘蛛池模板: 成人a视频 | 久草热线视频 | 亚洲精品一区二区在线播放 | av片免费大全在线观看不卡 | 国产一区二区三区不卡免费观看 | 男女视频免费在线观看 | 一区二区三区四区在线播放 | 成人免费看黄网址 | 亚洲国产日韩欧美高清片a 亚洲国产日韩欧美在线 | 青草久久网| 日本三级欧美三级人妇英文 | 成人国产精品一区二区网站 | 草草影院视频 | 人人99| 久草视频在线首页 | 久久93精品国产91久久综合 | 国产精品国产三级国产专区5o | 欧美在线一级视频 | 在线精品亚洲欧洲第一页 | 免费高清欧美一区二区视频 | 成年人在线免费观看视频网站 | 国产1区2区三区不卡 | 午夜在线精品不卡国产 | 久久亚洲国产精品一区二区 | 亚洲精品第五页中文字幕 | 免费一级肉体全黄毛片 | 高清在线精品一区二区 | 亚洲欧美日韩国产vr在线观 | 国产性精品 | 精品国产日韩亚洲一区二区 | 午夜a一级毛片一.成 | 欧洲做人爱c欧美 | 黑人特黄aa毛片 | 欧美日韩国产片 | 欧美精品亚洲精品日韩 | 亚洲国产欧美一区二区欧美 | 成人久久在线 | 日韩一级片免费看 | 波多野结衣免费观看视频 | 欧美日韩综合网在线观看 | 成人毛片免费视频播放 |