在数据库列更改时动态更改hibernateMap

z9gpfhce  于 2021-07-29  发布在  Java
关注(0)|答案(0)|浏览(174)

我有一个包含下一个表的数据库(简化):
tpersons:fid-主键,int-人员id fname-nvarchar(100)-人员姓名
totherfields:fid-主键,int-附加字段的id fname-nvarchar(100)-数据库中的字段名
tothervalues:fpersonid-外键,int-人员ffield1的id,ffield2,…-在totherfields中定义的字段集。
例如,在totherfields({1,“ffield1”}和{2,“ffield2”})中有2条记录,然后在tothervalues表中有列“ffield1”和“ffield2”。
我有两份申请。第一个应用程序可以更改数据库,添加新的附加字段,并填写人员及其附加字段的数据。第二个应用程序是c#上的一个服务,它使用hibernateMap来处理这个数据库。
对于本例,它有下一个Map文件:
person.hbm.xml:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
  assembly="MyApp.Common.Model"
  namespace="MyApp.Common.Model">
  <class name="Person" entity-name="Person" table="TPersons" polymorphism="explicit">
    <id name="Id" column="FId">
      <generator class="native">
        <param name="sequence">SEQ_TPERSONS</param>
      </generator>
    </id>

    <one-to-one name="AddFields" entity-name="AddFields" fetch="join" cascade="all"/>
  </class>
</hibernate-mapping>

其他字段.hbm.xml:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
  assembly="MyApp.Common.Model"
  namespace="MyApp.Common.Model">
  <class name="AddFields" entity-name="AddFields" table="TOtherValues" polymorphism="explicit">
    <id name="Id" column="FPersonId">
    </id>
    <property name="FField1" not-null="false" access="MyApp.Common.Model.AddFieldsAccessor, MyApp.Common.Model"/>
    <property name="FField2" not-null="false" access="MyApp.Common.Model.AddFieldsAccessor, MyApp.Common.Model"/>
  </class>
</hibernate-mapping>

它工作正常,而我不改变第一个应用程序领域。
get请求的结果:

{
    "AdvancedFields": {
        "Fields": {
            "FOTHER1": "text1",
            "FOTHER2": "02.02.2020"
        },
        "Id": 1,
        "TypeId": "AddFields"
    },
    "Id": 1,
    "TypeId": "Person"
}

我应该使这个服务工作时,我改变了第一次申请领域。例如,我将“ffield3”添加到数据库中,将新记录添加到totherfields表中,将新列添加到tothervalues中。我的服务应该找到一些方法,并在他的get请求中显示这个新字段。也许这个addfields.hbm.xml应该被服务更改和重新加载,也许我应该在它前面添加“ffield3”和一些键“skip if not exists”,也许是其他方式。但我无法重新启动服务,它应该返回带有数据库中所有其他字段的人员。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题