-->
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: Mapping Hashmap of Coordinates in Hibernate with Annotation
PostPosted: Thu Apr 15, 2010 11:44 pm 
Newbie

Joined: Thu Apr 15, 2010 10:54 pm
Posts: 1
I've just started using hibernate and I'm trying to map walking distance between two coordinates into a hashmap, There can be many connections from one "FromCoordinate" to another "ToCoordinate". I'm not sure if i've implemented this correctly, What annotations do i need to map this MashMap? Thanks

HashMap> coordWalkingConnections = new HashMap>();


Code:
@Entity
@Table(name = "COORDCONNECTIONS")
public class CoordinateConnection implements Serializable{

    private static final long serialVersionUID = -1624745319005591573L;

    /** auto increasing id number */
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "ID")
    @id
    private int id;

    @Embedded
    public FromCoordinate fromCoord;

    @Embedded
    public ToCoordinate toCoord;


HashMap<FromCoordinate, ArrayList<ToCoordinate >> coordWalkingConnections = new HashMap<FromCoordinate, ArrayList<ToCoordinate >>();

}

public class FromCoordinate implements ICoordinate
{
    @Column(name = "FROM_LAT")
    private double latitude;

    @Column(name = "FROM_LNG")
    private double longitude;
}

public class ToCoordinate implements ICoordinate
{

    @Column(name = "TO_LAT")
    private double latitude;

    @Column(name = "TO_LNG")
    private double longitude;

    @Column(name = "DISTANCE")
    private double distance;
}

DATABASE STRUCTURE
id  FROM_LAT    FROM_LNG    TO_LAT      TO_LNG      Dist
1   43.352669   -6.264341   43.350012   -6.260653   0.38
2   43.352669   -6.264341   43.352669   -6.264341   0.00
3   46.352669   -6.264341   43.353373   -6.262013   0.17
4   47.352465   -6.265865   43.351290   -6.261200   0.25
5   45.452578   -6.265768   43.352788   -6.264396   0.01
6   45.452578   -6.265768   45.782788   -6.234523   0.01
    .....
    ...
    .

Example HashMap for HashMap<Coordinate, ArrayList<Coordinate>>


<KEY{43.352669  -6.264341}, Arraylist VALUES{(43.350012,-6.260653,0.383657),  (43.352669, -6.264341, 0.000095), (43.353373, -6.262013,  0.173201)}>
<KEY{47.352465  -6.265865}, Arraylist VALUES{(43.351290,-6.261200,0.258781)}>
<KEY{45.452578  -6.265768}, Arraylist VALUES{(43.352788,-6.264396,0.013726),(45.782788,-6.234523,0.017726)}>


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.