-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: JPA entity question
PostPosted: Mon Dec 13, 2010 7:11 pm 
Newbie

Joined: Mon Dec 13, 2010 6:43 pm
Posts: 1
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.java
Code:
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.java
Code:
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;
   }
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.