java - map three tables with primary keys and foreign keys Composite in hibernate -
i have map these tables in hibernate , truth have tried in many ways , has not worked me, having if can this, not paste code have because suppose it's not right , changed lot.
table country
idcountry (pk)
countryname
table region
idregion (pk)
idcountry (pk, fk)
regionname
table provinces
idprovinces (pk)
idregion (pk,fk)
provincesname
hopefully can me, thank much
here tables mapping:
@entity @table(name = "country") public class country implements serializable { @id @generatedvalue(strategy = generationtype.auto) @column(name = "idcountry", unique = true, nullable = false) private int countryid; @column(name = "countryname", nullable = false) private string countryname; @onetomany(mappedby = "regionpk.country", cascade = cascadetype.all) private set<region> regions = new hashset<region>(0); // generate getters, setters, hashcode() , equals() } @entity @table(name = "region") public class region implements serializable { @embeddedid private regionpk regionpk; // regionpk contains composite pk @column(name = "regionname", nullable = false) private string regionname; @onetomany(mappedby = "provincepk.region", cascade = cascadetype.all) private set<province> provinces = new hashset<province>(0); // generate getters, setters, hashcode() , equals() } @embeddable public class regionpk implements serializable { @generatedvalue(strategy = generationtype.auto) @column(name = "idregion", unique = true, nullable = false) private int regionid; @manytoone @joincolumn(name = "idcountry", nullable = false) private country country; // generate getters, setters, hashcode() , equals() } @entity @table(name = "provinces") public class province implements serializable { @embeddedid private provincepk provincepk; // provincepk contains composite pk @column(name = "provincename", nullable = false) private string provincename; // generate getters, setters, hashcode() , equals() } @embeddable public class provincepk implements serializable { @generatedvalue(strategy = generationtype.auto) @column(name = "idprovinces", unique = true, nullable = false) private int provinceid; @manytoone @joincolumn(name = "idregion", nullable = false) private region region; // generate getters, setters, hashcode() , equals() }
Comments
Post a Comment