facebook

Hibernate reverse engineering problems

  1. MyEclipse Archived
  2.  > 
  3. Database Tools (DB Explorer, Hibernate, etc.)
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #256808 Reply

    Hi

    using MyEclipse 5.01 I am trying to create hibernate mapping files and pojo classes from my db schema.
    So far, everything works, except the type mapping.

    Neither by defining global custom types, nor by specifying an eclipicit column type, any of these types are used:
    NUMBER(1) -> Long instead of boolean
    TIMESTAMP -> String instead of Date

    Event the classname I defined is ignored.

    Here is my db schema:
    CREATE TABLE LOTMLCYCLE (
    YEAR NUMBER(4) NOT NULL,
    ACTIVE NUMBER(1) DEFAULT 0,
    START_DATE TIMESTAMP NOT NULL,
    END_DATE TIMESTAMP NOT NULL,
    UNHIDE_TIME NUMBER(4) NOT NULL,
    COVERED_IMAGE_INDEX NUMBER(9),
    CONSTRAINT LOTMLCYCLE_PK PRIMARY KEY(YEAR)
    );

    Here is my hibernate.reveng.xml:
    <hibernate-reverse-engineering>

    <type-mapping>
    <sql-type jdbc-type=”NUMBER(4)” hibernate-type=”int” />
    <sql-type jdbc-type=”TIMESTAMP” hibernate-type=”java.util.Date” />
    </type-mapping>
    <table name=”LOTMLCYCLE” schema=”STR” class=”MioLotCycle”>
    <primary-key>
    <generator class=”assigned”></generator>
    <column name=”YEAR” type=”int” />
    </primary-key>
    <column name=”ACTIVE” type=”boolean” />
    <column name=”UNHIDE_TIME” type=”int” />
    <column name=”COVERED_IMAGE_INDEX” type=”int” />
    </table>
    </hibernate-reverse-engineering>

    and here is the generated POJO:

    public class Lotmlcycle implements java.io.Serializable {
    // Fields
    private Long year;
    private Long active;
    private String startDate;
    private String endDate;
    private Long unhideTime;
    private Long coveredImageIndex;

    Thank for your support

    #256821 Reply

    Brian Fernandes
    Moderator

    Rodge,

    Could you check your log file when you invoke the Reverse engineering process? I think you migh see a log saying “Error processing rev-eng settings file” as NUMBER is not a valid JDBC type.
    As a result of this, all the other settings in your file are being skipped as well.

    My suggestion is to replace NUMBER on page 2 with INTEGER. If that does not work, remove the row entirely and use the custom setting on page 3.
    I realize that the error in custom RE settings file must be made more apparent.

    Let us know how it goes,
    Best,
    Brian.

    #256878 Reply

    Thanks, that is it! I deleted custom type mappings and defined every column by hand. A cool feature would be, if the wizard would list all JDBC types which are used in the selected tables and then let the user enter the mapped type for each…

    Now another last problem: I get all my pojos generated in the default package, although I selected another existing package. I remenber, that during my tests, they have been put into the right package once, but I cannot reproduce it. I have no idea what could be wrong…

    #256883 Reply

    Brian Fernandes
    Moderator

    Rodge,

    A cool feature would be, if the wizard would list all JDBC types which are used in the selected tables and then let the user enter the mapped type for each…

    Typically, the RE process should have generated the right types already and there should be no need for you to use page 2 or page 3 to customize the types. Putting in all the types in there sort of forces the user to specify them. Did you need to specify types for all your columns?

    I get all my pojos generated in the default package, although I selected another existing package. I remenber, that during my tests, they have been put into the right package once, but I cannot reproduce it. I have no idea what could be wrong…

    There is a package field on page 1, besides that, if you customized the class name, make sure you enter the fully qualifed name, not just the simple name of the class. My guess is you’re just specifying the simple name, I’ll try to make that label more explict.

    Let us know how it goes,
    Brian.

    #256997 Reply

    Brain,

    I needed to specify the following types, which I used in my Oracle 9 Schema:
    Timestamp -> Date (instead of String)
    Number(1) -> boolean (instead of Long)
    Number(8) -> int or Integer (instead of Long)

    I guess the boolean is difficult to map automatically, since a Byte could also be appropriate… Unfortunately Oracle has no BOOL type….
    At least the Timestamp should always be mapped to java.util.Date, as well as Oracle DATE, which also gets mapped to String.

    You are right, I only set the simple class names on page 3 since I was expecting the Reverse engineering wizard to use the package I specified on page 1 to prefix the classnames… I see, that if I could use the same names for tables as for the pojos, everything would have worked fine. Unfortunately we have some guidelines in our company which prevents me from giving the pojos names to the tables… Additionally, Oracle Table names are caseinsensitive, and thus would lead to unsatisfying pojo classnames like Transactionhistory (instead of TransactionHistory).

    Thank you

    Roger

Viewing 5 posts - 1 through 5 (of 5 total)
Reply To: Hibernate reverse engineering problems

You must be logged in to post in the forum log in