Skip to content
Snippets Groups Projects
Commit 31636674 authored by Goik Martin's avatar Goik Martin
Browse files

Cleaning up Hibernate annotations

parent d8da4be4
No related branches found
No related tags found
No related merge requests found
Showing
with 27 additions and 67 deletions
......@@ -6,13 +6,13 @@ import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
/**
* {@link User} instances with component addresses
*
*/
@Entity
@Table(uniqueConstraints={@UniqueConstraint(columnNames={"uid"}),
......@@ -21,7 +21,7 @@ public class User {
private Long id;
@Id
@GeneratedValue
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long getId() {return id;}
protected void setId(Long id) {this.id = id;}
......
......@@ -4,15 +4,13 @@ import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
/**
* @author goik
*
* {@link User} instances with addresses
*
* {@link User} instances with addresses
*/
@Entity
@Table(uniqueConstraints={@UniqueConstraint(columnNames={"uid"}),
......@@ -21,7 +19,7 @@ public class User {
private Long id;
@Id
@GeneratedValue
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long getId() {return id;}
protected void setId(Long id) {this.id = id;}
......
......@@ -7,16 +7,14 @@ import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OrderColumn;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
/**
* @author goik
*
* {@link User} instances with addresses
*
* {@link User} instances with addresses
*/
@Entity
@Table(uniqueConstraints={@UniqueConstraint(columnNames={"uid"}),
......@@ -25,7 +23,7 @@ public class User {
private Long id;
@Id
@GeneratedValue
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long getId() {return id;}
protected void setId(Long id) {this.id = id;}
......
......@@ -3,6 +3,7 @@ package entity.company4;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToOne;
import javax.persistence.Table;
......@@ -18,7 +19,7 @@ import javax.persistence.UniqueConstraint;
public class Employee {
@Id
@GeneratedValue
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long getId() {return id;}
protected void setId(Long id) {this.id = id;}
private Long id;
......
......@@ -2,6 +2,7 @@ package entity.company4;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToOne;
import javax.persistence.Table;
......@@ -17,7 +18,7 @@ import javax.persistence.UniqueConstraint;
public class Laptop {
@Id
@GeneratedValue
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long getId() {return id;}
protected void setId(Long id) {this.id = id;}
private Long id;
......
......@@ -3,6 +3,7 @@ package entity.company5.model;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToOne;
import javax.persistence.Table;
......@@ -19,7 +20,7 @@ import javax.persistence.UniqueConstraint;
public class Employee {
@Id
@GeneratedValue
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long getId() {return id;}
protected void setId(Long id) {this.id = id;}
private Long id;
......
......@@ -2,6 +2,7 @@ package entity.company5.model;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToOne;
import javax.persistence.Table;
......@@ -18,7 +19,7 @@ import javax.persistence.UniqueConstraint;
public class Laptop {
@Id
@GeneratedValue
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long getId() {return id;}
protected void setId(Long id) {this.id = id;}
private Long id;
......
......@@ -14,14 +14,9 @@ import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import org.hibernate.annotations.Cascade;
/**
*
* {@link Employee} and {@link Project} related by
* {@link EmployeeProject} and {@link OneToMany} / {@link ManyToOne}
*
*/
@Entity
@Table(uniqueConstraints={@UniqueConstraint(columnNames={"staffNumber"})})
......@@ -43,8 +38,6 @@ public class Employee {
@OneToMany(orphanRemoval=true,fetch = FetchType.LAZY, mappedBy ="pk.employee",
cascade = {CascadeType.PERSIST, CascadeType.MERGE})
@Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE})
public Set<EmployeeProject> getEmployeeProjects() { return employeeProjects;}
public void setEmployeeProjects(Set<EmployeeProject> employeeProjects) { this.employeeProjects = employeeProjects;}
private Set<EmployeeProject> employeeProjects = new HashSet<EmployeeProject>();
......
......@@ -14,13 +14,9 @@ import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import org.hibernate.annotations.Cascade;
/**
*
* {@link Employee} and {@link Project} related by
* {@link EmployeeProject} and {@link OneToMany} / {@link ManyToOne}
*
*/
@Entity
@Table(uniqueConstraints={@UniqueConstraint(columnNames={"no"})})
......@@ -43,7 +39,6 @@ public class Project {
@OneToMany(orphanRemoval=true, fetch = FetchType.LAZY, mappedBy ="pk.project",
cascade = {CascadeType.PERSIST, CascadeType.MERGE})
@Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE})
public Set<EmployeeProject> getEmployeeProjects() { return employeeProjects;}
public void setEmployeeProjects(Set<EmployeeProject> employeeProjects) { this.employeeProjects = employeeProjects;}
private Set<EmployeeProject> employeeProjects = new HashSet<EmployeeProject>();
......
......@@ -4,10 +4,7 @@ import javax.persistence.Entity;
import javax.persistence.Id;
/**
* @author goik
*
* A simple class intended to be mapped to a database server
*
*/
@Entity
public class User {
......
......@@ -5,17 +5,13 @@ import javax.persistence.Id;
import javax.persistence.Transient;
/**
* @author goik
*
* A simple class intended to be mapped to a database server
*
*/
@Entity
public class User {
String uid;
/**
*
* @return The user's unique login name e.g. "goik"
*/
@Id
......
......@@ -5,10 +5,7 @@ import javax.persistence.Entity;
import javax.persistence.Id;
/**
* @author goik
*
* A simple class intended to be mapped to a database server
*
*/
@Entity
public class User {
......
......@@ -5,10 +5,7 @@ import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
/**
* @author goik
*
* Persisting a simple instance of {@link User}
*
*/
public class PersistSingleUser {
......
......@@ -7,10 +7,7 @@ import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
/**
* @author goik
*
* {@link User} instances with primary key and unique constraint
*
*/
@Entity
@Table(uniqueConstraints={@UniqueConstraint(columnNames={"uid"})})
......
......@@ -7,8 +7,6 @@ import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
/**
* @author goik
*
* {@link Project} instances with surrogate primary key and composed business key
*/
@Entity
......
......@@ -3,22 +3,18 @@ package hibintro.v7;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Index;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import org.hibernate.annotations.Index;
/**
* @author goik
*
* {@link User} instances with a non-unique index
* on {@link #getCname()} property for faster database retrieval.
*
* {@link User} instances providing a non-unique index
* to the {@link #getCname()} property for faster database retrieval.
*/
@Entity
@Table(uniqueConstraints={@UniqueConstraint(columnNames={"uid"})})
@org.hibernate.annotations.Table(appliesTo="User",
indexes = {@Index(name = "findCname", columnNames = {"cname"})})
@Table(uniqueConstraints={@UniqueConstraint(name="uidKey", columnNames={"uid"})},
indexes = {@Index(name = "byCname", columnList="cname", unique = false)}
)
public class User {
int uidNumber;
......
......@@ -6,8 +6,6 @@ import javax.persistence.Id;
import javax.persistence.Table;
/**
* @author goik
*
* {@link User} instances with
* renaming of database table and attributes.
*/
......
......@@ -23,6 +23,7 @@ public class PersistSingleUser {
u.setUidNumber(123);
u.setUid("goik");
u.setCname("Martin Goik");
u.setActive(true);
em.persist(u);
}
em.getTransaction().commit();
......
......@@ -4,12 +4,8 @@ import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import org.hibernate.annotations.Type;
/**
* @author goik
*
* {@link User} instances with re-mapped boolean property
* {@link User} instances with re-mapped boolean property
*/
@Entity
public class User {
......@@ -41,7 +37,7 @@ public class User {
public void setCname(String cname) {this.cname = cname;}
boolean active = false;
@Type(type="yes_no")
@Column(columnDefinition="CHAR(1)")
public boolean isActive() {return active;}
public void setActive(boolean active) {this.active = active;}
}
\ No newline at end of file
......@@ -5,13 +5,12 @@ import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
/**
* @author goik
*
* Root class for different payment methods
*/
@Entity
......@@ -20,7 +19,7 @@ public abstract class BillingDetails {
private Long id;
@Id
@GeneratedValue
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long getId() {return id;}
protected void setId(Long id) {this.id = id;}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment