<tfoot id='r6VY5'></tfoot>

  1. <i id='r6VY5'><tr id='r6VY5'><dt id='r6VY5'><q id='r6VY5'><span id='r6VY5'><b id='r6VY5'><form id='r6VY5'><ins id='r6VY5'></ins><ul id='r6VY5'></ul><sub id='r6VY5'></sub></form><legend id='r6VY5'></legend><bdo id='r6VY5'><pre id='r6VY5'><center id='r6VY5'></center></pre></bdo></b><th id='r6VY5'></th></span></q></dt></tr></i><div id='r6VY5'><tfoot id='r6VY5'></tfoot><dl id='r6VY5'><fieldset id='r6VY5'></fieldset></dl></div>
      <legend id='r6VY5'><style id='r6VY5'><dir id='r6VY5'><q id='r6VY5'></q></dir></style></legend>

    1. <small id='r6VY5'></small><noframes id='r6VY5'>

        <bdo id='r6VY5'></bdo><ul id='r6VY5'></ul>

      Hibernate:通过注释具有动态表名的数据对象

      时间:2023-07-26

        <tbody id='FYXNL'></tbody>
      <i id='FYXNL'><tr id='FYXNL'><dt id='FYXNL'><q id='FYXNL'><span id='FYXNL'><b id='FYXNL'><form id='FYXNL'><ins id='FYXNL'></ins><ul id='FYXNL'></ul><sub id='FYXNL'></sub></form><legend id='FYXNL'></legend><bdo id='FYXNL'><pre id='FYXNL'><center id='FYXNL'></center></pre></bdo></b><th id='FYXNL'></th></span></q></dt></tr></i><div id='FYXNL'><tfoot id='FYXNL'></tfoot><dl id='FYXNL'><fieldset id='FYXNL'></fieldset></dl></div>
      • <small id='FYXNL'></small><noframes id='FYXNL'>

          <tfoot id='FYXNL'></tfoot>
          <legend id='FYXNL'><style id='FYXNL'><dir id='FYXNL'><q id='FYXNL'></q></dir></style></legend>
            <bdo id='FYXNL'></bdo><ul id='FYXNL'></ul>

                本文介绍了Hibernate:通过注释具有动态表名的数据对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我有一个与表关联的 Hibernate 数据类;想象像这样的实体Person:

                I have a Data Class for Hibernate associated to a table; imagine the Entity Person like this:

                 @Entity
                 @org.hibernate.annotations.Proxy(lazy=false)
                 @Table(name="Person", schema="MySchema")
                 @Inheritance(strategy=InheritanceType.SINGLE_TABLE)
                 public class ProfileData implements Serializable {
                
                    private static final long serialVersionUID = -844564646821609090L;
                
                    public PersonData() {
                    }
                
                    @Column(name="idPerson", nullable=false, unique=true)   
                    @Id 
                    ...
                

                我需要按此表的年份创建历史表:Person2010、Person2011、Person2012... 是否可以不创建新的数据对象?也许通过参数...?我不知道.

                I need to create historic tables by years of this table: Person2010, Person2011, Person2012... Is it possible without creating new Data Objects? Maybe by a parameter...? I don´t know.

                Entity类是一样的,表名和构造函数都变了.

                The Entity class is the same, changing the table name and the constructor.

                推荐答案

                另一种架构,更复杂但优雅:

                Another one Architecture, more complez but elegant:

                YES,您可以使用 NamingStrategies 更改表名:

                YES, You can change the table names using NamingStrategies:

                public class MyNamingStrategy extends DefaultNamingStrategy {
                   ...
                   @Override
                   public  String tableName(String tableName) {
                      return tableName+yearSuffixTable;
                   }
                   ...
                }
                

                而且,当您想使用 _year 表时,您必须使用 Hibernate 创建一个覆盖 rhe 表名称的会话:

                And, when you wanna to use the _year tables, you must to create a session with Hibernate that override rhe table names:

                  SessionFactory sessionFactory;
                  Configuration config = new AnnotationConfiguration()
                                         .configure("hibernate.cfg.xml")
                                         .setNamingStrategy( new MyNamingStrategy () );
                  sessionFactory = config.buildSessionFactory();
                  session = sessionFactory.openSession();
                

                对于我的架构,我按年创建一个会话并将其存储到应用程序映射中,以便在需要时访问.

                For my architecture I create a session by year and store it into Application map for access when I need it.

                谢谢.

                这篇关于Hibernate:通过注释具有动态表名的数据对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:什么是注解以及它们如何在 Spring 这样的框架中实 下一篇:Spring MVC 中的 @Named 注解

                相关文章

                最新文章

              • <small id='T1ASs'></small><noframes id='T1ASs'>

                <i id='T1ASs'><tr id='T1ASs'><dt id='T1ASs'><q id='T1ASs'><span id='T1ASs'><b id='T1ASs'><form id='T1ASs'><ins id='T1ASs'></ins><ul id='T1ASs'></ul><sub id='T1ASs'></sub></form><legend id='T1ASs'></legend><bdo id='T1ASs'><pre id='T1ASs'><center id='T1ASs'></center></pre></bdo></b><th id='T1ASs'></th></span></q></dt></tr></i><div id='T1ASs'><tfoot id='T1ASs'></tfoot><dl id='T1ASs'><fieldset id='T1ASs'></fieldset></dl></div>

                  <tfoot id='T1ASs'></tfoot>

                    <legend id='T1ASs'><style id='T1ASs'><dir id='T1ASs'><q id='T1ASs'></q></dir></style></legend>
                    • <bdo id='T1ASs'></bdo><ul id='T1ASs'></ul>