facebook

Hibernate relationships incorrect with Oracle driver

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

    Daniel Ray
    Member

    Generating Hibernate mappings via DB explorer is creating relationships that do not exist in the Oracle DB. DB has two tables, TRACK and TRACK_TYPE.

    TRACK has a TRACK_TYPE via the TRACK_TYP_CD and the created mapping is <many-to-one name=”trackType” column=”TRACK_TYP_CD” class=”TrackType” /> which is correct.

    I also get the following mapping for TRACK_TYPE
    <set name=”trackSet” inverse=”true”>
    <key column=”TRACK_TYP_CD”/>
    <one-to-many class=”Track”/>
    </set>

    I do not get this mapping when using MySQL or SQL Server. I am using the classes14.jar. Any advice would be helpful as the DB is still being refined and manually editing the hbm files each time is becoming too time consuming.

    #240968 Reply

    Daniel Ray
    Member

    Version: 3.1.0
    Build id: I20050627-1435
    Version: 4.0.1
    Build id: 20050930-4.0.1-GA

    #240978 Reply

    Riyad Kalla
    Member

    1) Please post the C REATE TABLE scripts for the two tables, NOTE you will need to break up the SQL keywords because we have a security plugint hat will stop the posting of the scripts.

    2) Where did classes14.jar come from and how are you “using it”?

    #241122 Reply

    Daniel Ray
    Member

    Heres the setup in the config file. (elipses used to hide connection info)

    <hibernate-configuration>
    <session-factory>
    <property name=”myeclipse.connection.profile”>LDSMETA</property>
    <property name=”connection.url”>jdbc:oracle:thin:@…</property>
    <property name=”connection.username”>…</property>
    <property name=”connection.password”>…</property>
    <property name=”connection.driver_class”>oracle.jdbc.driver.OracleDriver</property>
    <property name=”dialect”>org.hibernate.dialect.Oracle9Dialect</property>

    Create script for Track table
    c-reate table “LDSMETA”.”TRACK”(
    “TRACK_ID” NUMBER(12) PRIMARY KEY not null,
    “TRACK_TYP_CD” CHAR(1),
    “TRACK_TITLE” VARCHAR2)

    Create script for Track_Type table
    c-reate table “LDSMETA”.”TRACK_TYPE”(
    “TRACK_TYP_CD” CHAR(1) PRIMARY KEY not null,
    “TRACK_TYP_DESC” VARCHAR2 not null,
    “ACTIVE” CHAR(1) default ”N’ ‘ not null)

    I gave the wrong jar name in my haste. The correct jar that contains the Oracle driver is ojdbc14.jar.

    #241136 Reply

    Riyad Kalla
    Member

    I think you may have excluded any of the Foreign Key constraints from your c-reate table scripts, because from what you posted above I’m not sure how you ended up with a m2o or even a set relationship… can you post the entire generated c-reate table script for me? I want to try and reproduce this issue locally.

    #241165 Reply

    Daniel Ray
    Member

    Well, the script was created using the db tool. Bug in the ‘generate table script’ option? FK shows up in my .mer file.

    Here’s the script from the Oracle DBA.
    C-REATE TABLE LDSMETA.TRACK
    (
    TRACK_ID NUMBER(12) NOT NULL,
    TRACK_TYP_CD CHAR(1) NULL,
    TRACK_TITLE VARCHAR2(256) NULL,
    CONSTRAINT TRACK_FK1
    FOREIGN KEY (TRACK_TYP_CD)
    REFERENCES LDSMETA.TRACK_TYPE (TRACK_TYP_CD)
    ENABLE,
    )

    #241170 Reply

    Riyad Kalla
    Member

    Sorry, could you also post the TRACK_TYPE script as well, I’m still not seeing a reason why the hibernate mapper decided to create a set for you, very odd…

    #241174 Reply

    Daniel Ray
    Member

    Track Type script is in earlier post. Could the indexes on the tables be causing the problems? I have the same problem for all the tables in the db where one table has a m2o relationship to another and I get a o2m (set) on the ‘another’ table. Could the driver be the problem? Oracle 10.1.0.4.

    C-REATE INDEX LDSMETA.TRACK_IX1
    ON LDSMETA.TRACK(TRACK_TYP_CD)
    A-LTER TABLE LDSMETA.TRACK
    ADD CONSTRAINT TRACK_PK
    PRIMARY KEY (TRACK_ID)
    ENABLE
    VALIDATE

    C-REATE INDEX LDSMETA.TRACK_TYPE_PIX
    ON LDSMETA.TRACK_TYPE(TRACK_TYP_CD)
    A-LTER TABLE LDSMETA.TRACK_TYPE
    ADD CONSTRAINT TRACK_TYPE_PK
    PRIMARY KEY (TRACK_TYP_CD)
    ENABLE
    VALIDATE
    /

    #241176 Reply

    Riyad Kalla
    Member

    It is certainly possible that the driver is returning metadata that is causing the mapping generator to create that set. If possible, could you wait a few weeks for our 4.1M2 release and try using the new mapping generator that will be in that version? We are completely replacing it, so I would hate to spend a lot of time analyzing every possible problem here, and then have all of it fixed when 4.1M2 get’s released.

    Is this a viable option for you for the time being?

    #241177 Reply

    Daniel Ray
    Member

    It’s frustrating being that I paid for a pro version of the software and haven’t really gained anything by doing so. I’ll try a few other Oracle drivers in the meantime being that I already have to wait on other features available for Windows that aren’t available for Mac and Linux. Again, waiting appears to be the norm now.

    #241181 Reply

    Riyad Kalla
    Member

    Ok so clearly this is not a viable option, I’ve asked a developer from the Hibernate team to look into this to hopefully find a temporary workaround for you.

    I’ll try a few other Oracle drivers in the meantime being that I already have to wait on other features available for Windows that aren’t available for Mac and Linux. Again, waiting appears to be the norm now.

    The only feature that is Windows only is the new designer which is in the process of being ported to Mac/Linux. The only features that isn’t on the Mac due to an SWT-bug in the Eclipse platform itself is the UML editor.

    #241186 Reply

    Daniel Ray
    Member

    Upgraded to 4.1m1 ( New Hibernate Mapping Editor and custom Outline View ) and problem persists

    <hibernate-mapping package=”…”>

    <class name=”Track” table=”TRACK”>
    <id name=”trackId” column=”TRACK_ID” type=”java.lang.Long”>
    <generator class=”increment”/>
    </id>

    <property name=”trackTitle” column=”TRACK_TITLE” type=”java.lang.String” />

    <many-to-one name=”trackType” column=”TRACK_TYP_CD” class=”TrackType” />

    </class>

    </hibernate-mapping>

    <hibernate-mapping package=”…”>

    <class name=”TrackType” table=”TRACK_TYPE”>
    <id name=”trackTypCd” column=”TRACK_TYP_CD” type=”java.lang.String”>
    <generator class=”increment”/>
    </id>

    <property name=”trackTypDesc” column=”TRACK_TYP_DESC” type=”java.lang.String” not-null=”true” />
    <property name=”active” column=”ACTIVE” type=”java.lang.String” not-null=”true” />

    <set name=”trackSet” inverse=”true”>
    <key column=”TRACK_TYP_CD”/>
    <one-to-many class=”Track”/>
    </set>
    </class>

    </hibernate-mapping>

    #241187 Reply

    Daniel Ray
    Member

    Err .. quick genration of tables has TRACK_TYPE with a generator. There is no generator class for TRACK_TYPE.

    #241206 Reply

    Riyad Kalla
    Member

    4.1M1 still includes our old generator, M2 will include the new mapping generator.

    #241247 Reply

    Daniel Ray
    Member

    Fair enough. I’ve manually edited the generated files and classes to correctly reflect the db. I had no luck getting the oci driver to work even after installing the Instant Client. For now, I’m going to leave things as they are and refrain from using the db tools within Myeclipse until the M2 release due to the number of tables I’m dealing with. Again, this is one of several db that I will have to work with and being able to quickly generate my hibernate mappings and classes will greatly reduce my overtime. Not to mention the changes needed as each of the db evolve.

Viewing 15 posts - 1 through 15 (of 36 total)
Reply To: Hibernate relationships incorrect with Oracle driver

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