Hibernate version:3.2.5.ga
I'm building my Entity classes and I'm trying to configure cardinality for a OneToMany between 2 of, Player and GameStat. I've read a through the forum that stated that you should use a @Transient getGameStats() within Player Transient, but I looked at the CavaetEmptor and noticed that is doesn't use it. I followed the caveatemptor to the T and I still get
org.hibernate.MappingException: Could not determine type for: java.util.Set, for columns: [org.hibernate.mapping.Column(gameStats)] . If I make the method @Transient it is fine, but it doesn't create the foreign key mapping table in my *.ddl file. I know it is something simple.
My Error Stack
Code:
[hibernatetool] Executing Hibernate Tool with a JPA Configuration
[hibernatetool] 1. task: hbm2ddl (Generates database schema)
[hibernatetool] An exception occurred while running exporter #2:hbm2ddl (Generates database schema)
[hibernatetool] To get the full stack trace run ant with -verbose
[hibernatetool] org.hibernate.MappingException: Could not determine type for: java.util.Set, for columns: [org.hibernate.mapping.Column(gameStats)]
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] An Ant BuildException has occured: org.hibernate.MappingException: Could not determine type for: java.util.Set, for columns: [org.hibernate.mapping.Column(gameStats)]
This is my source code for Player.java
Code:
@Entity
@Table(name="PLAYERS")
@org.hibernate.annotations.BatchSize(size = 10)
public class Player implements Serializable{
private Integer id = new Integer(0);
@Length(min=1,max=20)
@NotNull
private String firstName;
@Length(min=1,max=20)
@NotNull
private String lastName;
@Length(min=1, max=20)
@NotNull
private String position;
@Length(min=1, max=2)
@NotNull
private int jerseyNo;
@Length(min=1, max=20)
@NotNull
private Blob photo;
@Length(min=1, max=20)
@NotNull
private String expLevel;
@OneToMany(mappedBy = "player")
private Set<GameStat> gameStats = new HashSet<GameStat>();
@Length(min=1, max=3)
private String height;
static Logger logger =Logger.getLogger(Player.class.getName());
/**
* Return the id for the user.
* @return
*/
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "PLAYER_ID", unique = true, nullable = true, insertable = true, updatable = true)
public Integer getId() { return id; }
/**
*
* @param id
*/
public void setId(Integer id){ this.id = id; }
/**
* @return the firstName
*/
@Column(name = "first_name", unique = false, nullable = true, insertable = true, updatable = true)
public String getFirstName() { return firstName; }
/**
* @param firstName the firstName to set
*/
public void setFirstName(String firstName) { this.firstName = firstName; }
/**
* @return the lastName
*/
@Column(name = "last_name", unique = false, nullable = false, insertable = true, updatable = true)
public String getLastName() { return lastName; }
/**
* @param lastName the lastName to set
*/
public void setLastName(String lastName) { this.lastName = lastName; }
/**
* @return the position
*/
@Column(name = "position", unique = false, nullable = false, insertable = true, updatable = true)
public String getPosition() { return position; }
/**
* @param position the position to set
*/
public void setPosition(String position) { this.position = position; }
/**
* @return the jerseyNo
*/
@Column(name = "jersey_no", unique = false, nullable = true, insertable = true, updatable = true)
public int getJerseyNo() { return jerseyNo; }
/**
* @param jerseyNo the jerseyNo to set
*/
public void setJerseyNo(int jerseyNo) { this.jerseyNo = jerseyNo; }
/**
* @return the photo
*/
@Column(name = "photo", unique = false, nullable = true, insertable = true, updatable = true)
public Blob getPhoto() { return photo; }
/**
* @param photo the photo to set
*/
public void setPhoto(Blob photo) { this.photo = photo; }
/**
* @return the expLevel
*/
@Column(name = "exp_level", unique = false, nullable = true, insertable = true, updatable = true)
public String getExpLevel() { return expLevel; }
/**
* @param expLevel the expLevel to set
*/
public void setExpLevel(String expLevel) {
this.expLevel = expLevel;
}
/**
* @return the height
*/
@Column(name = "height", unique = false, nullable = true, insertable = true, updatable = true)
public String getHeight() {return height;}
/**
* @param height the height to set
*/
public void setHeight(String height) { this.height = height; }
public Set<GameStat> getGameStats() { return gameStats; }
public void addGameStat(GameStat gameStat) {
if (gameStat == null) throw new IllegalArgumentException("Null GameStat!");
gameStat.setPlayer(this);
gameStats.add(gameStat);
}
/**
* Creates a Player Entity Class
*
* @param firstName First name of the player
* @param lastName Last name of the player
* @param height Height of the player
* @param position Posistion of the player
* @param expLevel Experience level of the player
* @param photo Picture of the player
*/
public Player( String firstName, String lastName, String height,
String position, String expLevel, Blob photo, Set<GameStat> gameStats){
this.firstName = firstName;
this.lastName = lastName;
this.height = height;
this.position = position;
this.expLevel = expLevel;
this.photo = photo;
this.gameStats = gameStats;
logger.debug("Creating a Player pojo");
}
/**
* Default COnstructor for a Player Entity Class
*/
public Player(){};
}
This is my source code for GameStat.java
Code:
@Entity
@Table(name="STATISTICS")
public class GameStat implements Serializable, Comparable{
static Logger logger = Logger.getLogger(GameStat.class.getName());
private Integer id = new Integer(0);
@Length(min=1, max=10)
@NotNull
private Integer points;
@Length(min=1, max=10)
@NotNull
private Integer rebounds;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "GAME_STAT_ID", unique = true, nullable = true, insertable = true, updatable = true)
public Integer getId() { return id; }
[color=blue]
@ManyToOne(fetch = FetchType.LAZY)
@JoinTable(
name = "PLAYER_GAMESTATS",
joinColumns = @JoinColumn(name = "GAME_STAT_ID"),
inverseJoinColumns = @JoinColumn(name = "PLAYER_ID")
)
@org.hibernate.annotations.ForeignKey(
name = "FK_PLAYER_ID",
inverseName = "FK_PLAYER_ID"
)
private Player player;
[/color]
public void setId(Integer id){ this.id =id; }
/**
* @return the points
*/
@Column(name = "points", unique = false, nullable = false, insertable = true, updatable = true)
public Integer getPoints() {return points;}
/**
* @param points the points to set
*/
public void setPoints(Integer points) { this.points = points; }
/**
* @return the rebounds
*/
@Column(name = "rebounds", unique = false, nullable = false, insertable = true, updatable = true)
public Integer getRebounds() { return rebounds; }
/**
* @param rebounds the rebounds to set
*/
public void setRebounds(Integer rebounds) { this.rebounds = rebounds; }
public Player getPlayer() { return player; }
public void setPlayer(Player player) { this.player = player; }
/**
* Constructor for Stats passing in the points, rebounds, and games played.
* @param points The points for a particular player
* @param rebounds The rebounds for a particular player
* @param gamesPlayed The games played for a particular player
*/
public GameStat( Integer points, Integer rebounds, Player player ){
this.points = points;
this.rebounds = rebounds;
this.player = player;
logger.debug("Creating a GameStat POJO points:" + points + ", rebounds=" + rebounds );
}
/**
*
*/
public GameStat(){logger.debug("Creating a default GameStat POJO.");}
public int compareTo(Object arg0) {
// TODO Auto-generated method stub
return 0;
}
}