hibernate配置文件贴出来压,这样怎么看
解决方案 »
- 如何将网站用户和电脑绑定?即一机一码
- 怎样才能dtd文件放到myeclipse创建的项目中
- j2ee系统 点击登录后,点浏览器后退按钮又回到登录页面,然后再点前进又进入系统,这样很不安全
- SSH2配置好后启动tomcat报错,
- N个struts2.1.8问题
- 你好 我想问下关于Gigaspaces的事情
- 菜鸟!!求救!没见这个异常javax.servlet.ServletException: class "org.apache.commons.collections.SequencedHashMap"'s signer information does n
- 请教axis2如何在weblogic8.1下部署,急~
- 有人知道 怎么用jtable显示 表格内数据的合计或者列数吗?像dbgrid中合计行那样的,或者其他的解决方案 100分
- 谁有dom4j的文档?发给我看看
- 求助:如何用java web start + tomcat + oracle + application设计学生管理系统
- 初学struts遇难题,高分求救
不过配置多不会错的,因为我是用Myeclipse自动生成的Cat.hbm.xml和hibernate.cfg.xml!
当:
SQLQuery sq=s.createSQLQuery("from test.cat");
Iterator i=sq.list().iterator();
i怎么搞多是NULL。数据库是Mysql。且里面有数据。
不知道为什么!
改为
Configuration conf=new Configuration().configure();试试
原来就是Configuration conf=new Configuration().configure();
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"><!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration>
<session-factory>
<property name="myeclipse.connection.profile">zxr</property>
<property name="connection.url">
jdbc:mysql://localhost:3306/test
</property>
<property name="connection.username">root</property>
<property name="connection.password">0555243000</property>
<property name="connection.driver_class">
com.mysql.jdbc.Driver
</property>
<property name="dialect">
org.hibernate.dialect.MySQLDialect
</property>
<mapping resource="test/Cat.hbm.xml" />
</session-factory>
</hibernate-configuration>
Cat.hbm.xml:<?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" ><!-- DO NOT EDIT: This is a generated file that is synchronized -->
<!-- by MyEclipse Hibernate tool integration. -->
<!-- Created Mon Sep 19 15:52:42 CST 2005 -->
<hibernate-mapping package="test"> <class name="Cat" table="cat">
<id name="username" column="username" type="java.lang.String">
<generator class="increment"/>
</id>
<property name="userpassword" column="userpassword" type="java.lang.String" />
</class>
</hibernate-mapping>
测试类:
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.SQLQuery;
import org.hibernate.Query;
import org.hibernate.HibernateException;
import java.util.Iterator;
import java.util.List;
import test.*;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Logger;
import org.hibernate.Transaction;public class test {
public static void main(String args[]){
Iterator ite=null;
String str="failure";
List l=null;
Query q=null;
SessionFactory sf;
Session s=null;
Transaction t=null;
Configuration conf=null;
BasicConfigurator.configure();
try{
conf = new Configuration();
conf.configure();
sf=conf.buildSessionFactory();
s=sf.openSession();
t=s.beginTransaction();
q=s.createQuery("from cat");
ite=q.iterate();
t.commit();
System.out.print("\n\nok\n\n");
}catch(HibernateException he){}
System.out.print(ite);
}
}
错误信息:......
7968 [main] DEBUG org.hibernate.hql.ast.ErrorCounter - throwQueryException() : no errors
8047 [main] DEBUG org.hibernate.hql.antlr.HqlSqlBaseWalker - query() << begin, level = 1
8109 [main] ERROR org.hibernate.hql.PARSER - *** ERROR: cat is not mapped.
8109 [main] DEBUG org.hibernate.hql.ast.ErrorCounter - cat is not mapped.
cat is not mapped.
at org.hibernate.hql.ast.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:85)
at org.hibernate.hql.ast.FromElementFactory.addFromElement(FromElementFactory.java:77)
at org.hibernate.hql.ast.FromClause.addFromElement(FromClause.java:67)
at org.hibernate.hql.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:217)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:2830)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:2719)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:513)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:371)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:201)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:151)
at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:189)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:130)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:83)
at org.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:427)
at org.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:884)
at org.hibernate.impl.SessionImpl.iterate(SessionImpl.java:920)
at org.hibernate.impl.QueryImpl.iterate(QueryImpl.java:41)
at test.main(test.java:35)
8125 [main] DEBUG org.hibernate.hql.antlr.HqlSqlBaseWalker - query() : finishing up , level = 1
8125 [main] DEBUG org.hibernate.hql.ast.HqlSqlWalker - processQuery() : ( SELECT FromClause{level=1} )
8140 [main] DEBUG org.hibernate.hql.ast.HqlSqlWalker - Derived SELECT clause created.
8187 [main] DEBUG org.hibernate.hql.antlr.HqlSqlBaseWalker - query() >> end, level = 1
8187 [main] DEBUG org.hibernate.hql.ast.AST - --- SQL AST ---
\-[SELECT] QueryNode: 'SELECT'
+-[SELECT_CLAUSE] SelectClause: '{derived select clause}'
\-[FROM] FromClause: 'from' FromClause{level=1, fromElementCounter=0, fromElements=0, fromElementByClassAlias=[], fromElementByTableAlias=[], fromElementsByPath=[], collectionJoinFromElementsByPath=[], impliedElements=[]}null
cat应该是那个类的名字要大写Cat你写成这样看看("from Cat as hello")
hello可随意 其它地方你就慢慢找啊
Query sq=s.createQuery("from Cat");
Iterator i=sq.list().iterator();
如果是
SQLQuery sq=s.createSQLQuery("select c.username as name,c.userpassword as password from Cat c").addEntity("c",Cat.class);
Iterator i=sq.list().iterator();
就会出现column uername0_ not found 错误。