Hello,
I'm having some problems with a bidirectional one-to-many association where the associated entity is a joined subclass.
I have a base class called GamePrototype :
Code:
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
public class GamePrototype {
private long Id;
private Brand brand;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
@ManyToOne
@JoinColumn(name = "brand_id")
public Brand getBrand() {
return brand;
}
public void setBrand(Brand brand) {
this.brand = brand;
}
}
I have a Game class which extends GamePrototype :
Code:
@Entity
public class Game extends GamePrototype {
// Some other properties in this class...
}
And I have a Brand entity which has a collection of Game objects :
Code:
@Entity
public class Brand {
private long id;
private Collection<Game> games = new HashSet();
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
@OneToMany(mappedBy = "brand")
public Collection<Game> getGames() {
return games;
}
public void setGames(Collection<Game> games) {
this.games = games;
}
}
When I try to get the collection of games back from my brand object, I get an exception because the SQL is trying to access the brand_id field on the Game table (which doesn't exist) rather than the brand_id field on the GamePrototype table.
Any help would be much appreciated,
John Pang