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的更多相关文章

  1. 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 ...

  2. C#中的枚举类型(enum type)

    ylbtech 原文 C#中的枚举类型(enum type) 概念 枚举类型(enum type)是具有一组命名常量的独特的值类型.在以下示例中: enum Color { Red, Green, B ...

  3. 【转】掌握java枚举类型(enum type)

    原文网址:http://iaiai.iteye.com/blog/1843553 1   背景 在java语言中还没有引入枚举类型之前,表示枚举类型的常用模式是声明一组具有int常量.之前我们通常利用 ...

  4. 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)实现单例模式. ...

  5. 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 ...

  6. C# Enum Type

    class Program { public enum TimeOfDay { Morining, Afternoon, Evening } static void Main(string[] arg ...

  7. ADO编程:error C2011: 'LockTypeEnum' : 'enum' type redefinition

     C++ Code  123   // Import the ADO type library #import "C:\\Program Files\\Common Files\\syste ...

  8. “locktype”enum type 类型重定义问题的解决

    作者:朱金灿 来源:http://blog.csdn.net/clever101 使用ado来连接数据库,结果出现这样一些编译错误: 1>f:\c++pro\iocptser\debug\msa ...

  9. Hibernate学习---第六节:数组&list&map&set的映射配置

    1.实体类,代码如下: package learn.hibernate.bean; import java.util.Date; import java.util.HashMap; import ja ...

随机推荐

  1. 测试开发Python培训:抓取新浪微博抓取数据-技术篇

    测试开发Python培训:抓取新浪微博抓取数据-技术篇   poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标.在poptest的se ...

  2. Grafana中多租户设置

    Grafana中通过设置不同的组织,以及将用户分配到不同组织,来做到多租户,类似门户的概念. Grafana默认是不允许非管理员用户创建新的组织的,这个可以通过修改配置文件以允许非管理员用户创建组织: ...

  3. python 语句:条件、循环、break、continue...

    1. 条件语句 执行条件:判断条件"成立时(非零),则执行后面的语句,而执行内容可以多行,以缩进来区分表示同一范围. [Python程序语言指定任何非0和非空(null)值为true,0 或 ...

  4. IOS设备型号(原创)

    以下是我收集的ios目前为止移动设备型号,ipad air不知道,本人没有这款设备,求指导的给个回复,在这谢谢了 ///** ////////////////////   设备类型 字符串   /// ...

  5. activiti 5.13 使用activiti设置用户组任务的 工作流的角色

    1.设置activiti 流程引擎的用户,组别,关系/**在部署流程定义和启动流程实例的中间,设置组任务的办理人,向Activiti表中存放组和用户的信息*/ IdentityService iden ...

  6. Python学习_argsparse

    # -*- coding: utf-8 -*- import argparse args = "-f hello.txt -n 1 2 3 -x 100 -y b -z a -q hello ...

  7. JS和CSS中引号的使用

        font-family属性值如果是英文可以不加引号,如果是中文按照CSS标准则应该加引号,但不加引号也没关系.比如:font-family:Arial,"宋体"," ...

  8. JavaEE开发之SpringMVC中的路由配置及参数传递详解

    在之前我们使用Swift的Perfect框架来开发服务端程序时,聊到了Perfect中的路由配置.而在SpringMVC中的路由配置与其也是大同小异的.说到路由,其实就是将URL映射到Java的具体类 ...

  9. DateTime.Now的一些用法

    System.DateTime.Now.ToString("D");   //Tuesday, December 13, 2016 System.DateTime.Now.ToSt ...

  10. mvc中razor的一个bug

    具体东西就不多说了,所有编译,代码都是木有问题的. 结果预览页面的时候竟然告诉我编译错误,尼玛这不科学啊. 来看看错误页面 看着问题大概应该是缺少} ,或者多了个} 倒置的编译错误才对,但是编译生成完 ...