MyEclipse: Hibernate relationships incorrect with Oracle driver

budoray - Nov 07, 2005 - 04:29 PM
Post subject: Hibernate relationships incorrect with Oracle driver
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.
budoray - Nov 07, 2005 - 10:12 PM
Post subject:
Version: 3.1.0
Build id: I20050627-1435
Version: 4.0.1
Build id: 20050930-4.0.1-GA
support-rkalla - Nov 08, 2005 - 01:42 AM
Post subject:
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"?
budoray - Nov 09, 2005 - 03:40 PM
Post subject:
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.
support-rkalla - Nov 09, 2005 - 04:30 PM
Post subject:
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.
budoray - Nov 09, 2005 - 05:55 PM
Post subject:
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,
)
support-rkalla - Nov 09, 2005 - 06:52 PM
Post subject:
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...
budoray - Nov 09, 2005 - 07:19 PM
Post subject:
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
/
support-rkalla - Nov 09, 2005 - 07:32 PM
Post subject:
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?
budoray - Nov 09, 2005 - 07:44 PM
Post subject:
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.
support-rkalla - Nov 09, 2005 - 08:07 PM
Post subject:
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.

Quote:

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.
budoray - Nov 09, 2005 - 08:49 PM
Post subject:
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>
budoray - Nov 09, 2005 - 08:51 PM
Post subject:
Err .. quick genration of tables has TRACK_TYPE with a generator. There is no generator class for TRACK_TYPE.
support-rkalla - Nov 10, 2005 - 01:44 AM
Post subject:
4.1M1 still includes our old generator, M2 will include the new mapping generator.
budoray - Nov 10, 2005 - 03:42 PM
Post subject:
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.
budoray - Nov 10, 2005 - 04:02 PM
Post subject:
BTW .. The OCI problem is only an issue with Java 5.0. Java 1.4 works just fine.
budoray - Jan 03, 2006 - 11:18 PM
Post subject:
This problem perists with

Version: 3.1.0
Build id: I20050627-1435

Version: 4.0.200
Build id: 20051205-4.1-Milestone2
budoray - Jan 09, 2006 - 09:07 PM
Post subject:
4.1M2 has three (more) bugs.

1. Does not generate FK relationships.
2. Subclass is wiped out when new Abstract class is created.
3. Hibernate.cfg is not getting updated.
support-rkalla - Jan 09, 2006 - 09:50 PM
Post subject:
budoray,
I sent these to the hibernate team ASAP to look into, thank you for reporting them.
support-rkalla - Jan 09, 2006 - 10:15 PM
Post subject:
budoray,
1) Do you see any errors in your log file near the bottom related to this? (<workspace dir>\.metadata\.log)
2) In the example of table "business" that generates AbstractBusiness.java and Business.java, are you saying that Business.java is wiped out each time you regenerate?
3) To clarify, this is not getting updated when you regenerate the mappings, or did you mean something else?
4) Are you using the Oracle OCI or thin driver? If you are using OCI, can you try the thin (Type 4)?
budoray - Jan 10, 2006 - 03:55 AM
Post subject:
1. None
2. Yes. AbstractTrack is created. Track is overwritten as if it did not exist in the first place.
3. Yes. The hibernate.cfg.xml is NOT updated
4. Thin. See prior posts. Running into problems connecting with OCI driver.

This is frustrating. I posted the problem in November. I was asked to wait until M2. Problems are worse now. This is such a disappointment to me as I've come to rely on your plugin. I really do not wish to take the time to get accustomed to another plugin like Excadel, but mapping multiple, large Oracle databases, that change almost daily due to new requirements and with xref tables on top of that is too time consuming to simply ignore.

Look, I can live with the short comings of the Linux distribution. It would be great to have the flow designer to help facilitate the requirements and needs of both the operations and user groups that are driving the applications that I'm building. However, due to the size and frequent changes of the databases I query, a GREAT Hibernate tool is a MUST.
budoray - Jan 10, 2006 - 03:33 PM
Post subject:
Removed eclipse and myeclipse. Reinstalled both. Same problems except that I no longer get a log file to check. All that is present is the version.ini file.
support-rkalla - Jan 10, 2006 - 04:15 PM
Post subject:
budoray,
Two of us are working on this thread right now concurrently.

First I need to appologize for broken stream of help here in this thread, that is my fault for not catching up on the back story before replying and your frustration is absolutely justified. I would also like to thank you for keeping your head and sticking with us while we trouble shoot this with you.

Now onto the technical details. A developer from the Hib team and I have replicated the Track and TrackType tables in a local install of Oracle using the c reate table statements you provided. We both have 3.1.1 and 4.1M2 installed (as downloaded from the site) and have run through all this thread. We have found the following things and need your help understanding some others. I will use quote blocks below to address things you have posted in this thread thus far and try and number them so we can refer to them later.

1.
Quote:

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.

The additional mapping is harmless but correct from the testing we have done. We do not know why this does not occur with MySQL or SQL Server but a huge portion of the mapping generation logic is based off of the JDBC driver being used. That can effect a mapping generation from failing, to getting the wrong type to creating false relationships. There may be something in the oracle driver that reports additional metadata back to the generation logic that ends up creating the inverse of the m2o.

2.
Quote:

Does not generate FK relationships.

Neither of us could reproduce this. As I mentioned above the m2o and o2m were both created using 4.1M2 from the Oracle tables you gave us above. We also generated ERD diagrams and the relationship was correctly visualized. To make sure, we also generated the DDL for the tables and correctly saw the FK relationship.

3.
Quote:

Subclass is wiped out when new Abstract class is created.

This is absolutely a bug that will be fixed ASAP. The concrete subclass should not be touched after it's first generation step.

4.
Quote:

Hibernate.cfg is not getting updated.

We cannot reproduce this. We tried regenerating the TrackType to a new package, and the hibernate.cfg.xml file was updated with the new hbm.xml record. We also tried genning a new table that hadn't been mapped before and it was correctly added. Please tell us which steps you took to establish that the update is not being performed.
budoray - Jan 10, 2006 - 05:29 PM
Post subject:
As I mentioned, the db changes very frequently right now. They are regenerating indexes and fk relationships at the moment. I will update this thread the moment I remap.
Support-Brian - Jan 10, 2006 - 05:39 PM
Post subject:
On issue 4 - could you open your project properties and go to the MyEclipse-Hibernate page. Does the "Active configuration file:" point to an existing and valid hibernate configuration file?

If the configuration file fails to update, an error log will almost certainly be generated. Just in case you are looking in the wrong location, you can go to MyEclipse > About MyEclipse > Configuration Summary and click View Error Log.

Best,
Brian.
snpe - Jan 10, 2006 - 09:39 PM
Post subject:
i have try read this thread and i think that i know why budoray don't get 'set' mapping when using mysql or ms sql server

they haven't define foreign key in this databases

it is easy check

have you next when using mysql/ms sql :

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

probably , not

hibernate tools generate many-to-one/one-to-many (foreign keys) relation with <many-to-one> on one side and collection (set) on another side - this is same for every databases - i ask for features taht exclude this in reveng.xml, but it isn't possible for now

drivers or database isn't problem - it is same if you use oci or thin (oci isn't pure java driver and you have add oracle native client libraries in path for oci)

and one question for budoray : how big is change in databases that this support is so hard - how many tables,keys and changes
I think that you can't find perfect tools for generating mapping from database - this tools have to be general, but
you have special requests, probably
I use tool (hibernate tools and myeclipse) for first outline mapping, only and i have to change it alwyas
budoray - Jan 10, 2006 - 10:35 PM
Post subject:
Track table has seven FK. I only get one mapping. The database explorer shows the seven constraints on the FK tab as expected.

What I've found is that I have to select each table referenced as a FK to get the correct mapping.
budoray - Jan 10, 2006 - 10:57 PM
Post subject:
SNPE - Many, many, many tables on multiple databases. This is more like a 'mining' operation where one database is built by two others. PKs and FKs are added and removed, tables are dropped, renamed, and more are added as the requirements are further defined. Mapping them by hand is not hard, rather, it's tedious, time consuming, and prone to more mistakes made by this overworked developer <smile>. The difference with the MySQL and Oracle dbs was the 'set' mapping generation that can be ignored since it appears to be driver specific.

I don't think I'm asking for anything special. Subclasses shouldn't be overwritten (thus the AbstractClass generation) and selecting to regenerate a table mapping shouldn't force me to select each referenced table (Those tables have many FK and those references have FK etc) just to regenerate one table. This was not the case prior to the 4.0 release. (Different engine as explained above).
support-rkalla - Jan 10, 2006 - 11:03 PM
Post subject:
Quote:

Subclasses shouldn't be overwritten (thus the AbstractClass generation)

This is a bug, we will get it fixed.

Quote:

and selecting to regenerate a table mapping shouldn't force me to select each referenced table (Those tables have many FK and those references have FK etc) just to regenerate one table.

This wasn't a use case we tested, while I believe the developer will agree with you I don't know if the change necessary to make it work the way it should will make it into 4.1. I'll discuss it with him in a few hours.
snpe - Jan 10, 2006 - 11:07 PM
Post subject:
pre 4.0 releases had simple mapping - i can't use it
i think that you have to make your templates (.vm files) if you have too much changes in database

i don't understand yet whta mean 'multiple database' - dou you have different changes in different databases or
changes propagate to all databases - for former you have to make one mappings for all databases - i can't think anout first scenario
budoray - Jan 10, 2006 - 11:34 PM
Post subject:
That's great news. Once the over write bug is fixed, then the problem of having to select each referenced table when mapping will not be as severe and I have a workaround (Just need to check the FK before remapping).
budoray - Jan 23, 2006 - 04:10 PM
Post subject:
The subclass is no longer being overwritten. However, I'm still forced to select each table that has a FK (and the tables that have FK to it, etc) to the table I'm trying to generate. This is a problem in that I have to overwrite the subclass now to get the FK relationships due to the constructors that are created.

Selecting one table creates something like this for subclass
public Track(String trackTypCd, Long genreId, String langCd....){
super(...);
}

Selecting FK tables will create something like this for subclass
public Track(TrackType trackType, Genre genre, Language language...){
super(....);
}

Now the subclass will be broken if I change a mapping and regenerate i.e I no longer need a Language for the Track. The AbstractTrack will be fine, but the Track class will contain a constructor that is no longer valid.
budoray - Jan 23, 2006 - 04:11 PM
Post subject:
Sorry, 4.1GA
budoray - Jan 23, 2006 - 04:15 PM
Post subject:
Also, hibernate.cfg.xml is not being updated. I can remove the reference manually, regenerate the mapping, and my config files remains the same.
support-rkalla - Jan 23, 2006 - 04:26 PM
Post subject:
Quote:

The subclass is no longer being overwritten. However, I'm still forced to select each table that has a FK (and the tables that have FK to it, etc) to the table I'm trying to generate. This is a problem in that I have to overwrite the subclass now to get the FK relationships due to the constructors that are created.

This is a known issue, it is filed but hasn't been targetted for a release yet. We realize this is a show-stopper for folks with larger tables with more FKs so we are treating it as a high priority item.

On the subclass regeneration front, the policy is simple, don't regenerate if subclass already exists. Now if you change the mapping, the subclass will obviously be stale. What do you suggest, should we change only the consructors or overwrite the entire class?

Quote:

Also, hibernate.cfg.xml is not being updated. I can remove the reference manually, regenerate the mapping, and my config files remains the same.

We were never able to reproduce this internally when we ran through simultaneously on different builds over here.

Can you, just for testing, create a new project, add Hib caps to it pointing at your same data source that you are using now, then gen all the tables. Did your cfg.xml file get updated?
budoray - Jan 23, 2006 - 05:21 PM
Post subject:
Prior to 4.1, if I recall correctly, we had an empty constructor and a constructor that took the PK. Now, we get constructors with all the columns from the table. I think the fix for the problem is the need to fix the problem of having to select all of the tables with FK. With that done, then you could invalidate the generated constructors that are no longer valid due to the new mappings. Maybe there's a better approach, but overwriting the entire subclass is out of the question.

Creating a new project and adding hibernate capabilities fixes the problem with the config file.
All times are GMT - 6 Hours
Powered by PNphpBB2 © 2003-2004 The PNphpBB Group
Credits