zoukankan      html  css  js  c++  java
  • Hibernate 5.2.1笔记

    1、Junit中获取SessionFactory方式

    private SessionFactory sessionFactory;
        
        @Override
        protected void setUp() throws Exception {
            final StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
                    .configure()
                    .build();
            try {
                //自动生成数据库表
                //new SchemaExport().create(EnumSet.of(TargetType.DATABASE),new MetadataSources(registry).buildMetadata());
                sessionFactory = new MetadataSources( registry ).buildMetadata().buildSessionFactory();
            }
            catch (Exception e) {
                StandardServiceRegistryBuilder.destroy( registry );
            }
        }

    2、ID生成策略

    AUTO、IDENTITY、SEQUENCE、TABLE

       @Id
        @GeneratedValue(strategy = GenerationType.IDENTITY)
        public int getId() {
            return id;
        }

    数据库是SQL Server 2008,再生成主键时使用  @GeneratedValue 或者 @GeneratedValue(strategy = GenerationType.AUTO)

    数据库生成的策略使用的是SEQUENCE,其他数据库没做测试

    3、使用@ManyToMany多对多双向关联时,主键生成策略不起作用的问题依旧

     
  • 相关阅读:
    C#中关于zip压缩解压帮助类的封装(转)
    MonoTouch的官网
    Android布局
    VS2010网站发布
    HTML5的PLACEHOLDER属性
    some np problem
    srm 578
    opencv 边缘算子
    Python扩展(pybind11混编)
    PyTorch之初级使用
  • 原文地址:https://www.cnblogs.com/helloquan/p/5705904.html
Copyright © 2011-2022 走看看