Hibernate map enum type
1. Bean
@Entity
@Table(name = "entities")
public class Entities {
public enum entityType {
location, group;
}
private entityType locationOrGroup; @Column(name="location_or_group")
@Enumerated(EnumType.STRING) //Should set the type of location_or_group to varchar in database
public entityType getLocationOrGroup() {
return locationOrGroup;
}
public void setLocationOrGroup(entityType locationOrGroup) {
this.locationOrGroup = locationOrGroup;
} }
2. Database
CREATE TABLE entities
(
location_or_group varchar
);
3. Unit Test
@Test
public void testEnum() {
Session session = Config.getSessionFactory().openSession();
session.beginTransaction(); Query query = session.createQuery("select locationOrGroup from Entities"); @SuppressWarnings("unchecked")
List<Object> entities = query.list();
System.out.println(entities.get(0));
assertEquals(entities.get(0).toString(), "group");//entities.get(0)here is of type entityType in bean file, should be cast to String session.getTransaction().commit();
session.close();
}
Hibernate map enum type的更多相关文章
- Effective Java 03 Enforce the singleton property with a private constructor or an enum type
Principle When implement the singleton pattern please decorate the INSTANCE field with "static ...
- C#中的枚举类型(enum type)
ylbtech 原文 C#中的枚举类型(enum type) 概念 枚举类型(enum type)是具有一组命名常量的独特的值类型.在以下示例中: enum Color { Red, Green, B ...
- 【转】掌握java枚举类型(enum type)
原文网址:http://iaiai.iteye.com/blog/1843553 1 背景 在java语言中还没有引入枚举类型之前,表示枚举类型的常用模式是声明一组具有int常量.之前我们通常利用 ...
- Effective Java Item3:Enforce the singleton property with a private constructor or an enum type
Item3:Enforce the singleton property with a private constructor or an enum type 采用枚举类型(ENUM)实现单例模式. ...
- Java之创建对象>3.Enforce the singleton property with a private constructor or an enum type
1. 通过一个公开的字段来获取单例 // Singleton with public final field public class Elvis { public static final Elv ...
- C# Enum Type
class Program { public enum TimeOfDay { Morining, Afternoon, Evening } static void Main(string[] arg ...
- ADO编程:error C2011: 'LockTypeEnum' : 'enum' type redefinition
C++ Code 123 // Import the ADO type library #import "C:\\Program Files\\Common Files\\syste ...
- “locktype”enum type 类型重定义问题的解决
作者:朱金灿 来源:http://blog.csdn.net/clever101 使用ado来连接数据库,结果出现这样一些编译错误: 1>f:\c++pro\iocptser\debug\msa ...
- Hibernate学习---第六节:数组&list&map&set的映射配置
1.实体类,代码如下: package learn.hibernate.bean; import java.util.Date; import java.util.HashMap; import ja ...
随机推荐
- 老李分享:Robotium编写测试用例如何模拟Junit4的BeforeClass和AfterClass方法1 - 条件判断法
老李分享:Robotium编写测试用例如何模拟Junit4的BeforeClass和AfterClass方法1 - 条件判断法 poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜 ...
- Uva 11076 Add Again (数论+组合数学)
题意:给你N个数,求把他们的全排列加和为多少 思路:对于这道题,假设数字k1在第一位,然后求出剩下N-1位的排列数num1,我们就可以知道k1在第一位时 排列有多少种为kind1, 同理,假设数字k2 ...
- 实现高效的GPRS驱动程序
1. 引言 用过几款GPRS模块,也从淘宝上买过多个GPRS模块,一般的都会送一个驱动程序和使用demo,但是代码质量都较低. 回头看了下几年前使用的GPRS代码,从今天的角度来看,也就是买模块赠送一 ...
- Web性能优化工具WebPageTest(一)——总览与配置
网站性能优化工具大致分为两类:综合类和RUM类(实时监控用户类),WebPageTest属于综合类. WebPageTest通过布置一些特定的场景进行测试,例如不同的网速.浏览器.位置等. 测试完成后 ...
- 浩哥解析MyBatis源码(八)——Type类型模块之TypeAliasRegistry(类型别名注册器)
原创作品,可以转载,但是请标注出处地址:http://www.cnblogs.com/V1haoge/p/6705769.html 1.回顾 前面几篇讲了数据源模块,这和之前的事务模块都是enviro ...
- mysql数据库实操笔记20170418
一.建立商品分类表和价格表: 1.分类表`sankeq``sankeq`CREATE TABLE cs_mysql11(id INT(11) NOT NULL AUTO_INCREMENT,categ ...
- AFNetworking 内部详解
AFNetworking 是一个适用于IOS 和 Mac OSX 两个平台的网络库,他是在Foundation URL Loading System 基础上进行的一套封装 ,并提供了丰富的API接口 ...
- Linux -atime、mtime、ctime
Linux中,文件都有其自身的atime.mtime.ctime,在不同的命令下,各时间发生相应的改变.下面,我们来简单的介绍一下: atime (access time):表示最后一次访问文件或目录 ...
- cocos2d-x - C++/Lua交互
使用tolua++将自定义的C++类嵌入,让lua脚本使用 一般过程: 自定义类 -> 使用tolua++工具编译到LuaCoco2d.cpp中 -> lua调用 步骤一:自定义一个C++ ...
- python与opencv的结合之人脸识别值
首先还是要感谢http://www.jb51.net/article/67392.htm这位大神的无私奉献,开源的代码,让我省去了很多事,但是就光系统环境的配置就花去了我将近一个星期的时间,真是不容易 ...