I'm having some problems figuring out what's the right way to approach this. I'm an absolute newbie
Two entities:
[*]User class which contains all of the information about the user.
[*]Logentry class will contain information about the visited page. There's not always going to be a User associated with it. So the foreign key can be empty..
This what i have so far...
User.javaCode:
package db.entity;
import javax.persistence.*;
import java.sql.Date;
import java.util.Locale;
@Entity
public class User
{
private Long id;
private String username;
private String password;
private String email;
private Boolean gender;
private Date birthDate;
private Locale country;
private short userType;
public User(String username, String password, String email, short userType)
{
this.username = username;
this.password = password;
this.email = email;
this.userType = userType;
}
public User()
{
}
@Id
@GeneratedValue
public Long getId()
{
return id;
}
public void setId(Long id)
{
this.id = id;
}
@Column(nullable=false)
public String getUsername()
{
return username;
}
public void setUsername(String username)
{
this.username = username;
}
@Column(nullable=false)
public String getPassword()
{
return password;
}
public void setPassword(String password)
{
this.password = password;
}
@Column(nullable=false)
public String getEmail()
{
return email;
}
public void setEmail(String email)
{
this.email = email;
}
public Boolean getGender()
{
return gender;
}
public void setGender(Boolean gender)
{
this.gender = gender;
}
public Date getBirthDate()
{
return birthDate;
}
public void setBirthDate(Date birthDate)
{
this.birthDate = birthDate;
}
public short getUserType()
{
return userType;
}
public void setUserType(short userType)
{
this.userType = userType;
}
public Locale getCountry()
{
return country;
}
public void setCountry(Locale country)
{
this.country = country;
}
private LogEntry logEntries;
@ManyToOne
public LogEntry getLogEntries()
{
return logEntries;
}
public void setLogEntries(LogEntry logEntries)
{
this.logEntries = logEntries;
}
}
LogEntry.javaCode:
package db.entity;
import org.hibernate.annotations.ForeignKey;
import javax.persistence.*;
import java.sql.Timestamp;
@Entity
public class LogEntry
{
private long id;
private Timestamp moment;
private String ip;
private String page;
private User user;
public LogEntry()
{
}
public LogEntry(String ip, String page)
{
moment = new Timestamp(System.currentTimeMillis());
this.ip = ip;
this.page = page;
}
public LogEntry(String ip, String page, User user)
{
moment = new Timestamp(System.currentTimeMillis());
this.ip = ip;
this.page = page;
this.user = user;
}
@Id @GeneratedValue
public long getId()
{
return id;
}
public void setId(long id)
{
this.id = id;
}
public Timestamp getMoment()
{
return moment;
}
public void setMoment(Timestamp moment)
{
this.moment = moment;
}
public String getIp()
{
return ip;
}
public void setIp(String ip)
{
this.ip = ip;
}
public String getPage()
{
return page;
}
public void setPage(String page)
{
this.page = page;
}
@OneToMany
public User getUser()
{
return user;
}
public void setUser(User user)
{
this.user = user;
}
}