0

Having a table A and a table B, A has a fk to B. In A, column of this FK is unique and nullable. That means, a B is only referencied as a maximum for one A.

But hibernate tools reverse enginering is generating pojos as:

Pojo A with a field B. Ok, that's correct. Pobo B with a set of A. No, it's not, should be a single field A.

What's wrong? I'm missing something?

this is my reveng.xml

<?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>

<type-mapping>
    <sql-type jdbc-type="BIGINT" hibernate-type="java.math.BigInteger" />
    <sql-type jdbc-type="NUMERIC" precision="19" hibernate-type="java.math.BigInteger"/>
    <sql-type jdbc-type="NUMERIC" precision="10" not-null="true" hibernate-type="int"/>
    <sql-type jdbc-type="NUMERIC" precision="10" not-null="false" hibernate-type="java.lang.Integer"/>
    <sql-type jdbc-type="NUMERIC" precision="4" not-null="true" hibernate-type="byte"/>
    <sql-type jdbc-type="NUMERIC" precision="4" not-null="false" hibernate-type="java.lang.Byte"/>
    <sql-type jdbc-type="OTHER" hibernate-type="timestamp"/>
</type-mapping>

<table-filter match-name="MLOG.*"  exclude="true" /> 
<table-filter match-name="RUPD.*"  exclude="true" />  

<!-- Forzamos a que el id sea Integer. Al eliminar el autoincremental hibernate pasa este campo a int.-->
<!-- Se cambia el codigo para que no afecte el tipo-->
<!--
<table name="cpanel_bloque_canal" catalog="ob_cpanel"> 
    <primary-key>                       
        <key-column name="idBloque" type="java.lang.Integer"/>
    </primary-key>
</table>
-->

Ignasi
  • 5,887
  • 7
  • 45
  • 81
  • Could you post the relevant hibernate.reveng.xml file? – JamesB Jul 04 '14 at 12:05
  • Hibernate reverse engineering is not perfect and does not do everything as logical as we humans might see it. There are many problems and edge cases that don't work. I run into these kinds of things all the time. Have you found the solution to this problem? I suspect Hibernate reverse engineering just cannot handle this. – Jason Mar 04 '22 at 17:03

1 Answers1

-1

The mapping is correct, because in this case one record from table B is referred to from several records from table A.

Example

  • Table A data:
  • ID ID_FROM_B
  • 1 1
  • 2 1
  • 3 2

  • Table B data:

  • ID
  • 1
  • 2

If you were getting records from table B and joining the A records on it you would get the results:

For B ID 1: ID(TableA) 1; ID(TableA) 2 -- This has to be put into a collection, That is why you get a pojo structure like that.

Sinisha Mihajlovski
  • 1,811
  • 1
  • 20
  • 34