createQuery("from UserInfoVO");为什么不是createQuery("from UserInfo");哪来的UserInfoVO类
解决方案 »
- hibernate中的lazy与fetch有什么区别
- MySQL死了?
- 如何用JAVA代码查看文件夹中的变化
- cookie无法创建~~急在线等,,,请各位大侠帮忙!
- jsf+hibernate+spring
- forEach嵌套取值 明细是多条的请问怎么取出
- 自由电子档《剖析Webwork源码》下载,多提意见!
- ++++++++++++++++++ Apache 2.0.54 Tomcat 5.5.12 整合 ++++++++++++++++++++++
- 难道CSDN上就没有一个人能回答这个问题吗?
- 新手:实体bean相当于数据对数据层的抽象,会话bean相当于业务逻辑,是这样的吗?
- 更新SQL Server 2005 blob字段的奇怪问题
- 一个关于如何在jsp页面间传值的问题
小弟初学Hibernate,对hql不清楚,在一遍文章上看到说from后面的是一个pojo类名不是数据库中的table名称
<class name="UserInfoVO" table="user">
<id name="id" type="java.lang.Integer" column="id">
<!-- 主键产生方式 -->
<generator class="increment" />
</id>
<property name="userName" type="java.lang.String" length="10"/>
<property name="password" type="java.lang.String"
column="password"
length="10"/>
<property name="popedom"type="java.lang.String"
column="popedom"
length="10"/>
</class>
</hibernate-mapping>
public class UserInfoVO implements Serializable{
private Integer id;
private String userName;
private String password;
private String popedom;
public UserInfoVO(){}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
以下省略....
做个简单的查询,目的是测试你的hibernate 数据库连接是否正确
如果正确在研究 UserInfoVO.hbm.xml和 UserInfoVO 你的 UserInfoVO 要写出有参数的构造方法
那么应该是from UserInfo而不是UserInfoVO.
Hibernate: select userinfovo0_.id as id, userinfovo0_.userName as userName, userinfovo0_.password as password, userinfovo0_.popedom as popedom from user userinfovo0_
小异: Could not execute query
UserInfo这个类查
配置文件:
<?xml version='1.0' encoding='UTF-8'?>
<!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="show_sql">true</property>
<property name="connection.url">
jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=fileUp
</property>
<property name="connection.username">sa</property>
<property name="connection.password"></property>
<property name="dialect">
org.hibernate.dialect.SQLServerDialect
</property>
<property name="connection.driver_class">
com.microsoft.jdbc.sqlserver.SQLServerDriver
</property>
<!--映射文件-->
<mapping resource="UserInfo.hbm.xml" />
</session-factory>
</hibernate-configuration>UserInfo.hbm.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" ><hibernate-mapping>
<class name="UserInfoVO" table="user">
<id name="id" type="java.lang.Integer"
column="id">
<!-- 主键产生方式 -->
<generator class="increment" />
</id>
<property name="userName"
type="java.lang.String"
length="10"/>
<property name="password" type="java.lang.String"
column="password" length="10"/>
<property name="popedom" type="java.lang.String"
column="popedom" length="10"/>
</class>
</hibernate-mapping> import java.util.List;
import net.sf.hibernate.Query;
import net.sf.hibernate.SessionFactory;
import net.sf.hibernate.Session;
import net.sf.hibernate.Transaction;
import net.sf.hibernate.cfg.Configuration;public class HibernateDemo {
/**
* @param args
*/
Configuration cfg;
SessionFactory sf;
Session session;
public static void main(String[] args) {
// TODO Auto-generated method stub
try{
HibernateDemo demo=new HibernateDemo();
System.out.println("size: "+demo.getUserInfo().size());
}
catch(Exception e){
System.out.println("小异: "+e.getMessage());
}
}
public List getUserInfo() throws Exception{
List lt=null;
cfg=new Configuration().configure();
sf=cfg.buildSessionFactory();
session=sf.openSession();
Transaction tx=session.beginTransaction();
Query query=session.createQuery("from UserInfoVO");
lt=query.list();
tx.commit();
session.close();
return lt;
}
}
import java.io.Serializable;
public class UserInfoVO implements Serializable{
private Integer id;
private String userName;
private String password;
private String popedom;
public UserInfoVO(){}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getPopedom() {
return popedom;
}
public void setPopedom(String popedom) {
this.popedom = popedom;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
}
把<!-- 主键产生方式 -->
<generator class="increment" />
</id>
中class换一下,
<generator class="native"></generator>