hibernate 使用annotation进行的操作方法:
1. 需要在实体类中添加注解,例如下列代码:
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package com.buy.user;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.hibernate.annotations.GenericGenerator;
@Entity
@Table( name = "EVENTS" )
public class Event {
private Long id;
private String title;
private Date date;
public Event() {
// this form used by Hibernate
}
public Event(String title, Date date) {
// for application use, to create new events
this.title = title;
this.date = date;
}
@Id
@GeneratedValue(generator="increment")
@GenericGenerator(name="increment", strategy = "increment")
public Long getId() {
return id;
}
private void setId(Long id) {
this.id = id;
}
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "EVENT_DATE")
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}
2. hibernate.cfg.xml 配置如下:
<?xml version='1.0' encoding='utf-8'?>
<!--
~ Hibernate, Relational Persistence for Idiomatic Java
~
~ Copyright (c) 2010, Red Hat Inc. or third-party contributors as
~ indicated by the @author tags or express copyright attribution
~ statements applied by the authors. All third-party contributions are
~ distributed under license by Red Hat Inc.
~
~ This copyrighted material is made available to anyone wishing to use, modify,
~ copy, or redistribute it subject to the terms and conditions of the GNU
~ Lesser General Public License, as published by the Free Software Foundation.
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
~ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
~ for more details.
~
~ You should have received a copy of the GNU Lesser General Public License
~ along with this distribution; if not, write to:
~ Free Software Foundation, Inc.
~ 51 Franklin Street, Fifth Floor
~ Boston, MA 02110-1301 USA
-->
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/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/buy360</property>
<property name="connection.username">root</property>
<property name="connection.password">root</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.MySQL5Dialect</property>
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">create</property>
<!-- <mapping resource="com/buy/user/Event.hbm.xml"/> -->
<mapping class="com.buy.user.Event"/>
</session-factory>
</hibernate-configuration>
分享到:
相关推荐
《深入剖析Hibernate 4.1.5源码》 Hibernate,作为Java领域中著名的对象关系映射(ORM)框架,自发布以来就以其强大的功能和易用性深受开发者喜爱。本文将聚焦于Hibernate 4.1.5版本的源代码,通过对源码的深入解析...
Hibernate 4.1.5 SP1 API chm格式方便携带和查询 如果文件打开看不到右边的内容,是因为你的操作系统为了安全对下载的chm文件进行了锁定,只需要在打开前右键单击该chm文件选择“属性”,然后在“常规”选项卡的...
Hibernate4.1.5的API文档,英文版
《Hibernate 4.1.5.SP1:持久化框架的核心技术与应用》 Hibernate,作为Java领域中的一个著名对象关系映射(ORM)框架,它极大地简化了数据库操作,使得开发者能够以面向对象的方式处理数据库交互。本次我们将深入...
《Hibernate 4.1.5.SP1:Java ORM框架的核心技术与实践》 Hibernate,作为Java领域中的一个著名对象关系映射(ORM)框架,它极大地简化了数据库操作,使得开发者能够以面向对象的方式处理数据库交互。这次我们关注...
Struts2、Hibernate4和Spring4(简称SSH)是Java Web开发中三个非常重要的框架,它们各自负责不同的职责,但可以协同工作以构建高效、灵活的业务应用。在这个"struts2.3.2+hibernate4.3.8+spring4.1.5整合jar包"中,...
本人的此jar合集只能保证SSH2的基础环境,至于更复杂的功能,可能此集合已经包含,或者您可以从您下载的Spring或者hibernate或者struts中寻找您需要的jar包,按要求添加即可。 【因本人能力有限,不能保证此jar集合...
本人的此jar合集只能保证SSH2的基础环境,至于更复杂的功能,可能此集合已经包含,或者您可以从您下载的Spring或者hibernate或者struts中寻找您需要的jar包,按要求添加即可。 【因本人能力有限,不能保证此jar集合...
关于目前最新S2SH版本的整合测试,Struts2.3.20、Spring4.1.5、Hibernate4.3.8
ffmpeg-4.1.5.tar.bz2
SSH整合是Java Web开发中的一种常见技术组合,指的是Spring、Struts2和Hibernate这三大框架的集成应用。这个压缩包包含的是Spring 4.1.5、Hibernate 4.3.1和Struts2.2.1的核心库,用于帮助开发者快速搭建基于这些...
2. **Spring Beans**:定义了如何创建、配置和管理应用中的bean。XML和Java配置都是可选的,4.1.5版本对这两种方式都进行了优化。 3. **Spring AOP**:提供了面向切面编程的支持,可以创建可重用的切面来封装系统级...
"artdialog4.1.5" 是一个知名的JavaScript弹出对话框插件,它为Web开发者提供了方便且可自定义的对话框解决方案。这个版本(4.1.5)是artdialog...通过深入学习和实践,开发者可以充分利用其功能,提升网站的用户体验。
tk.mabatis的jar包 4.1.5版本。可参考以下方式使用 <tk-mapper.version>4.1.5 <pagehelper.version>1.2.10 <!-- Mybatis通用Mapper --> <groupId>tk.mybatis <artifactId>mapper ${tk-...
赠送jar包:httpasyncclient-4.1.5.jar; 赠送原API文档:httpasyncclient-4.1.5-javadoc.jar; 赠送源代码:httpasyncclient-4.1.5-sources.jar; 赠送Maven依赖信息文件:httpasyncclient-4.1.5.pom; 包含翻译后...
数据访问与集成(Data Access/Integration)模块是Spring处理数据库操作的关键,包括JDBC、ORM(对象关系映射)支持如Hibernate、MyBatis等,以及JPA(Java Persistence API)。Spring MVC作为Web开发的一部分,提供...
4.1.5版本对JPA和Hibernate的支持更加完善,事务管理也更为智能化,可以更好地适应各种数据库环境。 四、Web层 Spring的Web MVC框架在4.1.5版本中提供了对RESTful风格的支持,包括JSON绑定和HTTP方法约束。同时,它...
eLabsim4.1.5.exe
2. **持久化模型**:Hibernate支持JPA(Java Persistence API)标准,提供了Entity、EntityManager和EntityManagerFactory等接口,用于处理对象的创建、查询和删除。 3. **查询语言HQL**:Hibernate Query Language...
zeromq-4.1.5.zip ZeroMQ \zero-em-queue\, \ØMQ\: Ø Connect your code in any language, on any platform. Ø Carries messages across inproc, IPC, TCP, TIPC, multicast. Ø Smart patterns ...