package com.philihp.weblabora.jpa;

import static javax.persistence.AccessType.FIELD;

import javax.persistence.Access;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Basic;
import javax.persistence.JoinColumn;
import static javax.persistence.FetchType.LAZY;

@Entity(name = "User")
@Table(name = "weblabora_user")
@Access(FIELD)
@NamedQuery(name = "findUserByFacebookId", query = "SELECT u FROM User u WHERE u.facebookId = :facebookId")
public class User extends BasicEntity {

	@Id
	@GeneratedValue
	@Column(name = "user_id")
	private int userId;

	@Basic(optional = false)
	@Column(name="facebook_id", nullable = false)
	private String facebookId;

	@Basic(optional = false)
	@Column(name = "name", nullable = false)
	private String name;
	
	@ManyToOne(fetch = LAZY, targetEntity = com.philihp.weblabora.jpa.Game.class)
	@JoinColumn(name = "active_game_id", referencedColumnName = "game_id")
	private Game activeGame;

	public int getUserId() {
		return userId;
	}

	public void setUserId(int userId) {
		this.userId = userId;
	}

	public String getFacebookId() {
		return facebookId;
	}

	public void setFacebookId(String facebookId) {
		this.facebookId = facebookId;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Game getActiveGame() {
		return activeGame;
	}
	public Integer getActiveGameId() {
		return activeGame==null?null:activeGame.getGameId();
	}

	public void setActiveGame(Game activeGame) {
		this.activeGame = activeGame;
	}

}

@@ -1797,14 +1797,95 @@
 me;%0D%0A%09%7D%0D
+%0A%09%0D%0A%09public String toString() %7B%0D%0A%09%09return getName()+%22(%22+getFacebookId()+%22)%22;%0D%0A%09%7D%0D
 %0A%0D%0A%7D%0D%0A

fix for issue #1