Hibernate Annotation (Hibernate 注解)

Doris副本修复实战:从状态机到手动修复的完整指南 在分布式数据库系统中,多副本机制是实现高可用与数据一致性的核心技术。其原理是通过在不同节点存储数据的多个拷贝,确保部分节点故障时服务仍可继续。这项技术的核心价值在于保障数据可靠性,并支撑在线分析处理(OLAP)等对数据一致性要求高的应用场景。当副本出现损坏、丢失或版本不一致时,系统通常依赖自动修复机制,但在元数据损坏、多副本同时故障等复杂场景下,自动修复可能失效,需要深入理解副本状态机并借助手动工具介入。本文将聚焦Doris数据库,解析Tablet副本状态流转(如BAD、VERSION_ERROR),并详细 阅读详情

进入:http://www.hibernate.org

说明文档:

英文:http://docs.jboss.org/hibernate/annotations/3.5/reference/en/html_single/

中文:http://docs.jboss.org/hibernate/annotations/3.4/reference/zh_cn/html_single/

下载:hibernate annotation 3.4.0 GA

得到:hibernate-annotations.jar

   hibernate-commons-annotation.jar

   ejb3-persistence.jar

数据库:mysql

category表:id,name,description       <Pk>id

product表:id,name ,price, description ,category_id                  <pk>id  <fk>category_id

新建java project项目:

Add Hibernate Capabilities

hibernate.cfg.xml

复制代码
 1 <?xml version='1.0' encoding='UTF-8'?>
 2 <!DOCTYPE hibernate-configuration PUBLIC
 3           "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
 4           "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
 5 
 6 <!-- Generated by MyEclipse Hibernate Tools.                   -->
 7 <hibernate-configuration>
 8 
 9  <session-factory>
10   <property name="dialect">
11    org.hibernate.dialect.MySQLDialect
12   </property>
13   <property name="connection.url">
14    jdbc:mysql://localhost:3307/users
15   </property>
16   <property name="connection.username">root</property>
17   <property name="connection.password">root</property>
18   <property name="connection.driver_class">
19    com.mysql.jdbc.Driver
20   </property>
21   <property name="myeclipse.connection.profile">
22    mysqlusers
23   </property>
24   <property name="format_sql">true</property>
25   <property name="show_sql">true</property>
26   <property name="current_session_context_class">thread</property>
27   <mapping class="com.b510.examples.Product" />
28   <mapping class="com.b510.examples.Category" />
29 
30  </session-factory>
31 
32 </hibernate-configuration>
复制代码

利用Hibernate的逆向工程生成:

Category.java      and           Product.java   

Category.java

复制代码
 1 package com.b510.examples;
 2 
 3 import java.util.HashSet;
 4 import java.util.Set;
 5 
 6 // 标准注解
 7 
 8 import javax.persistence.CascadeType;
 9 import javax.persistence.Column;
10 import javax.persistence.Entity;
11 import javax.persistence.FetchType;
12 import javax.persistence.GeneratedValue;
13 import javax.persistence.Id;
14 import javax.persistence.OneToMany;
15 import javax.persistence.Table;
16 
17 //增加的注解
18 
19 import org.hibernate.annotations.GenericGenerator;
20 
21 //当前的类是一个持久化类,是Category这个类。他映射了一个表category。所对应的 数据库是users
22 //这句:@Table(name = "category", catalog = "users")  可以省略
23 @Entity
24 @Table(name = "category", catalog = "users")
25 
26 public class Category implements java.io.Serializable {
27 
28  private static final long serialVersionUID = 3240281547213597385L;
29  private Integer id;
30  private String name;
31  private String description;
32  private Set<Product> products = new HashSet<Product>(0);
33 
34  
35  public Category() {
36  }
37 
38  public Category(String name, String description, Set<Product> products) {
39   this.name = name;
40   this.description = description;
41   this.products = products;
42  }
43 
44  // 主键 :@Id    主键生成方式:strategy = "increment"
45  //映射表中id这个字段,不能为空,并且是唯一的
46  @GenericGenerator(name = "generator", strategy = "increment")
47  @Id
48  @GeneratedValue(generator = "generator")
49  @Column(name = "id", unique = true, nullable = false)
50  public Integer getId() {
51   return this.id;
52  }
53 
54  public void setId(Integer id) {
55   this.id = id;
56  }
57 
58  //映射表中name这个字段 ,长度是500
59  @Column(name = "name", length = 500)
60  public String getName() {
61   return this.name;
62  }
63 
64  public void setName(String name) {
65   this.name = name;
66  }
67  
68  //映射表中description这个字段 ,长度是500
69  @Column(name = "description", length = 500)
70  public String getDescription() {
71   return this.description;
72  }
73 
74  public void setDescription(String description) {
75   this.description = description;
76  }
77 
78  //级联操作:cascade = CascadeType.ALL
79  //延迟加载:fetch = FetchType.LAZY
80  //映射:mappedBy = "category"
81  //一对多方式
82  @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "category")
83  public Set<Product> getProducts() {
84   return this.products;
85  }
86 
87  public void setProducts(Set<Product> products) {
88   this.products = products;
89  }
90 
91 }
复制代码

Product.java

复制代码
 1 package com.b510.examples;
 2 
 3 import javax.persistence.Column;
 4 import javax.persistence.Entity;
 5 import javax.persistence.FetchType;
 6 import javax.persistence.GeneratedValue;
 7 import javax.persistence.Id;
 8 import javax.persistence.JoinColumn;
 9 import javax.persistence.ManyToOne;
10 import javax.persistence.Table;
11 import org.hibernate.annotations.GenericGenerator;
12 
13 
14 @Entity
15 @Table(name = "product", catalog = "users")
16 public class Product implements java.io.Serializable {
17 
18  private static final long serialVersionUID = -1546206493725028472L;
19  private Integer id;
20  private Category category;
21  private String name;
22  private String price;
23  private String descripton;
24 
25  
26  public Product() {
27  }
28 
29  public Product(Category category, String name, String price,
30    String descripton) {
31   this.category = category;
32   this.name = name;
33   this.price = price;
34   this.descripton = descripton;
35  }
36  
37  @GenericGenerator(name = "generator", strategy = "increment")
38  @Id
39  @GeneratedValue(generator = "generator")
40  @Column(name = "id", unique = true, nullable = false)
41  public Integer getId() {
42   return this.id;
43  }
44 
45  public void setId(Integer id) {
46   this.id = id;
47  }
48 
49  //延迟加载:多对一方式
50  //关联信息:外键name = "category_id"
51  @ManyToOne(fetch = FetchType.LAZY)
52  @JoinColumn(name = "category_id")
53  public Category getCategory() {
54   return this.category;
55  }
56 
57  public void setCategory(Category category) {
58   this.category = category;
59  }
60 
61  @Column(name = "name", length = 500)
62  public String getName() {
63   return this.name;
64  }
65 
66  public void setName(String name) {
67   this.name = name;
68  }
69 
70  @Column(name = "price", length = 10)
71  public String getPrice() {
72   return this.price;
73  }
74 
75  public void setPrice(String price) {
76   this.price = price;
77  }
78 
79  @Column(name = "descripton", length = 500)
80  public String getDescripton() {
81   return this.descripton;
82  }
83 
84  public void setDescripton(String descripton) {
85   this.descripton = descripton;
86  }
87 
88 }
复制代码

测试代码:

HibernateTest.java

复制代码
 1 /**
 2  * 
 3  */
 4 package com.b510.examples;
 5 
 6 import java.util.Set;
 7 
 8 import org.hibernate.Session;
 9 import org.hibernate.SessionFactory;
10 import org.hibernate.cfg.AnnotationConfiguration;
11 import org.hibernate.cfg.Configuration;
12 
13 /**
14  *
15  * @author XHW
16  *
17  * @date 2011-7-20
18  *
19  */
20 public class HibernateTest {
21 
22  public static void main(String[] args) {
23   HibernateTest test=new HibernateTest();
24   test.add();
25   test.find();
26  }
27  public void add(){
28  Configuration config=new AnnotationConfiguration();
29  config.configure();
30  SessionFactory sessionFactory=config.buildSessionFactory();
31  Session session=sessionFactory.getCurrentSession();
32  session.beginTransaction();
33  Category c=(Category)session.get(Category.class, 5);
34  
35  Product p=new Product();
36  p.setName("计算机科学与技术");
37  p.setPrice("123");
38  p.setDescripton("计算机科学与技术,好啊,真是红啊");
39  
40  p.setCategory(c);
41  c.getProducts().add(p);
42  
43  session.save(p);
44  session.getTransaction().commit();
45  }
46  
47  
48  public void find(){
49   Configuration config=new AnnotationConfiguration();
50   config.configure();
51   SessionFactory sessionFactory=config.buildSessionFactory();
52   Session session=sessionFactory.getCurrentSession();
53   session.beginTransaction();
54   Category c=(Category)session.get(Category.class, 5);
55    System.out.println("id: "+c.getId()+"  name:"+c.getName());
56    Set<Product> p=c.getProducts();
57    for(Product product:p){
58     System.out.println("id:"+product.getId()+"  name:"+product.getName()+"  description:"+product.getDescripton());
59    }
60    session.getTransaction().commit();
61  }
62 }
复制代码

运行效果:

复制代码
 1 log4j:WARN No appenders could be found for logger (org.hibernate.cfg.annotations.Version).
 2 log4j:WARN Please initialize the log4j system properly.
 3 Hibernate: 
 4     select
 5         category0_.id as id1_0_,
 6         category0_.description as descript2_1_0_,
 7         category0_.name as name1_0_ 
 8     from
 9         users.category category0_ 
10     where
11         category0_.id=?
12 Hibernate: 
13     select
14         products0_.category_id as category5_1_,
15         products0_.id as id1_,
16         products0_.id as id0_0_,
17         products0_.category_id as category5_0_0_,
18         products0_.descripton as descripton0_0_,
19         products0_.name as name0_0_,
20         products0_.price as price0_0_ 
21     from
22         users.product products0_ 
23     where
24         products0_.category_id=?
25 Hibernate: 
26     select
27         max(id) 
28     from
29         product
30 Hibernate: 
31     insert 
32     into
33         users.product
34         (category_id, descripton, name, price, id) 
35     values
36         (?, ?, ?, ?, ?)
37 Hibernate: 
38     select
39         category0_.id as id5_0_,
40         category0_.description as descript2_5_0_,
41         category0_.name as name5_0_ 
42     from
43         users.category category0_ 
44     where
45         category0_.id=?
46 id: 5  name:xml33
47 Hibernate: 
48     select
49         products0_.category_id as category5_1_,
50         products0_.id as id1_,
51         products0_.id as id4_0_,
52         products0_.category_id as category5_4_0_,
53         products0_.descripton as descripton4_0_,
54         products0_.name as name4_0_,
55         products0_.price as price4_0_ 
56     from
57         users.product products0_ 
58     where
59         products0_.category_id=?
60 id:9  name:计算机科学与技术  description:计算机科学与技术,好啊,真是红啊
复制代码
Node-RED系列(二二):使用dashboard搭配echarts制作漂亮的面板 在node-red中dashboard 是一个很常用的模块,其中它有一个chart节点可以用来制作一些图表,比如柱状图,折线图,饼图,但其中的图表并不是很美观,而且可配置项非常的少。 于是就有很多小伙伴找我做一套比较好看的图表面板,在对比了一下几个图表库,我选中了echarts。 不仅美观大方,而且非常容易集成,配置。下面先来看一下我做的效果。这里是直接做了四个折线图,第一个折线图有动态效果,第二个折线图是一个多线条的折线图,第三个折线图是在一个图例显示两个折线图。第二第三都可以用于数据对比。 第四个折线 阅读详情

相关推荐

山石网科Hillstone防火墙基础上网配置_CLI命令行(最新版)

山石网科Hillstone防火墙安全网关基础上网基础网络配置_CLI命令行(最新版)

路与肥的博客 1万+

org.hibernate.annotations和javax.persistence区别

Hibernate是Java持久化API的一种实现,在可能的情况下,应该使用标准注释(在javax.persistence中)。这样,理论上可以在其他JPA实现上运行代码。 只有当需要Hibernate特定的功能时,才应该使用Hibernate注释。 额外的依赖性只在jpa接口/注释jar文件上,而且非常轻。 @org.hibernate.annotations.Entity是@javax.pe...

一只勤奋的PIG 1613

Android13配置selinux让system应用可读sys,proc,SN号

Android13预置的system应用,需要读/sys, /proc目录,读(SN)serial number号, 需要修改selinux配置,否则会报avc错.其修改方法会比Android11复杂一些.。

zmlovelx(帅得不敢出门 程序员群31843264) 2654

Hibernate_入门

目录 一、概念 二、主键生成策略 ①程序员自己控制:assigned ② 数据库控制: identity(标识列/自动增长) sequence ③ hibernate控制:increment uuid/uuid.hex ④ 其它:native 三、使用 ①在pom.xml中导入Hibernate相关依赖 ②配置hibernate.cfg.xml文件 ③创建实体类,配置映射文件 ④测试 一、概念 Hibernate是持久层的ORM框架,我们可以通过操作java对象来操作我们的数据库数

隔壁的博客 348

Veritas NetBackup 10.1 Windows安装指南:从账户配置到完整部署

本文详细介绍了Veritas NetBackup 10.1在Windows系统上的完整安装流程,从账户配置到部署验证。重点讲解了创建专用服务账户、安装组件选择、许可证输入等关键步骤,并提供了常见问题排查和进阶配置建议,帮助用户顺利完成企业级备份解决方案的部署。

weixin_26765287的博客 453

CentOS 7下glibc升级到2.28的保姆级避坑指南(含GCC 7.3.1编译配置)

本文详细介绍了在CentOS 7系统中将glibc升级到2.28版本的完整流程,包括GCC 7.3.1的编译配置、环境变量设置、glibc编译的细节处理以及生产环境验证。文章特别强调了风险控制和避坑技巧,适用于需要提升系统兼容性的企业级用户。

weixin_29611239的博客 408

org.hibernate.AnnotationException: @org.hibernate.annotations.Table references an unknown table:

今天在开发的项目模块中,利用hibernate自动创建表时报org.hibernate.AnnotationException: @org.hibernate.annotations.Table references an unknown table: 原因是注解类用了@org.hibernate.annotations.Table,如下所示: import javax.persistence.

xiaxia_jessica的专栏 7728

基于分数阶的图像边缘细节检测——边缘计算

在图像处理中,我们可以使用分数阶导数运算器来计算图像的分数阶梯度,从而得到更精确的边缘信息。通过使用基于分数阶的图像边缘细节检测方法,我们可以更准确地捕捉图像中的边缘细节信息。在这篇文章中,我们将介绍一种基于分数阶的方法来进行图像边缘细节检测,并提供相应的源代码实现。需要注意的是,以上提供的代码示例仅用于演示基于分数阶的图像边缘细节检测方法的实现。然后,我们读取了待处理的图像,并进行了预处理,如高斯模糊,以减少噪声的影响。最后,我们通过设置一个阈值,将梯度图像转化为二值化的边缘图像,并将结果显示出来。

GudcSql的博客 403

Hibernate annotation 详解

1.级联CASCADE属性的意义: &nbsp; 只有&ldquo;关系标记&rdquo;才有cascade属性:OneToOne ,OneToMany ,ManyToOne ,ManyToMany. &nbsp;&nbsp;&nbsp;级联指的是当主控方执行操作时,关联对象(被动方)是否同步执行同一操作。 &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; 一个操作因级联...

闲谈 192

用 CL_ABAP_ZIP 在 ABAP 里打包任意文件:从前端多选到 ZIP 交付的一条龙实践

本文介绍了在SAP ABAP中实现文件打包交付的完整解决方案。文章首先区分了ZIP和GZIP的不同用途:ZIP用于多文件归档,GZIP用于单数据流压缩。核心流程包括四个步骤:文件选择、二进制上传、内存打包和ZIP输出,并提供了关键对象与函数的速查表。针对实际项目中常见的乱码、大文件处理等问题给出了解决方案,最后展示了一个完整的可运行示例代码,涵盖了从文件选择到下载的全流程实现。该方案适用于财务、质量、运维等多种业务场景,能够有效解决多文件交付的最后一公里问题。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 215

Android 12.0 framework系统修改安兔兔等显示的屏幕尺寸大小功能实现

在12.0的系统rom定制化开发中,在使用第三方app检测系统的一些信息中,比如安兔兔 设备信息等检测app中,有时候显示的屏幕尺寸大小和 产品规格书等信息不同,稍微有些差异,所以就需要看下系统framework层中,相关的设备信息是怎么读出来的,然后做些调整 接下来就来分析相关功能

安卓兼职framework和app工程师的博客 476

Hibernate常用Annotation标签说明

@ javax.persistence.Entity 实体类定义,该标签表示当前类是一个Hibernate的数据库实体,对应着数据库中的某个表 位置:用于类级别 参数:无 样例:@Entity 注意:导入标签类时可能会有多个,这里使用的是javax.persistence.Entity @javax.persistence.Table 实体类定义,该标签表示当前类是一个H

北京-李大鹏 4244

基于STM32F1XX 、HAL库的OPT4001-Q1环境光传感器驱动应用C语言程序设计

OPT4001-Q1 的输出是半对数 的,具有 9 个二进制对数满量程照度范围,每个范围内具有高度线性响应,使得 PicoStar™ 型号的测量能力为 312.5μlux 至 84klux,USON 型号的测量能力为 400µlux 至 107klux。// 禁用中断(示例)

PP_Cottage的博客 461

Spring下Hibernate Annotation注解

在spring+hibernate环境下使用Hibernate Annotation,其实主要的就是对hibernate实体类的注解。这里要注意的一个问题是要使用包javax.persistence.Entity;下面的注解,而不是org.hibernate.annotation.Entity;接下来就是在spring配置文件中配置,使其支持注解方式即可。annotation.Annota

czx33859066的专栏 765

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

Hibernate 注解 annotation

Hibernate 注解 annotation 博客分类:  Hibernate HibernateBeanSQL嵌入式数据结构 一、 实体 Bean 每个持久化POJO类都是一个实体Bean, 通过在类的定义中使用 @Entity 注解来进行声明。 声明实体Bean @Entity public class Flight implements Se

lidongtang的专栏 1295

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

Hibernate Annotation中BLOB、CLOB注解写法

在hibernate Annotation中,实体BLOB、CLOB类型的注解与普通的实体属性有些不同,具体操作如下:BLOB类型,类型声明为byte[]: private byte[] content;     注解: @Lob @Basic(fetch = FetchType.LAZY) @Column(name = "CONTE

sz_bdqn的专栏 1425

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

【hibernate框架3】使用Annotation注解进行实体类操作

上一篇讲的是hibernate的环境搭建,因为现在大部分公司在使用Annotation来操作实体类进而进行表的建立,免去了写Xxx.hbm.xml表映射文件的烦恼,所以我再写一个用Annotation来操作实体类的例子: 导包什么的我就不说了,详情看上一篇吧,直接切入主题: 1.首先说说什么是注解(Annotation),这个学过Java基础的人应该不陌生,这里只说一下在hibernate框架...

weixin_38213517的博客 196

hibernate annotation 注解

(1) 简介: 在过去几年里,Hibernate不断发展,几乎成为Java数据库持久性的事实标准。它非常强大、灵活,而且具备了优异的性能。在本文中,我们将了解如何使用Java 5 注释来简化Hibernate代码,并使持久层的编码过程变得更为轻松。   传统上,Hibernate的配置依赖于外部 XML 文件:数据库映射被定义为一组 XML 映射文件,并且在启动时进行加载。     在最近

一个人有了信仰,不管成不成功,至少不会迷茫。 1万+

hibernate mysql annotation_Hibernate Annotation (Hibernate 注解)

说明文档:下载:hibernate annotation 3.4.0 GA得到:hibernate-annotations.jarhibernate-commons-annotation.jarejb3-persistence.jar数据库:mysqlcategory表:id,name,description idproduct表:id,name ,price, description...

weixin_30902943的博客 89

Hibernate基于注解annotation的配置

Annotation在框架中是越来越受欢迎了,因为annotation的配置比起XML的配置来说方便了很多,不需要大量的XML来书写,方便简单了很多,只要几个annotation的配置,就可以完成我们以前需要书写的大量的XML文件。当然annotation的配置也有缺陷的,那就是annotation一般都是配置在代码中的,如果要修改的话,需要动源代码,丧失了灵活性,违背了OCP(增加开放...

awv94517的博客 341

hibernate注解annotation入门

前面的文章示例中我们写了实体类之后,都会写一个对应的*.hbm.xml配置文件,这种方式比较复杂,今天我们就来简单了解下使用注解annotation来替代配置文件的方法。 新建一个java项目,结构如下: Book实体类,在实体类中使用注解,代码如下: package com.test.pojo; import java.util.Date; import javax.persist

想念的专栏 459

Hibernate注解-annotation

Hibernate注解-annotation 文章目录Hibernate注解-annotation常用的注解注解编写的位置注解实现单表1、编写实体类2、编写主配置文件3、测试 在Hibernate中,通常配置对象关系映射的方式有两种,一种是基于xml的方式,另一种是基于annotation的注解方式,俗话说,萝卜青菜,可有所爱,每个人都有自己喜欢的配置方式,annotation的方式可以更简介,使...

ch19940812的博客 267

第五节 基于Annotation注解的Hibernate关联映射

基于Annotation注解的Hibernate关联映射 一对一关联映射 参考一对多关联映射 一对多关联映射 Department.java package cn.edu.scnu.annotationcurd.entity; import org.hibernate.annotations.GenericGenerator; import javax.persisten...

江城子_Lay的博客 335

hibernate annotation注解方式来处理映射关系

这位仁兄总结的不错: hibernate annotation注解方式来处理映射关系

longsq602的专栏 291

Hibernate or JPA Annotation中BLOB、CLOB注解写法

BLOB和CLOB都是大字段类型,BLOB是按二进制字节码来存储的。而CLOB是能够直接存储字符串的。 在hibernate or JPA Annotation中,实体BLOB、CLOB类型的注解与普通的实体属性有些不同,详细操作例如以下:   BLOB类型,类型声明为byte[]:   private byte[] content;   注解:   @Lo...

weixin_30663471的博客 149

Hibernate的Annotation注解

当项目变得比较大的时候,如何还使用hbm.xml文件来配置Hibernate实体就会变得比较复杂。这里Hibernate提供了Annotation注解方式,使得Hibernate的映射文件变得很方便管理了。       这里简单介绍Hibernate的Annotation注解 一、声明实体       @Entity       对实体注释。任何Hibernate映射对

刘霖晋 博客园 360
上一篇: eclipse, Log4j配置(真心的详细~)
下一篇: Java的反射机制浅谈
鹿晗的晗
博客等级 码龄16年 22粉丝 23原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值