I'm trying to learn hibernate and I'm stuck mapping this two object:
Class CD:
Code:
public class CD {
private int idCD;
private String title;
private List tracks = new ArrayList();
public CD() {
}
//getter and setter methods
and class Track:
Code:
public class Track {
private int idTrack;
private String title;
public Track() {
}
//getter and setter methods
The sql of the table for the CD objects:
Code:
CREATE TABLE tb_cd
(
title character varying(255),
id_cd serial NOT NULL,
CONSTRAINT pk_id_cd PRIMARY KEY (id_cd)
)
...and for the Track objects:
Code:
CREATE TABLE tb_track
(
id_track serial NOT NULL,
title character varying(255),
cd_id integer NOT NULL,
"order" integer NOT NULL,
"position" integer,
CONSTRAINT pk_id_track PRIMARY KEY (id_track),
CONSTRAINT fk_id_cd FOREIGN KEY (cd_id)
REFERENCES tb_cd (id_cd) MATCH SIMPLE
ON UPDATE CASCADE ON DELETE CASCADE,
CONSTRAINT fkfadf583a1a2704c7 FOREIGN KEY (cd_id)
REFERENCES tb_cd (id_cd) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
)
the relation between CD and Track are 1-->N and unidirectional. What are the correct mapping for this two class?
(The column "position" is for the <list-index> )