Welcome to dbForumz.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

How to map the table classes have more than one columns fo..

 
   Database Forums (Home) -> Java RSS
Next:  Java Developer/Powerbuilder Developer, Provo, UT.  
Author Message
RC

External


Since: May 04, 2005
Posts: 1



(Msg. 1) Posted: Thu Apr 10, 2008 8:38 am
Post subject: How to map the table classes have more than one columns for its primary
Archived from groups: comp>text>xml, others (more info?)

I have two existed tables, I am NOT allow to altering those tables
The 1st table (tableA) has one column for its primary key, the 2nd
table (tableB) has tow columns for its primary key. I am try to map
these two tables with Hibernate XML. Here are my XML file.

Please see ????? in tow places.

Question 1
1st ???? is <many-to-many> tag in class TableA, but <many-to-many> tag
only allows one column. How do I map it for two columns?

Question 2
2nd ????? is the <key> tag in class TableB, similar that <key> tag only
allows one column. How do I map it for two columns?

Thank Q very much in advance!

<hibernate-mapping auto-import="false"
default-lazy="true" default-access="field">

<class name="tableA" table="TABLEA" entity-name="TableA.class">
<id name="tableAId" type="string" column="TABLEAID"

access="field">
<generator class="native">
<param name="key">TABLEAID</param>
</generator>
</id>
<property name="column1" type="string" column="COLUMN1" />
<property name="column2" type="string" column="COLUMN2" />
.....
<set name="idsa" table="IDS" inverse="true">
<key column="TABLEAID" />
<many-to-many column="????" class="tableB" />
</set>
</class>

<class name="tablesB" table="TABLEB" entity-name="TableB.class">
<composite-id>
<!-- this table's primary key has two columns -->
<key-property name="tableBId1" type="string"
column="TABLEBID1" />
<key-property name="tableBId2" type="integer"
column="TABLEBID2" />
</composite-id>
<property name="column1" type="string" column="COLUMN1" />
<property name="column2" type="string" column="COLUMN2" />
....
<set name="idsb" table="IDS">
<key column="?????" />
<many-to-many column="TABLEAID" class="tableA" />
</set>
</class>
</hibernate-mapping>

 >> Stay informed about: How to map the table classes have more than one columns fo.. 
Back to top
Login to vote
David Lee Lambert

External


Since: Apr 10, 2008
Posts: 1



(Msg. 2) Posted: Thu Apr 10, 2008 11:49 am
Post subject: Re: How to map the table classes have more than one columns for its [Login to view extended thread Info.]
Archived from groups: comp>lang>java>databases (more info?)

On Apr 10, 8:38 am, RC wrote:
> I have two existed tables, I am NOT allow to altering those tables
> The 1st table (tableA) has one column for its primary key, the 2nd
> table (tableB) has tow columns for its primary key. I am try to map
> these two tables with Hibernate XML. Here are my XML file.

First of all, the column "TABLEAID" can't use a "native" generator,
because it's a string column;
you probably need "assigned" (the default), or possibly need to write
your own.

Second, are you allowed to create the join table (IDS)?

To answer both of your questions, you should be able to have multiple
<column> elements in a <key> or <many-to-many> elements, instead of
one "column" attribute.



> <hibernate-mapping auto-import="false"
> default-lazy="true" default-access="field">
>
>      <class name="tableA" table="TABLEA" entity-name="TableA.class">
>          <id name="tableAId" type="string" column="TABLEAID"
>
>                                              access="field">
>              <generator class="native">
>                  <param name="key">TABLEAID</param>
>              </generator>
>          </id>
>          <property name="column1" type="string" column="COLUMN1" />
>          <property name="column2" type="string" column="COLUMN2" />
>          .....
>          <set name="idsa" table="IDS" inverse="true">
>              <key column="TABLEAID" />
>              <many-to-many column="????" class="tableB" />
>          </set>
>       </class>
>
>        <class name="tablesB" table="TABLEB" entity-name="TableB.class">
>          <composite-id>
>          <!-- this table's primary key has two columns -->
>              <key-property name="tableBId1" type="string"
>                                             column="TABLEBID1" />
>              <key-property name="tableBId2" type="integer"
>                                             column="TABLEBID2" />
>          </composite-id>
>          <property name="column1" type="string" column="COLUMN1" />
>          <property name="column2" type="string" column="COLUMN2" />
>          ....
>          <set name="idsb" table="IDS">
>              <key column="?????" />
>              <many-to-many column="TABLEAID" class="tableA" />
>          </set>
>        </class>
> </hibernate-mapping>

--
DLL

 >> Stay informed about: How to map the table classes have more than one columns fo.. 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
How to know columns names in Derby database table - Hi! I'm trying this: [...] Vector<String> vNames = new Vector<String>(); String[] names; try { ResultSet myRs; Class.forName("org.apache.derby.jdbc.EmbeddedDriver"); con = DriverManager.getConnection("jdbc:derby:/ho...

Does Hibernate remove local var syms from non-mapped class.. - I believe that Hibernate does dynamic bytecode modification of classes specified in the mapping file, correct? Assuming that's true, is there any possibility that Hibernate could possibly have any impact on other classes that are not specified in the..

Testing for empty columns in resultset - This seems too trivial. After populating a resultset with a query, what is the best way to test if a column is null to avoid the dreaded null pointer exception when attempting a tostring() call. thanks

SimpleORM and MySQL auto-increment columns - Hi, I'm trying to integrate SimpleORM into my application but can't work out how to get the value of the auto-increment column of a table (the ID column - also the primary key)? (The database is MySQL, but I don't think it's entirely relevant to the..

Joining every row from 1 table to every row from another - Hello! Answer is propably simple, but I'm struggling and can't solve this problem. I have two tables: Table GARMENT STYLE_NO DESCRIPTION LABOUR_COST NOTIONS 1 Trousers 18 2 Long Skirt 15 Zip/ 1 cm off 3 Shorts 10 Zip/ Clip Table..
   Database Forums (Home) -> Java All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]