For example, think of a Cart system where we have another table for Items.
A cart can have multiple items, so here we have one to many mapping. Transaction; import com.journaldev.hibernate.model.
Table; @Entity @Table(name="ITEMS") public class Items1 annotation to provide the column name for mapping. But before we do, a word on unidirectional and bidirectional relationships.In Hibernate, it’s possible to map all three relationships that are available in a standard database, these include: But what Hibernate also includes is the ability to make EACH of those relationships either unidirectional or bidirectional.So the summary is following: one team has many players, one player can play for one team.In this way we get obvious “ CREATE TABLE `teams` ( `id` int(6) NOT NULL AUTO_INCREMENT, `name` varchar(20) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=Inno DB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8; CREATE TABLE `players` ( `id` int(6) NOT NULL AUTO_INCREMENT, `lastname` varchar(20) NOT NULL, `team_id` int(6) NOT NULL, PRIMARY KEY (`id`), KEY `player's team` (`team_id`), CONSTRAINT `player's team` FOREIGN KEY (`team_id`) REFERENCES `teams` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=Inno DB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8; The result of the code execution is: Hibernate: insert into teams (name) values (?