Hibernate入门

qunqun886 qunqun886 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
如题:很简单的问题啊,小弟都弄了两天了啊,还没有搞定,
数据库ch3,表:students_table 有四个字段,ID(主键),stuName(varchar),cardId(varchar),age(int),
Student.java

package model;

/**
*
* @author Administrator
*/
public class Student {

private String name;
private String cardId;
private int age;

public Student() {
name = "";
cardId = "";
age = 0;
}

public int getAge() {
return age;
}

public void setAge(int age) {
this.age = age;
}

public String getCardId() {
return cardId;
}

public void setCardId(String cardId) {
this.cardId = cardId;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}
}
Student.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">
<hibernate-mapping>
<class dynamic-insert="false" dynamic-update="false" mutable="true" table="student_table" name="model.Student" optimistic-lock="version" polymorphism="implicit" select-before-update="false">
<id name="id" unsaved-value="null">
<generator class="uuid.hex"/>
</id>
<property name="cardId" type="String"/>
<property name="name" type="String"/>
<property name="age" type="int"/>
</class>
</hibernate-mapping>
HibernateUtil.java

package persistence;

import org.hibernate.cfg.Configuration;
import org.hibernate.SessionFactory;
import org.hibernate.*;

/**
* Hibernate Utility class with a convenient method to get Session Factory object.
*
* @author Administrator
*/
public class HibernateUtil {

private static final SessionFactory sessionFactory;


static {
try {
// Create the SessionFactory from standard (hibernate.cfg.xml)
// config file.
sessionFactory = new Configuration().configure().buildSessionFactory();
} catch (Throwable ex) {
// Log the exception.
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}

public static Session getSession() {
Session s = sessionFactory.openSession();
return s;
}

public static void closeSession(Session s) {
if (s!= null) {
s.close();
}
}
}
DAOImp.java

package persistence;


import org.hibernate.cfg.Configuration;
import org.hibernate.SessionFactory;
import org.hibernate.*;
import model.Student;

/**
* Hibernate Utility class with a convenient method to get Session Factory object.
*
* @author Administrator
*/
public class DAOImp {
static Session session=null;
//创建新的学生对象
public static void createStu(Student stu){
try{
session=HibernateUtil.getSession();
Transaction tx=session.beginTransaction();
session.save(stu);
tx.commit();
}catch(HibernateException e){
System.out.print(e.toString());
}finally{
HibernateUtil.closeSession(session);;
}
}
}
BM.java

package BusinessManager;
import persistence.*;
import model.Student;
/**
*
* @author Administrator
*/
public class BM {
public static void main(String args[]){
Student stu=new Student();
stu.setName("qunqun");
stu.setCardId("05051050218");
stu.setAge(22);
DAOImp.createStu(stu);
}
}
hibernate.cfg.xml

<?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">
<hibernate-configuration>
<session-factory>
<property name="hibernate.show_sql">true
</property>
<property name="hibernate.connection.driver_class">
com.microsoft.jdbc.sqlserver.SQLServerDriver
</property>
<property name="hibernate.connection.url">
jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=ch3
</property>
<property name="hibernate.dialect">
org.hibernate.dialect.org.hibernate.dialect.SQLServerDialect
</property>
<property name="hibernate.connection.username">
sa
</property>
<property name="hibernate.connection.password">
</property>
<mapping resource="persistence/Student.hbm.xml"/>
</session-factory>
</hibernate-configuration>
现运行错误如下:
init:
deps-module-jar:
deps-ear-jar:
deps-jar:
Copying 1 file to F:\JSP\Hibernate\build\web\WEB-INF\classes
compile-single:
run-main:
2008-9-16 18:03:06 org.hibernate.cfg.Environment <clinit>
信息: Hibernate 3.2.5
2008-9-16 18:03:06 org.hibernate.cfg.Environment <clinit>
信息: hibernate.properties not found
2008-9-16 18:03:06 org.hibernate.cfg.Environment buildBytecodeProvider
信息: Bytecode provider name : cglib
2008-9-16 18:03:06 org.hibernate.cfg.Environment <clinit>
信息: using JDK 1.4 java.sql.Timestamp handling
2008-9-16 18:03:06 org.hibernate.cfg.Configuration configure
信息: configuring from resource: /hibernate.cfg.xml
2008-9-16 18:03:06 org.hibernate.cfg.Configuration getConfigurationInputStream
信息: Configuration resource: /hibernate.cfg.xml
2008-9-16 18:03:06 org.hibernate.cfg.Configuration addResource
信息: Reading mappings from resource : persistence/Student.hbm.xml
2008-9-16 18:03:06 org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
信息: Mapping class: model.Student -> student_table
Initial SessionFactory creation failed.org.hibernate.InvalidMappingException: Could not parse mapping document from resource persistence/Student.hbm.xml
Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class persistence.HibernateUtil
at persistence.DAOImp.createStu(DAOImp.java:31)
at BusinessManager.BM.main(BM.java:19)
Java Result: 1

...全文

相关推荐

《模式识别与数据挖掘》配套PPT课件

《模式识别与数据挖掘》配套PPT课件

Bryan Ding

科技成果转化项目进场交易前,评估备案环节需要准备哪些材料?_8.docx

科易网基于AI模型+行业大数据,在技术转移、成果转化、技术经纪、知识产权、产业创新、科技招商等垂直领域的多样化应用场景,推出科技创新领域的AI+工具与数智化解决方案,推动科技创新与产业创新智能化发展。

BIZKEEN

人工智能通识教育(中职版)课程标准+PPT课件+部分素材+电子活页+在线考核

人工智能通识教育(中职版)课程标准+PPT课件+部分素材+电子活页+在线考核

Bryan Ding

跨境电商供应链管理(AIGC版)课件+教案+参考答案

跨境电商供应链管理(AIGC版)课件+教案+参考答案

Bryan Ding

110KV单电源电网三段式电流保护+距离继电保护整定计算说明报告(23页+6000字)

内容概要:本文是一份关于110kV单电源电网继电保护整定计算的综合性技术报告,全文共23页、约6000字,系统阐述了三段式电流保护与距离保护的设计原理及其整定计算方法。报告深入分析了电力系统在短路故障条件下的电流与阻抗特性,详细推导了电流保护Ⅰ、Ⅱ、Ⅲ段的动作范围、整定原则、灵敏度校验及时间配合机制,确保满足继电保护的选择性、速动性、灵敏性和可靠性“四性”要求。同时,针对长距离或重要输电线路,补充介绍了距离保护的阻抗整定计算方法,并可能结合Matlab进行仿真验证与辅助计算,提升整定结果的准确性与工程实用性。; 适合人群:适用于电气工程及其自动化相关专业的高年级本科生、研究生,以及从事电力系统继电保护设计、运行维护的工程技术人员;要求读者具备电力系统分析、短路计算及继电保护的基础理论知识。; 使用场景及目标:①掌握110kV单电源辐射型电网中三段式电流保护的整定流程与实际计算步骤;②理解距离保护的工作原理及其在复杂工况下的应用优势;③完成实际工程项目的保护配置与整定计算任务,或作为课程设计、毕业设计及科研课题的技术参考资料;④结合Matlab工具实现整定计算的程序化处理与动作特性仿真验证。; 阅读建议:建议读者结合《电力系统继电保护原理》等相关教材同步学习,重点研读整定公式的推导过程与典型算例的计算细节,注意区分电流保护与距离保护的适用场景与配置逻辑,有条件时应利用Matlab等工具对保护动作行为进行建模与仿真,以深化对保护协调配合机制的理解。

欢多天天写代码
评论 4
收藏 已收藏
分享
返回顶部
qunqun886
Web 开发 81,108 成员 341,721 内容