hibernate 建立annotation版本的helloworld
来源:互联网 发布:godaddy购买域名教程 编辑:程序博客网 时间:2024/06/10 19:23
1、添加annotation相应的jar包。
2.Teacher.java
package com.wxh.hibernate.model;import javax.persistence.Entity; import javax.persistence.Id;@Entitypublic class Teacher {private int id;private String name;private String title;@Idpublic int getId() {return id;}@Idpublic void setId(int id) {this.id = id;}public String getName() {return name;}public void setName(String name) {this.name = name;}public String getTitle() {return title;}public void setTitle(String title) {this.title = title;}}
3.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> <!-- Database connection settings --> <property name="connection.driver_class">com.mysql.jdbc.Driver</property> <property name="connection.url">jdbc:mysql://localhost/db</property> <property name="connection.username">root</property> <property name="connection.password">111</property> <!-- SQL dialect --> <property name="dialect">org.hibernate.dialect.MySQLDialect</property> <!-- Disable the second-level cache --> <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property> <!-- Echo all executed SQL to stdout --> <property name="show_sql">true</property> <mapping class="com.wxh.hibernate.model.Teacher"/> </session-factory></hibernate-configuration>
import org.hibernate.Session; import org.hibernate.SessionFactory;import org.hibernate.cfg.AnnotationConfiguration;import org.hibernate.cfg.Configuration;import com.wxh.hibernate.model.Student;import com.wxh.hibernate.model.Teacher;public class TeacherTest {public static void main(String[] args){Teacher t=new Teacher();t.setId(1);t.setName("t1");t.setTitle("中级");Configuration cfg=new AnnotationConfiguration();SessionFactory sf=cfg.configure().buildSessionFactory();Session session=sf.openSession();session.beginTransaction();session.save(t);session.getTransaction().commit();session.close();sf.close();}}
0 0
- hibernate 建立annotation版本的helloworld
- 建立Annotation版本的HelloWorld
- Hibernate的Annotation版本的HelloWorld
- Hibernate 中创建Annotation版本的HelloWorld
- 003:hibernate:Annotation版本的Helloworld
- 建立 Annotation版本的hibernate小例子
- Hibernate(annotation版本helloworld)-2
- annotation版本的helloworld
- Annotation版本的hibernate
- hibernate3.3.2学习笔记---Annotation版本的HelloWorld及org.hibernate.HibernateException错误改正
- 03hibernate Annotation版本的hibernate
- 【Hibernate】helloworld项目建立
- Hibernate的关系映射总结annotation版本
- Hibernate helloworld xml版本
- hibernate的Annotation配置
- Hibernate 简单的annotation
- Hibernate的Annotation注解
- Hibernate的Annotation注解
- Java web在Linux上取接口参数乱码问题
- ACL
- Java的IO流
- 数据结构算法之排序系列Java、C源码实现(3)--直接选择排序
- JavaScript高级程序设计(第3版)第四章读书笔记
- hibernate 建立annotation版本的helloworld
- UVA 11925(p254)----Generating Permutations
- 树莓派安装 python3 及 python IDE
- UVA 11971(p335)----Polygon
- 迷人的hessian,你需要了解
- list,map,array理解
- Wireshark基本介绍和学习TCP三次握手
- UVA 11988(p143)----Broken Keyboard
- POJ 1743 Musical Theme(二分+后缀数组)