我如何获得Hibernate逆向工程工具来生成< bag>或< list>反向关联? [英] How do I get the Hibernate reverse engineering tools to generate <bag> or <list> for inverse associations?

查看:135
本文介绍了我如何获得Hibernate逆向工程工具来生成< bag>或< list>反向关联?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将元素添加到集合中,最终得到像这样映射:

 < set name =others inverse =truelazy =truetable =otherfetch =select> 
< key>
< column name =otherIdnot-null =true/>
< / key>
<一对多课程=my.pkg.OtherEntity/>
< / set>

我希望使用Hibernate,因为我不关心它们的顺序检索到,我只是想保持该协会的一面最新。根据 https://www.hibernate.org/117.html ,Hibernate可以添加到< bag>,< idbag>或< list>以inverse =true声明并且未初始化集合。 我的问题是我不'不知道如何强制(或建议)逆向工程工具(hibernate-tools.jar)来使用< bag>或< list> - 它总是使用< set>。

谢谢!

解决方案

您可以使用反向工程配置文件自定义逆向工程过程,该文件使用XML语法。我没有尝试过这个,但这个例子可能适合你:

 <?xml version =1.0编码= UTF-8 >?; 
<!DOCTYPE hibernate-reverse-engineering SYSTEM
http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd\">
< hibernate-reverse-engineering>
< table name =MYTABLE>
< column name =otherstype =bag/>
< / table>
< / hibernate-reverse-engineering>

如果它不能正常工作,您可能会发现更多关于控制逆向工程过程的细节< here


I want to add elements to a collection that ends up getting mapped like this:

<set name="others" inverse="true" lazy="true" table="other" fetch="select">
  <key>
    <column name="otherId" not-null="true" />
  </key>
  <one-to-many class="my.pkg.OtherEntity" />
</set>

I'd like Hibernate to use instead, because I don't care about the order they're retrieved in, I just want to keep that side of the association up-to-date. According to https://www.hibernate.org/117.html, "Hibernate can add to a <bag>, <idbag> or <list> declared with inverse="true" without initializing the collection."

My problem is I don't know how to force (or suggest to) the reverse engineering tools (hibernate-tools.jar) to use <bag> or <list>--it ALWAYS uses <set>.

Thanks!

解决方案

You can customize the reverse engineering procedure with a reverse-engineering configuration file, which uses an XML syntax. I haven't tried this myself, but this example may work for you:

<?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE hibernate-reverse-engineering SYSTEM
    "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd">
<hibernate-reverse-engineering>
    <table name="MYTABLE">
        <column name="others" type="bag"/>
    </table>
</hibernate-reverse-engineering>

If it does not work as it is, you may find more details about controlling the reverse engineering process here.

这篇关于我如何获得Hibernate逆向工程工具来生成&lt; bag&gt;或&lt; list&gt;反向关联?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆