Hibernate design to speed up querying of large dataset

Posted by paddydub on Stack Overflow See other posts from Stack Overflow or by paddydub
Published on 2010-04-28T20:17:35Z Indexed on 2010/04/28 20:27 UTC
Read the original article Hit count: 299

I currently have the below tables representing a bus network mapped in hibernate, accessed from a Spring MVC based bus route planner I'm trying to make my route planner application perform faster, I load all the above tables into Lists to perform the route planner logic.

I would appreciate if anyone has any ideas of how to speed my performace Or any suggestions of another method to approach this problem of handling a large set of data

    Coordinate Connections Table (INT,INT,INT, DOUBLE)( Containing 50,000 Coordinate Connections)
    ID, FROMCOORDID, TOCOORDID, DISTANCE
    1   1               2       0.383657
    2   1               17      0.173201
    3   1               63      0.258781
    4   1               64      0.013726
    5   1               65      0.459829
    6   1               95      0.458769

    Coordinate Table (INT,DECIMAL, DECIMAL) (Containing 4700 Coordinates)
    ID ,  LAT,       LNG
    0   59.352669   -7.264341
    1   59.352669   -7.264341
    2   59.350012   -7.260653
    3   59.337585   -7.189798
    4   59.339221   -7.193582
    5   59.341408   -7.205888

    Bus Stop Table (INT, INT, INT)(Containing 15000 Stops)
    StopID    RouteID COORDINATEID
    1000100001  100     17  
    1000100002  100     18  
    1000100003  100     19  
    1000100004  100     20  
    1000100005  100     21  
    1000100006  100     22  
    1000100007  100     23  

This is how long it takes to load all the data from each table:

    stop.findAll  = 148ms,  stops.size: 15670
    Hibernate: select coordinate0_.COORDINATEID as COORDINA1_2_, coordinate0_.LAT as LAT2_, coordinate0_.LNG as LNG2_ from COORDINATES coordinate0_
    coord.findAll =  51ms , coordinates.size: 4704
    Hibernate: select coordconne0_.COORDCONNECTIONID as COORDCON1_3_, coordconne0_.DISTANCE as DISTANCE3_, coordconne0_.FROMCOORDID as FROMCOOR3_3_, coordconne0_.TOCOORDID as TOCOORDID3_ from COORDCONNECTIONS coordconne0_
    coordinateConnectionDao.findAll  = 238ms ; coordConnectioninates.size:48132

Hibernate Annotations

    @Entity
    @Table(name = "STOPS")
    public class Stop implements Serializable {

        @Id
        @GeneratedValue(strategy = GenerationType.AUTO)
        @Column(name = "STOPID")
        private int stopID;

        @Column(name = "ROUTEID", nullable = false)
        private int routeID;

        @ManyToOne(fetch = FetchType.LAZY)
        @JoinColumn(name = "COORDINATEID", nullable = false)
        private Coordinate coordinate;
        }

    @Table(name = "COORDINATES")
    public class Coordinate {

        @Id
        @GeneratedValue
        @Column(name = "COORDINATEID")
        private int CoordinateID;

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

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

        }

    @Entity
    @Table(name = "COORDCONNECTIONS")
    public class CoordConnection {

        @Id
        @GeneratedValue
        @Column(name = "COORDCONNECTIONID")
        private int CoordinateID;

        @ManyToOne(fetch = FetchType.LAZY)
        @JoinColumn(name = "FROMCOORDID", nullable = false)
        private Coordinate fromCoordID;

        @ManyToOne(fetch = FetchType.LAZY)
        @JoinColumn(name = "TOCOORDID", nullable = false)
        private Coordinate toCoordID;

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

© Stack Overflow or respective owner

Related posts about hibernate

Related posts about database-design