你在hibernate.cfg.xml里配置把sql打印出来放到Mysql里执行一下不就知道了。Column 'id0_0_' not found
解决方案 »
- Resin 自动关闭
- 请教Hibernate 及 Spring 事务配置问题
- EJB为服务端开发引入了快速应用开发(RAD)模型。这句话什么意思?
- 如何在jsp页中将字段值作为初值赋给文本域?
- 在JAVA中通过代理访问网络有那些方法?
- 请教struts连接ms sql
- 初学hibernate和Struts不知哪位大哥有Hibernate+Struts的例子?
- 为什么我安装了jdk1.3了 运行会出现这样是错误呢?
- 如何获取泛型接口的方法返回值类型?
- Response{protocol=http/1.1, code=400, message=, url=http:xxxxx
- tomcat问题
- 求一道笔试题答案
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" ><hibernate-mapping package="model">
<class
name="Student"
table="student"
>
<meta attribute="sync-DAO">false</meta>
<id
name="Id"
type="string"
column="id"
>
<generator class="uuid.hex"/>
</id> <property
name="Name"
column="Name"
type="string"
not-null="true"
length="10"
/>
<property
name="Age"
column="Age"
type="java.lang.Byte"
not-null="false"
length="4"
/>
</class>
<sql-query callable="true" name="getAllInfo">
<return alias="student" class="model.Student">
<return-property name="Name"
column="Name"></return-property>
<return-property name="Age"
column="Age"></return-property>
</return>
{CALL GetAllinfo()}
</sql-query>
</hibernate-mapping>
*.cfg.xml如下:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration
PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"><hibernate-configuration>
<session-factory > <!-- local connection properties -->
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/schoolproject</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">800613</property>
<!-- property name="hibernate.connection.pool_size"></property --> <!-- dialect for MySQL -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property> <property name="hibernate.show_sql">true</property>
<property name="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
<mapping resource="model/Student.hbm.xml"/>
</session-factory>
</hibernate-configuration>*.java如下
package testhibernate;import java.util.List;import org.hibernate.*;
import org.hibernate.cfg.*;
import org.hibernate.classic.Session;import model.Student;public class TestHibernate { /**
* @param args
*/
public static void main(String[] args) {
// TODO 自动生成方法存根 try{
SessionFactory sf = new Configuration().configure().buildSessionFactory();
Session session = sf.openSession();
// Transaction tx = session.beginTransaction();
Query query = session.getNamedQuery("getAllInfo");
List su = query.list();
for (int i=0;i<su.size();i++){
Student st = (Student) su.get(i);
// st.setName("学生"+i);
// st.setAge("22");
// session.save(st);
System.out.println(st.getName()+"\t"+st.getAge());
}
// tx.commit();
session.close();
System.out.println("数据chaxun成功");
}catch(HibernateException e){
e.printStackTrace();
}
}}