facebook

hibernate.reveng.xml not picking up BLOB types

  1. MyEclipse IDE
  2.  > 
  3. Java EE Development (EJB, JSP, Struts, XDoclet, etc.)
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #349460 Reply

    raydawg2000
    Participant

    By default, ME2014 is mapping my sql BLOB type to a String but i want it mapped to a byte[]. I am using the reveng.xml file to dictate this but it is not working.

    
    <type-mapping>
        <sql-type jdbc-type="BLOB" hibernate-type="java.sql.Blob" not-null="true"></sql-type>
        <sql-type jdbc-type="DATE" hibernate-type="java.util.Date" not-null="true"></sql-type>
    </type-mapping>
    
    <table name="admin_user" catalog="apc">
            <column name="salt" jdbc-type="BLOB" type="java.sql.Blob"></column>
    </table>
    
    
    CREATE TABLE `admin_user` (
        `netid` VARCHAR(40) NOT NULL,
        `first_name` VARCHAR(40) NOT NULL,
        `last_name` VARCHAR(40) NOT NULL,
        `email` VARCHAR(40) NOT NULL,
        `phone` VARCHAR(40) NOT NULL,
        `password` BLOB NOT NULL,
        `salt` BLOB NOT NULL,
        `create_date` DATE NOT NULL,
        `timestamp` TIMESTAMP NOT NULL,
        `active` BOOL DEFAULT 1,
        CONSTRAINT `PK_admin_user` PRIMARY KEY (`netid`)
    )

    .

    
    <property name="password" type="java.lang.String">
                <column name="password" not-null="true" />
    </property>
    <property name="salt" type="byte[]">
                <column name="salt" not-null="true" />
    </property>

    Note that when I specifically map the column it works fine as is the case for the “salt” property. But when i use the type-mapping list to map all BLOB types, it does not work and the default is used as with the case of “password”. My mapping file generates with password as a String and Salt as a Blob type, but both should be Blob type.

    The hibernate-reveng wizard has other properties for matching such as Lenght, Scale, Precision and I have messed around with all of these but I still can’t get the mapping generated to work right

    #349468 Reply

    raydawg2000,

    We could get all the Blob types changed to byte[] after adding the type mapping in hibernate.reveng.xml file.

    Can you please make sure that you have selected ‘Hibernate types’ for the Type Mapping option under the 2nd wizard of Hibernate reverse engineering wizard ? Please see the attached screenshot for the visual reference.

    Here are the steps that I followed :
    1) Created a web project and added hibernate facets(4.1) with MySql connection to the web project.
    2) Right clicked on the admin_user table and selected Hibernate reverse engineering
    3) In the 1st wizard of hibernate reverse engineering, I have selected src folder, package, create POJO<>DB Table mapping information, Java data object, Java data access object and clicked Next
    4) In the second wizard, selected the reverse engineering file, selected Hibernate types as the Type mapping and clicked Finish.
    Hibernate-reveng.xml file :

    <type-mapping>
            <sql-type jdbc-type="BLOB" hibernate-type="java.sql.Blob"
                not-null="true">
            </sql-type>
            <sql-type jdbc-type="DATE" hibernate-type="java.util.Date"
                not-null="true">
            </sql-type>
        </type-mapping>

    Take a look at the screenshot of the generated code

    If there are any changes that you have done other than the steps that I followed, please mention those changes so that we could investigate further.

    Let us know how it works for you.

    #349473 Reply

    raydawg2000
    Participant

    Thanks, switching to “hibernate types” fixed the problem. For future reference, are there other jdbc-types that will only generate correctly if “hibernate types” is selected?

    I ask because I messed around with a few other types and had no issue using “java types”. So it seems weird that BLOB seems to be the only type that requires “hibernate types” to be selected and perhaps that should be documented somewhere if that is the case.

    thanks

    #349474 Reply

    raydawg2000
    Participant

    Thanks, switching to “hibernate types” fixed the problem. For future reference, are there other jdbc-types that will only generate correctly if “hibernate types” is selected?

    I ask because I messed around with a few other types and had no issue using “java types”. So it seems weird that BLOB seems to be the only type that requires “hibernate types” to be selected and perhaps that should be documented somewhere if that is the case.

    thanks

    #349491 Reply

    raydawg2000,

    Glad that you got it working. I have filed a documentation request to explain all the options in Hibernate reverse engineering wizard.
    Let us know if you see any issues or have any questions on MyEclipse.

Viewing 5 posts - 1 through 5 (of 5 total)
Reply To: hibernate.reveng.xml not picking up BLOB types

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