i use hibernate deal with entity. the classes are
@Entity
@Table(name="bus_line")
@NamedQuery(name="BusLine.findAll", query="SELECT b FROM BusLine b")
public class BusLine implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(unique=true, nullable=false)
private Long id;
@Column(nullable=false)
private Long firstExpressTime;
@Column(nullable=false)
private Long lastExpressTime;
private Integer lineDirection;
@Column(nullable=false, length=10)
private String lineName;
@Column(nullable=false)
private Long originatingStationID;
@Column(nullable=false, length=10)
private String originatingStationName;
@Column(nullable=false)
private Long terminusID;
@Column(nullable=false, length=10)
private String terminusName;
@ManyToMany(mappedBy="busLines")
private List<BusStation> busStations = new ArrayList<BusStation>();
omit getter and setter method
}
@Entity
@Table(name="bus_station")
@NamedQuery(name="BusStation.findAll", query="SELECT b FROM BusStation b")
public class BusStation implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(unique=true, nullable=false)
private Long id;
@Column(nullable=false)
private Double stationLat;
@Column(nullable=false)
private Double stationLng;
@Column(nullable=false, length=20)
private String stationName;
@JoinTable(name="bus_line_to_station",joinColumns = @JoinColumn(name="stationID"),
inverseJoinColumns=@JoinColumn(name="lineID"))
private List<BusLine> busLines = new ArrayList<BusLine>();
omit setter and getter method
}
the table is
CREATE TABLE `bus_line` (
`id` bigint(20) NOT NULL AUTO_INCREMENT ,
`lineName` varchar(10) NOT NULL ,
`originatingStationName` varchar(10) NOT NULL ,
`originatingStationID` bigint(20) NOT NULL ,
`terminusID` bigint(20) NOT NULL ,
`terminusName` varchar(10) NOT NULL ,
`firstExpressTime` datetime NOT NULL ,
`lastExpressTime` datetime NOT NULL ,
`lineDirection` int(3) DEFAULT '1' ,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `bus_line_to_station` (
`id` bigint(20) NOT NULL AUTO_INCREMENT ,
`lineID` bigint(20) NOT NULL ,
`stationID` bigint(20) NOT NULL ,
`stationOrder` int(3) NOT NULL ,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `bus_station` (
`id` bigint(20) NOT NULL AUTO_INCREMENT ,
`stationName` varchar(20) NOT NULL ,
`stationLng` double NOT NULL ,
`stationLat` double NOT NULL ,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
but i worry that if i divide one table into many sub tables,such as
bus_station divided into bus_station1,bus_station2,bus_station3 and so on
bus_line_to_station divided into bus_line_to_station1,bus_line_to_station2,bus_line_to_station3 and so on in the same database.
the hibernate how to deal with the situation?
or i create other two databases,and create table bus_line_to_station1,bus_line_to_station2 ...in database1,and create table bus_station1,bus_station2 ... in database2.
the hibernate how to deal with the situation? thanks for your any help and suggestion in advance.