栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

MappedSuperclass-更改子类中的SequenceGenerator

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

MappedSuperclass-更改子类中的SequenceGenerator

是的,有可能。您可以使用

@SequenceGenerator
注释覆盖默认的生成器名称。

  • 基类

    @MappedSuperclasspublic abstract class PersistentEntity implements Serializable{    private static final long serialVersionUID = 1L;    @Id    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "default_gen")    protected Long id = 0L;    public Long getId()    {        return id;    }    public void setId(Long id)    {         this.id = id;    }}
  • 序列(SQL)

    create sequence role_seq;
  • 派生类

    @Entity@Table(name = "role")@SequenceGenerator(name = "default_gen", sequenceName = "role_seq", allocationSize = 1)public class Role extends PersistentEntity implements Serializable{    private static final long serialVersionUID = 1L;    @NotNull    @Size(max = 32)    private String name;    public String getName()    {         return name;    }    public void setName(String name)    {         this.name = name;    }   }
  • 这种方法在Hibernate 4.1.x中很好用,但是在Eclipselink 2.x中却没有。

编辑

  • 根据评论,它似乎与Eclipselink 2.6.1-RC1一起使用。


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/507115.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号