-->
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.  [ 1 post ] 
Author Message
 Post subject: [newbie] Collection mapping problem
PostPosted: Tue Jan 04, 2005 10:18 pm 
Newbie

Joined: Mon Jan 03, 2005 5:21 am
Posts: 2
Hi,

I have 2 tables (on MySQL, * = primary key).
1. Flight (flight_id*, flight_number, ....)
2. Stopovers (flight_number*, airport*, list_index)

I've got one class (Flight.java) and want to maintain a List of airports within based on the flight number(which is not the key).

Code:

public class Flight {
private String flightId;
private String flightNumber;
private List stopovers;

public String getFlightId() {
   return flightId;
}

public List getStopovers() {
   return stopovers;
}

public String getFlightNumber() {
   return flightNumber;
}
..............
}



Mapping documents:
Code:
<hibernate-mapping>
....
     <id
            name="flightId"
            column="flight_id"
            type="java.lang.String"
            unsaved-value="null"
        >
            <generator class="uuid.hex">             
            </generator>
        </id>
      <property
            name="flightNumber"
            type="java.lang.String"
            column="flight_number"
        />

<list
            name="stopovers"
            table="stopovers"
            lazy="true"
            cascade="none"
        >
              <key
              >
                <column
                    name="flight_number"
                />
              </key>
              <index
                  column="list_index"
              />
              <element
                  column="airport"
                  type="string"
                  not-null="false"
                  unique="false"
              />
        </list>

....



problem

The code works but it builds the relationship between the primary keys Flight(flight_id*) and Stopovers (*flight_number), so when it create a flight it adds the value of flight_id (which is hex) to the Stopover(flight_number).

What I want to achieve is to have the relationship between Flight(flight_number) and Stopovers (*flight_number).

How can I achieve this ?

Appreciate any help.

_________________
-------
Kasun.


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

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.