hql hibernate on a problem ....

2010-04-02  来源:本站原创  分类:Java  人气:308 

In hibernate hql statement in the following error: Exception in thread "main" java.lang.IllegalStateException: No data type for node: org.hibernate.hql.ast.tree.IdentNode \ - [IDENT] IdentNode: 'sno' ( originalText = sno)
(
SessionFactory sf = new Configuration (). Configure ()
. BuildSessionFactory ();
Session session = sf.openSession ();
/ / String hql = "from Student s where s.sdept in (select s.sdept from s where s.sname = 'Joe Smith')";
String hql = "from Student s where s.sno in (select sno from Sc where cno = '1 ')";
Query query = session.createQuery (hql);
List list = query.list ();
Iterator it = list.iterator ();
while (it.hasNext ())
(
Student stu = (Student) it.next ();
System.out.println (stu.getSname () + "\ t" + stu.getSdept ());
)
)

Open Sc.hbm.xml found no sno property, which reads: <? Xml version = "1.0" encoding = "utf-8"?>
<! DOCTYPE hibernate-mapping PUBLIC "- / / Hibernate / Hibernate Mapping DTD 3.0 / / EN"
"Http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<! -
Mapping file autogenerated by MyEclipse Persistence Tools
->
<hibernate-mapping>
<class name="com.yan.hibernate.Sc" table="sc" catalog="lrdatabase">
<id name="id" type="java.lang.Integer">
<column name="id" />
<generator />
</ Id>
<many-to-one name="course" fetch="select">
<column name="cno" />
</ Many-to-one>
<many-to-one name="student" fetch="select">
<column name="sno" />
</ Many-to-one>
<property name="grade" type="java.lang.Integer">
<column name="grade" />
</ Property>
</ Class>
</ Hibernate-mapping>

[Color = darkred] The solution is:
The hql statement read: String hql = "from Student s where s.sno in (select student.sno from Sc where cno = '1')";[/ color]
Building a database table as follows: the database set up three tables student, course, sc table, the relationship is the foreign key sno sc corresponds to the student table sno, sc in the foreign key correspond to the course in the cno cno , the process of building the table are:
/ *
MySQL Data Transfer
Source Host: localhost
Source Database: lrdatabase
Target Host: localhost
Target Database: lrdatabase
Date: 2010-4-2 15:49:33
* /

SET FOREIGN_KEY_CHECKS = 0;
- ----------------------------
- Table structure for course
- ----------------------------
CREATE TABLE `course` (
`Id` int (10) NOT NULL AUTO_INCREMENT,
`Cno` int (10) DEFAULT NULL,
`Cname` varchar (50) CHARACTER SET utf8 DEFAULT NULL,
`Ccredit` int (11) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `cno` (`cno`)
) ENGINE = InnoDB AUTO_INCREMENT = 4 DEFAULT CHARSET = gbk;

- ----------------------------
- Table structure for sc
- ----------------------------
CREATE TABLE `sc` (
`Id` int (10) NOT NULL AUTO_INCREMENT,
`Sno` int (10) DEFAULT NULL,
`Cno` int (10) DEFAULT NULL,
`Grade` int (10) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `sno` (`sno`),
KEY `cno` (`cno`),
CONSTRAINT `sc_ibfk_1` FOREIGN KEY (`sno`) REFERENCES `student` (`sno`),
CONSTRAINT `sc_ibfk_2` FOREIGN KEY (`cno`) REFERENCES `course` (`cno`)
) ENGINE = InnoDB AUTO_INCREMENT = 2 DEFAULT CHARSET = gbk;

- ----------------------------
- Table structure for student
- ----------------------------
CREATE TABLE `student` (
`Id` int (10) NOT NULL AUTO_INCREMENT,
`Sno` int (10) DEFAULT NULL,
`Sname` varchar (20) CHARACTER SET utf8 DEFAULT NULL,
`Ssex` varchar (2) CHARACTER SET utf8 DEFAULT NULL,
`Sdept` varchar (10) CHARACTER SET utf8 DEFAULT NULL,
`Sage` int (10) DEFAULT NULL,
`Saddress` varchar (50) CHARACTER SET utf8 DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `sno` (`sno`)
) ENGINE = InnoDB AUTO_INCREMENT = 4 DEFAULT CHARSET = gbk;

- ----------------------------
- Table structure for user
- ----------------------------
CREATE TABLE `user` (
`Id` int (11) NOT NULL AUTO_INCREMENT,
`Name` varchar (20) CHARACTER SET utf8 DEFAULT NULL,
`Password` varchar (20) CHARACTER SET utf8 DEFAULT NULL,
`Phonetype` tinyint (11) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE = InnoDB AUTO_INCREMENT = 18 DEFAULT CHARSET = gbk;

- ----------------------------
- Records
- ----------------------------
INSERT INTO `course` VALUES ('1 ', '1', 'database', '2 ');
INSERT INTO `course` VALUES ('2 ', '2', 'operating system', '2 ');
INSERT INTO `course` VALUES ('3 ', '3', 'Software Engineering', '3 ');
INSERT INTO `sc` VALUES ('1 ', '1', '1 ', '86');
INSERT INTO `student` VALUES ('1 ', '1', 'Joe Smith', 'M', 'computer', '20 ',' Beijing ');
INSERT INTO `student` VALUES ('2 ', '2', 'John Doe', 'F', 'computer', '21 ',' Hebei ');
INSERT INTO `student` VALUES ('3 ', '3', 'King 5', 'F', 'law', '20 ',' Beijing ');
INSERT INTO `user` VALUES ('9 ',' John Doe ', '1', '1 ');
INSERT INTO `user` VALUES ('10 ',' King 5 ', '1', '1 ');
INSERT INTO `user` VALUES ('11 ',' Hello. ', '1', '2 ');
INSERT INTO `user` VALUES ('12 ',' Hello. ',' Aaa ', '1');
INSERT INTO `user` VALUES ('13 ',' hello ',' aaa ', '1');
INSERT INTO `user` VALUES ('14 ',' hello ',' a ', '1');
INSERT INTO `user` VALUES ('15 ',' hsdfgdsg ', '3242', '1 ');
INSERT INTO `user` VALUES ('16 ',' safdasaswerewrw ', '3242', '1 ');
INSERT INTO `user` VALUES ('17 ',' erewrw ', '3242', '1 ');

相关文章
  • hql hibernate on a problem .... 2010-04-02

    In hibernate hql statement in the following error: Exception in thread "main" java.lang.IllegalStateException: No data type for node: org.hibernate.hql.ast.tree.IdentNode \ - [IDENT] IdentNode: 'sno' ( originalText = sno) ( SessionFactory sf = n

  • HQL: Hibernate Query Language 2009-08-07

    HQL: Hibernate Query Language

  • HQL: Hibernate Query Language (Transfer from the official website) 2009-09-04

    HQL: Hibernate Query Language (Transfer from the official website) Chapter 15 HQL: Hibernate Query Language Hibernate is equipped with a very powerful query language, this language looks very much like SQL. Grammatical structure but do not be fooled

  • json-lib hibernate lazy loading problem 2010-10-07

    json-lib hibernate lazy loading problem ------ Question: Using json-lib to hibernate lazy loading of objects into a json when session closed packet error ------ Address: Can use json-lib's JsonConfig filter out unwanted properties, using the apply me

  • HQL: Hibernate查询语言 2013-05-26

    Hibernate配备了一种非常强大的查询语言,这种语言看上去很像SQL.但是不要被语法结构 上的相似所迷惑,HQL是非常有意识的被设计为完全面向对象的查询,它可以理解如继承.多态 和关联之类的概念. 第 15 章 HQL: Hibernate查询语言 Hibernate配备了一种非常强大的查询语言,这种语言看上去很像SQL.但是不要被语法结构 上的相似所迷惑,HQL是非常有意识的被设计为完全面向对象的查询,它可以理解如继承.多态 和关联之类的概念. 15.1. 大小写敏感性问题 除了Java类

  • weblogic10.3 hibernate3 org.hibernate.hql.ast.HqlToken error problem 2010-12-23

    struts2 + hibernate3.5.6 + spring3.03 applications to weblogic10.3 under, in the run weblogic10.3 found that the original run properly in the proper application tomcat6 not used in the development tools found in Throws: org.springframework.orm.hibern

  • Hibernate's query problem createSQLQuery 2009-06-05

    We use HQL subquery, when carried out, such as select * from Tree where pid in (select id from Tree, this time HIBERANTE will get an error, saying that asterisk wrong category. But if you * read inside the Tree class All sub-paragraph, there would be

  • Spring + Hibernate, CRD no problem, update invalid?? 2009-03-29

    Yes my spring2.5.6 + hibernte3.3, did not use spring and hibernateTemplate the HibernateDaoSupport, only its AnnotationSessionFactoryBean, Tim censored search do not have any problem, as long as one update on the invalid, the console is not error. I

  • Hibernate many-to-many delete problem 2009-04-09

    Hibernate many-to-many, many examples, but one look carefully, most of them are saved, delete the small talk, but there are still many problems, so has the need for a simple test, here we come to a simple set up many-to-many relationship Teacher and

  • [Change] hibernate n +1 problem 2010-04-06

    Hibernate frequently used set, bag and so on for 1 set of multiple relationships when the entity in obtaining relations between them according to the associated object or object set out, can also set cacade associate the update and delete. This is no

  • Hibernate handle the problem of large data 2010-05-07

    Resolve data-intensive problems I think the most important points : 1. Even if you clear the cache In handling large amounts of data, the data is saved in the buffer Session The L1 cache, the cache is too large to display performance when serious , A

  • Detailed hibernate lazy loading problem 2010-10-03

    Lazy loading: Lazy loading mechanism is to avoid unnecessary performance overhead of their argument, the so-called lazy loading is when the really need the data before it will actually perform the data loading operation. Provided in the Hibernate obj

  • hibernate entity mapping problem of naming 2010-11-12

    Comments during the entity configured today, always get an error saying can not find in the corresponding table in the database, and can not find the table shows added underscores, for example, UserInfo entities, there are attributes userName, it wil

  • spring + struts2 + hibernate + freemarker configuration problem again Summary 2010-11-20

    web container: tomcat5/tomcat6 jdk version: jdk1.6 spring version: 3.05 struts version: 2.1.6 hibernate version: 3.6 freemarker version: 2.3.16 All the jar packages are as follows: Configuration process took longer, often encountered lack of class an

  • Hibernate cascade save problem solving 2011-04-28

    A bill, a bill for details. Details of bills and bill-to-many relationship. Save time, reported the bill details of bill issue id is empty. Cause of the problem: Save the way hibernate cascade A. First save the parent. B. then save the sub-class, the

  • Since growth on the Hibernate access id problem 2011-01-09

    Access in oracle process of change that id from the original growth can not, insert the data is not successful, <id name="id" type="int"> <column name="DBS_ID" /> <generator /> </ Id> Open access datab

  • spring hibernate transaction management problem does not automatically flush 2011-01-14

    Configure services in the spring: Quote <bean> <property name="sessionFactory" ref="sessionFactory" /> </ Bean> <context:annotation-config/> <! - Use annotation definition of transaction -> <tx:annotati

  • Hibernate HQL Summary 2010-03-22

    HQL (Hibernate Query Language): is the object-oriented query, and its syntax and some similar SQL statements, only to be resolved at runtime. HQL is not as SQL as a data manipulation language, it is used to achieve the object, rather than to update,

  • Hibernate unable to obtain a record insert data problem tossing jdbc 2010-09-22

    Roughly as follows Front: struts2 + spring3 + hibernate3 + mysql database used to obtain data on the page, contains a small amount of data updates. Back: jdbc + mysql to receive a client data sent (socket communication), and stored in the database fo

  • hibernate hql实用教程 2012-12-29

    Hibernate配备了一种非常强大的查询语言,这种语言看上去很像SQL.但是不要被语法结构 上的相似所迷惑,HQL是非常有意识的被设计为完全面向对象的查询,它可以理解如继承.多态 和关联之类的概念. 第 15 章 HQL: Hibernate查询语言 Hibernate配备了一种非常强大的查询语言,这种语言看上去很像SQL.但是不要被语法结构 上的相似所迷惑,HQL是非常有意识的被设计为完全面向对象的查询,它可以理解如继承.多态 和关联之类的概念. 15.1. 大小写敏感性问题 除了Java类