-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 
Author Message
 Post subject: Middlegen output for self-referencing tables
PostPosted: Wed Dec 31, 2003 4:44 pm 
Regular
Regular

Joined: Tue Nov 11, 2003 7:35 pm
Posts: 63
I have a table that references itself. Here is the definition:
Code:
CREATE TABLE QW_EMPLOYEE
(
  EMPLOYEE_ID  NUMBER,
  FIRST_NAME   VARCHAR2(20),
  LAST_NAME    VARCHAR2(30),
  MANAGER_ID   NUMBER
);
ALTER TABLE QW_EMPLOYEE ADD (
  CONSTRAINT PK_QW_EMPLOYEE PRIMARY KEY (EMPLOYEE_ID)
);
ALTER TABLE QW_EMPLOYEE ADD (
  CONSTRAINT TEST_FK FOREIGN KEY (MANAGER_ID)
    REFERENCES QW_EMPLOYEE (EMPLOYEE_ID)
);


Notice that MANAGER_ID is a reference to another record in the table (the manager is also an employee!) Running this table through middlegen though produces the following file:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
   
<hibernate-mapping>
<!--
    Created by the Middlegen Hibernate plugin

    http://boss.bekk.no/boss/middlegen/
    http://hibernate.sourceforge.net/
-->

<class
    name="testQwb.hibernate.persistent.QwEmployee"
    table="QW_EMPLOYEE"
>

    <id
        name="employeeId"
        type="java.lang.Integer"
        column="EMPLOYEE_ID"
    >
        <generator class="assigned" />
    </id>

    <property
        name="firstName"
        type="java.lang.String"
        column="FIRST_NAME"
        length="20"
    />
    <property
        name="lastName"
        type="java.lang.String"
        column="LAST_NAME"
        length="30"
    />

    <!-- associations -->
    <!-- bi-directional many-to-one association to QwEmployee -->
    <many-to-one
        name="qwEmployee"
        class="testQwb.hibernate.persistent.QwEmployee"
        not-null="true"
    >
        <column name="MANAGER_ID" />
    </many-to-one>

</class>
</hibernate-mapping>

Notice the many-to-one association. For some reason, Middlegen named the associated column "qwEmployee" instead of "managerID" or "managerIdQwEmployee" or something with at least the name "manager" in it! Is there some way in middlegen to be able to specify this, or to change the name to a more appropriate one?

Thanks and Happy New Year,
Daniel


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 04, 2004 12:02 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Not at the moment. Custom field and Class names is due to be added (and is not that difficult (maybe turn into being a bit fiddly) just need to map the custom name to the internal name).


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 22, 2004 1:04 pm 
Newbie

Joined: Wed Jul 14, 2004 10:30 am
Posts: 3
Location: Tampa, FL
Has support for custom field names been added yet? I am having this same exact problem. If I could name the property in either the crossref tag or if there is a setting to force it to use the column names that would work for me.

(currently using Middlegen-Hibernate-R5)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 22, 2004 9:55 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
I have not done it as yet (always other things get in the way).
The second option I have played with a little still not happy but I could commit it this weekend.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 23, 2004 9:44 am 
Newbie

Joined: Wed Jul 14, 2004 10:30 am
Posts: 3
Location: Tampa, FL
Ok, if you do commit it I will try it out.

If all else fails we are considering writing something that processes the hbm.xml files after they are generated and renames the fields.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 23, 2004 5:53 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Ant has a nice regex search and replace tag. An example (with a different purpose) is on the middlegen wiki page.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 28, 2004 10:38 am 
Newbie

Joined: Wed Jul 14, 2004 10:30 am
Posts: 3
Location: Tampa, FL
Thanks for the tip, I will give that a try.

_________________
Nilesh Kapadia


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 28, 2004 6:55 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
I have commit a method to replace the name generation code if you choose to. Its similar to how the JavaTypeMapper can be replaced. I still need to clean up a few items but its the first step. I have also commit an option to turn the plurisation etc off if you choose to.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.