Skip to content

Instantly share code, notes, and snippets.

@gunnarmorling
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gunnarmorling/ed8838c314d447b76a2a to your computer and use it in GitHub Desktop.
Save gunnarmorling/ed8838c314d447b76a2a to your computer and use it in GitHub Desktop.
@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