简体   繁体   English

休眠代码生成怪异行为

[英]Hibernate code generation weird behaviour

I´m getting a weird behaviour using hibernate tools to generate my entities. 使用休眠工具生成实体时,我的行为很奇怪。 I need the "java names" to respect some convension. 我需要“ java名称”来尊重一些惯例。 So I configured de reveng.xml It´s like this: 所以我配置了de reveng.xml,就像这样:

<hibernate-reverse-engineering>
    <schema-selection match-schema="SCHEMA" match-table="PRE_.*" />

    <table-filter match-name="PRE_.*" package="com.my.ent"/>

    <table name="PRE_MY_TABLE" schema="SCHEMA" class="MyTable">
        <column name="C_ID" property="id" />
        <column name="C_COD" property="cod" />
    </table>
    <table name="PRE_MY_TABLE_2" schema="SCHEMA" class="MyTable2">
        <column name="C_ID" property="id" />
        <column name="C_COD" property="cod" />
    </table>
        ....
    <table name="PRE_MY_TABLE_N" schema="SCHEMA" class="MyTableN">
        <column name="C_ID" property="id" />
        <column name="C_COD" property="cod" />
    </table>
</hibernate-reverse-engineering>

What I spect is the resulting code (of entities 1 to N) to be located in the folder set in the tool conf with the folder structure inside (com.my.ent) and respecting the names set in the reveng file. 我想说的是,结果代码(实体1到N)位于工具conf中设置的文件夹中,文件夹结构位于内部(com.my.ent),并尊重reveng文件中设置的名称。 Instead of that I´m getting the code located with the right folder structure but with the names exactly as in the DB. 取而代之的是,我得到的代码位于正确的文件夹结构中,但名称与数据库中的名称完全相同。

I don´t get it, this is a simple procedure and I cant get it working well. 我不明白,这是一个简单的过程,我无法使其正常运行。

Any help will be apreciated. 任何帮助将不胜感激。

Thanks in advance! 提前致谢!

Well, the problem was really simple to resolve. 好吧,这个问题真的很容易解决。

The issue was in the table declaration. 问题出在表声明中。

Declaring the class unqualified, overrides the package declaration in the table filter, so the generated code goes to the root folder and the entities created dont contain the package declaration (using default). 声明该类不合格,将覆盖表过滤器中的程序包声明,因此生成的代码将转到根文件夹,并且创建的实体不包含程序包声明(使用默认值)。

The solution is to declare the table configuration as follows: 解决方案是声明表配置,如下所示:

<table-filter match-name="PRE_.*" package="com.my.ent"/>

<table name="PRE_MY_TABLE" schema="SCHEMA" class="com.my.ent.MyTable">
    <column name="C_ID" property="id" />
    <column name="C_COD" property="cod" />
</table>

Cheers! 干杯!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM