Skip to content

Instantly share code, notes, and snippets.

@gunnarmorling

gunnarmorling/Court.java

Last active Aug 29, 2015
Embed
What would you like to do?
@Entity
public class Court {
@EmbeddedId
private CourtId id;
private String name;
@OneToMany(mappedBy = "playedOn")
private Set<Game> games = new HashSet<Game>();
...
}
@Entity
public class Game {
@EmbeddedId
private GameId id;
private String name;
@ManyToOne
private Court playedOn;
...
}
> db.Game.find()
{
"_id" : {
"category" : "primary",
"sequenceNo" : "456"
},
"name" : "Bruce - Dwain",
"playedOn_id" : {
"countryCode" : "DE",
"sequenceNo" : "123"
}
}
> db.Court.find()
{
"_id" : {
"countryCode" : "DE",
"sequenceNo" : "123"
},
"games" : [
{
"id.sequenceNo" : "456",
"id.category" : "primary"
}
],
"name" : "Center Court"
}
create table Court (
countryCode varchar(255) not null,
sequenceNo varchar(255) not null,
name varchar(255),
primary key (countryCode, sequenceNo)
) ENGINE=InnoDB
create table Game (
category varchar(255) not null,
sequenceNo varchar(255) not null,
name varchar(255),
playedOn_countryCode varchar(255),
playedOn_sequenceNo varchar(255),
primary key (category, sequenceNo)
) ENGINE=InnoDB
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment