I'm new to JPA and now study on how to join the two tables by manytoone relation. The entity I get are from Database. I have two tables , named Department and Employee. Many employee is belongs to one Department.
Department
#Entity
#Table(name = "DEPARTMENT")
#XmlRootElement
#NamedQueries({
#NamedQuery(name = "Department.findAll", query = "SELECT d FROM Department d")
, #NamedQuery(name = "Department.findById", query = "SELECT d FROM Department d WHERE d.id = :id")
, #NamedQuery(name = "Department.findByName", query = "SELECT d FROM Department d WHERE d.name = :name")})
public class Department implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#Basic(optional = false)
#Column(name = "ID")
private Integer id;
#Column(name = "NAME")
private String name;
#OneToMany(mappedBy = "departmentId")
private Collection<Employee> employeeCollection;
public Department() {
}
public Department(Integer id) {
this.id = id;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
#XmlTransient
public Collection<Employee> getEmployeeCollection() {
return employeeCollection;
}
public void setEmployeeCollection(Collection<Employee> employeeCollection) {
this.employeeCollection = employeeCollection;
}
#Override
public int hashCode() {
int hash = 0;
hash += (id != null ? id.hashCode() : 0);
return hash;
}
#Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof Department)) {
return false;
}
Department other = (Department) object;
if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
return false;
}
return true;
}
#Override
public String toString() {
return "entity.Department[ id=" + id + " ]";
}
}
Employee
#Entity
#Table(name = "EMPLOYEE")
#XmlRootElement
#NamedQueries({
#NamedQuery(name = "Employee.findAll", query = "SELECT e FROM Employee e")
, #NamedQuery(name = "Employee.findByEid", query = "SELECT e FROM Employee e WHERE e.eid = :eid")
, #NamedQuery(name = "Employee.findByDeg", query = "SELECT e FROM Employee e WHERE e.deg = :deg")
, #NamedQuery(name = "Employee.findByEname", query = "SELECT e FROM Employee e WHERE e.ename = :ename")
, #NamedQuery(name = "Employee.findBySalary", query = "SELECT e FROM Employee e WHERE e.salary = :salary")})
public class Employee implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#Basic(optional = false)
#Column(name = "EID")
private Integer eid;
#Column(name = "DEG")
private String deg;
#Column(name = "ENAME")
private String ename;
// #Max(value=?) #Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation
#Column(name = "SALARY")
private Double salary;
#JoinColumn(name = "DEPARTMENT", referencedColumnName = "ID")
#ManyToOne
private Department department;
public Employee() {
}
public Employee(Integer eid) {
this.eid = eid;
}
public Integer getEid() {
return eid;
}
public void setEid(Integer eid) {
this.eid = eid;
}
public String getDeg() {
return deg;
}
public void setDeg(String deg) {
this.deg = deg;
}
public String getEname() {
return ename;
}
public void setEname(String ename) {
this.ename = ename;
}
public Double getSalary() {
return salary;
}
public void setSalary(Double salary) {
this.salary = salary;
}
public Department getDepartment() {
return department;
}
public void setDepartment(Department department) {
this.department = department;
}
#Override
public int hashCode() {
int hash = 0;
hash += (eid != null ? eid.hashCode() : 0);
return hash;
}
#Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof Employee)) {
return false;
}
Employee other = (Employee) object;
if ((this.eid == null && other.eid != null) || (this.eid != null && !this.eid.equals(other.eid))) {
return false;
}
return true;
}
#Override
public String toString() {
return "entity.Employee[ eid=" + eid + " ]";
}
}
ManyToOne
public class ManyToOne {
public static void main(String[] args) {
EntityManagerFactory emfactory = Persistence.
createEntityManagerFactory("JoinTablePU");
EntityManager entitymanager = emfactory.
createEntityManager();
entitymanager.getTransaction().begin();
//Create Department Entity
Department department = new Department();
department.setName("Development");
//Store Department
entitymanager.persist(department);
//Create Employee1 Entity
Employee employee1 = new Employee();
employee1.setEname("Satish");
employee1.setSalary(45000.0);
employee1.setDeg("Technical Writer");
employee1.setDepartment(department);
//Create Employee2 Entity
Employee employee2 = new Employee();
employee2.setEname("Krishna");
employee2.setSalary(45000.0);
employee2.setDeg("Technical Writer");
employee2.setDepartment(department);
//Create Employee3 Entity
Employee employee3 = new Employee();
employee3.setEname("Masthanvali");
employee3.setSalary(50000.0);
employee3.setDeg("Technical Writer");
employee3.setDepartment(department);
//Store Employees
entitymanager.persist(employee1);
entitymanager.persist(employee2);
entitymanager.persist(employee3);
entitymanager.getTransaction().commit();
entitymanager.close();
emfactory.close();
}
}
Error
Exception Description: The attribute [employeeCollection] in entity class [class entity.Department] has a mappedBy value of [departmentId] which does not exist in its owning entity class [class entity.Employee]. If the owning entity class is a #MappedSuperclass, this is invalid, and your attribute should reference the correct subclass.
at org.eclipse.persistence.exceptions.PersistenceUnitLoadingException.exceptionSearchingForPersistenceResources(PersistenceUnitLoadingException.java:127)
at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactoryImpl(PersistenceProvider.java:107)
at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactory(PersistenceProvider.java:177)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:79)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
at jointable.ManyToOne.main(ManyToOne.java:22)
It should be
#OneToMany(mappedBy = "department")
private Collection<Employee> employeeCollection;
The mappedBy = "department" attribute specifies that
the private Department department; field in Employee owns the
relationship (i.e. contains the foreign key for the query to
find all employees for a department.
Here you can find similar example
mappedBy property is used to denote the inverse field in a bidirectional relationship. It identifies that employeeCollection will get automatically populated when the department entity is retrieved from the DB.
In your case , it should be mappedBy = department
Check this link to find the exact representation of your employee-dept model forming a bidirectional relationship and its elaborate description.
Related
I'm using JavaEE to build a very simple Java full stack app, so I'm using JSF with Prime Faces 6.2 to render an xthml in the frontend and EJB, JPA with Hibernate and postgresql in the backend, however, When I set rowKey="#{person.id}" from a dataTable component from Prime Faces. Next exception is thrown.
"00:13:36,307 ERROR [io.undertow.request] (default task-55) UT005023: Exception handling request to /javaee-app/faces/listPersons.xhtml: javax.servlet.ServletException ... Caused by:java.lang.NullPointerException"
listPersons.xhtml
Prime Faces DataTable Component(opening tag and its attributes)
<p:dataTable id="persons"
value="#{personBean.persons}"
var="person"
editable="true"
rowKey="#{person.id}"
selection="#{personBean.personSelected}"
selectionMode="single">
The exception thrown that appears when trying to render the page is this.
However, if I set rowKey="#{person.name}" or even rowKey="#{person.email}" in stead of rowKey="#{person.id}" the problem disappears and xthml page is rendered correctly.
<p:dataTable id="persons"
value="#{personBean.persons}"
var="person"
editable="true"
rowKey="#{person.name}"
selection="#{personBean.personSelected}"
selectionMode="single">
with rowKey="#{person.name}" or rowKey="#{person.email}" xhtml page is rendered correctly"
Postgresql Database person
MODEL/ENTITY
#Entity
#Table(name = "person")
#NamedQueries({
#NamedQuery(name = "Person.findAll", query = "SELECT p FROM Person p"),
#NamedQuery(name = "Person.findById", query = "SELECT p FROM Person p
WHERE p.id = :id")
, #NamedQuery(name = "Person.findByName", query = "SELECT p FROM
Person p WHERE p.name = :person_name")
, #NamedQuery(name = "Person.findByLastname", query = "SELECT p FROM
Person p WHERE p.lastname = :lastname")
, #NamedQuery(name = "Person.findByEmail", query = "SELECT p
FROM Person p WHERE p.email = :email")
, #NamedQuery(name = "Person.findByPhone", query = "SELECT p
FROM Person p WHERE p.phone = :phone")})
public class Person implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
#Basic(optional = false)
#NotNull
#Size(min = 1, max = 60)
#Column(name = "person_name")
private String name;
#Basic(optional = false)
#NotNull
#Size(min = 1, max = 60)
private String lastname;
#Basic(optional = false)
#NotNull
#Size(min = 1, max = 60)
private String email;
#Size(max = 60)
private String phone;
#OneToMany(mappedBy = "person", fetch = FetchType.EAGER)
private List<Users> users;
public Person() { }
public Person(Integer id) {
this.id = id;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getLastname() {
return lastname;
}
public void setLastname(String lastname) {
this.lastname = lastname;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public List<Users> getUsers() {
return users;
}
public void setUsers(List<Users> users) {
this.users = users;
}
#Override
public int hashCode() {
int hash = 0;
hash += (id != null ? id.hashCode() : 0);
return hash;
}
#Override
public boolean equals(Object object) {
if (!(object instanceof Person)) {
return false;
}
Person other = (Person) object;
if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
return false;
}
return true;
}
#Override
public String toString() {
return "Person [id = " + id + ", name=" + name
+ ", lastName=" + lastname + " email=" + email + ", phone=" + phone + "]";
}
Any idea to solve this problem guys? Thanks in advance
I'm also adding the images of the errors generated in the application server, in my case Wildfly 8.2
picture1 Wildfly 8.2
picture2 Wildfly 8.2
The id is of type Integer:
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
Where as the getter returns int:
public int getId() {
return id;
}
Change getId to return Integer.
I am getting the following error when I am trying to execute the insertEmployeeDetails method :
org.hibernate.QueryException: could not resolve property: query of: abc.def.mypackage.orm.Employee [INSERT INTO Employee (name,definition,( SELECT value_emp_id FROM COMPANY_DATA WHERE testing_id = 1234 AND company_employee_id = 3345))]
Looking at similar online other posts on Stack overflow, say for example, the following one says:
org.hibernate.QueryException: could not resolve property:
that "we don't make reference to database column names, we reference property names instead".So I have clearly mentioned name and definition as defined in the entity class Employee below. The subquery where I am trying to get the value of column COLUMN_ID uses the sub query so I am not sure if I would be able to use something in agreement with HQL rules?, I mean that SELECT subquery which is supposed to pull value_emp_id from COMPANY_DATA table is a SQL query that I have mentioned. Does that needs to be modified? Could this be the reason for this type of error? Please advise.
My Entity Class Employee.java is as follows:
package abc.def.mypackage.orm
#Entity
#Table(name = "EMPLOYEE")
public class Employee {
public int getEmployeeId() {
return employeeId;
}
public void setEmployeeId(int employeeId) {
this.employeeId = employeeId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getIsCorrect() {
return isCorrect;
}
public void setIsCorrect(int isCorrect) {
this.isCorrect = isCorrect;
}
public int getIsWrong() {
return isWrong;
}
public void setIsWrong(int isWrong) {
this.isWrong = isWrong;
}
public int getCompanyId() {
return companyId;
}
public void setCompanyId(int companyId) {
this.companyId = companyId;
}
public Integer getTransactionId() {
return transactionId;
}
public void setTransactionId(Integer transactionId) {
this.transactionId = transactionId;
}
public String getDefinition() {
return definition;
}
public void setDefinition(String definition) {
this.definition = definition;
}
#Id
#Column(name = "EMPLOYEE_ID")
#GeneratedValue(strategy = GenerationType.AUTO, generator = "seqgen")
#SequenceGenerator(name = "seqgen", sequenceName = "EMPLOYEE_AUTOINC_SEQ")
private int employeeId;
#Column(name = "NAME")
private String name;
#Column(name = "DEFINITION")
private String definition;
#Column(name = "IS_CORRECT")
private int isCorrect;
#Column(name = "IS_WRONG")
private int isWrong;
#Column(name = "COMPANY_ID")
private int companyId;
#Column(name = "TRANSACTION_ID", nullable = true)
private Integer transactionId;
}
Here is how I am using the HQL in my method :
public boolean insertEmployeeDetails(Employee employee)
{
logger.debug("Starting EmployeeDaoImpl.insert() .....");
Session session = null;
Transaction tx = null;
boolean status = true;
try {
session = sessionFactory.openSession();
tx = session.beginTransaction();
String hqlInsert = "INSERT INTO Employee (name,definition,"
+ "( SELECT value_emp_id FROM COMPANY_DATA WHERE testing_id = 1234 AND"
+ " company_employee_id = 3345))";
int createdEntities = session.createQuery( hqlInsert )
.executeUpdate();
session.persist(employee);
tx.commit();
System.out.println("Checking for hqlInsert");
System.out.println(hqlInsert);
System.out.println("Checking for CreatedEntities");
System.out.println(createdEntities);
} catch(Exception ex) {
tx.rollback();
ex.printStackTrace();
status = false;
} finally {
session.close();
}
logger.debug("Completed EmployeeDaoImpl.insert() .....");
return status;
}
The problem here is that you are confusing createQuery() with createSQLQuery(), because createQuery() executes a HQL query and not an SQL query as you can see in the documentation:
createQuery
Create a new instance of Query for the given HQL query string.
In fact the hqlInsert query string you passed to the createQuery() method is an SQL insert query, which is unsopported by createQuery(), you need to use createSQLQuery() so you can execute it with Hibernate, and make sure to use database columns instead of Entity attributes on it as it's an SQL query.
I'm really stuck here and I'd love to get some help right about now.
Everytime I try to deploy, it keeps saying that it failed.
EDIT:
Okay so I've realized that the main issue seems to be:
Caused by: Exception [EclipseLink-7154] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.ValidationException
Exception Description: The attribute [productCollection] in entity class [class entity.Category] has a mappedBy value of [category] which does not exist in its owning entity class [class entity.Product]. If the owning entity class is a #MappedSuperclass, this is invalid, and your attribute should reference the correct subclass.
The entity classes are as follows:
Category.java
#Entity
#Table(name = "category")
#NamedQueries({
#NamedQuery(name = "Category.findAll", query = "SELECT c FROM Category c"),
#NamedQuery(name = "Category.findById", query = "SELECT c FROM Category c WHERE c.id = :id"),
#NamedQuery(name = "Category.findByName", query = "SELECT c FROM Category c WHERE c.name = :name")})
public class Category implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
#Basic(optional = false)
#Column(name = "id")
private Short id;
#Basic(optional = false)
#Column(name = "name")
private String name;
#OneToMany(cascade = CascadeType.ALL, mappedBy = "category")
private Collection<Product> productCollection;
public Category() {
}
public Category(Short id) {
this.id = id;
}
public Category(Short id, String name) {
this.id = id;
this.name = name;
}
public Short getId() {
return id;
}
public void setId(Short id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Collection<Product> getProductCollection() {
return productCollection;
}
public void setProductCollection(Collection<Product> productCollection) {
this.productCollection = productCollection;
}
#Override
public int hashCode() {
int hash = 0;
hash += (id != null ? id.hashCode() : 0);
return hash;
}
#Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof Category)) {
return false;
}
Category other = (Category) object;
if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
return false;
}
return true;
}
#Override
public String toString() {
return "entity.Category[id=" + id + "]";
}
}
Product.java
#Entity
#Table(name = "product")
#XmlRootElement
#NamedQueries({
#NamedQuery(name = "Product.findAll", query = "SELECT p FROM Product p"),
#NamedQuery(name = "Product.findById", query = "SELECT p FROM Product p WHERE p.id = :id"),
#NamedQuery(name = "Product.findByName", query = "SELECT p FROM Product p WHERE p.name = :name"),
#NamedQuery(name = "Product.findByPrice", query = "SELECT p FROM Product p WHERE p.price = :price"),
#NamedQuery(name = "Product.findByDescription", query = "SELECT p FROM Product p WHERE p.description = :description"),
#NamedQuery(name = "Product.findByLastUpdate", query = "SELECT p FROM Product p WHERE p.lastUpdate = :lastUpdate")})
public class Product implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
#Basic(optional = false)
#Column(name = "id")
private Integer id;
#Basic(optional = false)
#NotNull
#Size(min = 1, max = 45)
#Column(name = "name")
private String name;
#Basic(optional = false)
#NotNull
#Size(min = 1, max = 45)
#Column(name = "price")
private BigDecimal price;
#Size(max = 255)
#Column(name = "description")
private String description;
#Basic(optional = false)
#NotNull
#Column(name = "last_update")
#Temporal(TemporalType.TIMESTAMP)
private Date lastUpdate;
#JoinColumn(name = "category_id", referencedColumnName = "id")
#ManyToOne(optional = false)
private Category categoryId;
#OneToMany(cascade = CascadeType.ALL, mappedBy = "product")
private Collection<OrderedProduct> orderedProductCollection;
public Product() {
}
public Product(Integer id) {
this.id = id;
}
public Product(Integer id, String name, BigDecimal price, Date lastUpdate) {
this.id = id;
this.name = name;
this.price = price;
this.lastUpdate = lastUpdate;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public BigDecimal getPrice() {
return price;
}
public void setPrice(BigDecimal price) {
this.price = price;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Date getLastUpdate() {
return lastUpdate;
}
public void setLastUpdate(Date lastUpdate) {
this.lastUpdate = lastUpdate;
}
public Category getCategoryId() {
return categoryId;
}
public void setCategoryId(Category categoryId) {
this.categoryId = categoryId;
}
#XmlTransient
public Collection<OrderedProduct> getOrderedProductCollection() {
return orderedProductCollection;
}
public void setOrderedProductCollection(Collection<OrderedProduct> orderedProductCollection) {
this.orderedProductCollection = orderedProductCollection;
}
#Override
public int hashCode() {
int hash = 0;
hash += (id != null ? id.hashCode() : 0);
return hash;
}
#Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof Product)) {
return false;
}
Product other = (Product) object;
if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
return false;
}
return true;
}
#Override
public String toString() {
return "entity.Product[ id=" + id + " ]";
}
}
Please help me as soon as possible.
Thank you.
I figured out the solution.
All i had to do was change:
#OneToMany(cascade = CascadeType.ALL, mappedBy = "category")
to
#OneToMany(cascade = CascadeType.ALL, mappedBy = "categoryId")
Because in my Product.java, the category is mentioned as:
public Category getCategoryId() {
return categoryId;
}
I have a service rest from database generated in netbeans. This creates entity classes for each table .
#Entity
#Table(name = "users")
#XmlRootElement
#NamedQueries({
#NamedQuery(name = "Users.findAll",
query = "SELECT u FROM Users u"),
#NamedQuery(name = "Users.findById",
query = "SELECT u FROM Users u WHERE u.id = :id"),
#NamedQuery(name = "Users.findByName",
query = "SELECT u FROM Users u WHERE u.name = :name"),
#NamedQuery(name = "Users.findByTelephone",
query = "SELECT u FROM Users u WHERE u.telephone = :telephone"),
#NamedQuery(name = "Users.findByYear",
query = "SELECT u FROM Users u WHERE u.year = :year")})
public class Users implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#Basic(optional = false)
#NotNull
#Column(name = "id")
private Integer id;
#Size(max = 25)
#Column(name = "name")
private String name;
#Column(name = "telephone")
private Integer telephone;
#Column(name = "year")
private Integer year;
public Users() {
}
public Users(Integer id) {
this.id = id;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getTelephone() {
return telephone;
}
public void setTelephone(Integer telephone) {
this.telephone = telephone;
}
public Integer getYear() {
return year;
}
public void setYear(Integer year) {
this.year = year;
}
#Override
public int hashCode() {
int hash = 0;
hash += (id != null ? id.hashCode() : 0);
return hash;
}
#Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof Users)) {
return false;
}
Users other = (Users) object;
if ((this.id == null && other.id != null)
|| (this.id != null && !this.id.equals(other.id))) {
return false;
}
return true;
}
#Override
public String toString() {
return "glee.Users[ id=" + id + " ]";
}
How I can query the db with this class from another? ?
For example do a select : select name from bb.users;
and save it in an array eg
Thanks
#NamedQuery(name,query) annotation is used to hard code the Queries
into the Persistence class. You can retrieve the query using the
name attribute specified.
When using hibernate session, you can use getNamedQuery to
get the query.
When used with EntityManager you can use
createNamedQuery.
Both of this will retrieve the query and and you can execute the query with basic query operations.
List Users =
session.getNamedQuery("Users.findById").setParameter("id",
"1").list();
I have an ObtainedSkill table as well as a Resource table. There is no column in the Resource table for ObtainedSkill. There are only get/set methods. The ObtainedSkill table has a forien key to a Resource Serial Number.
When I call setObtainedSkill() and then update the Resource with the new ObtainedSkills list, it doesn't update. The Resource's ObtainedSkills are still null.
My question is, how do I go about adding ObtainedSkills to my Resource? Do I have to have another column in the Resource table for ObtainedSkills?
Here's my test class:
public static void main(String[] args) throws Exception {
EntityManagerFactory emf = Persistence.createEntityManagerFactory("XRM_JPA");
ResourcezManager rm = new ResourcezManager(emf);
Resourcez resource = rm.getNewResourcez();
resource = rm.findResourcezBySerialNumber("2G9933");
for (int i = 0; i < resource.getObtainedSkills().size(); i++) {
if (resource.getObtainedSkills().get(i) != null) {
System.out.println(resource.getObtainedSkills().get(i).toString());
}
}
emf.close();
}
I get a NullPointerException when it tries to execute the System.out.
Here are the relevant entities
Skill Entity
package xrm.model;
import java.io.Serializable;
import javax.persistence.*;
import java.util.List;
/**
* The persistent class for the SKILL database table.
*
*/
#Entity
#NamedQueries({#NamedQuery(name = "getSkillBySkillName", query = "SELECT s FROM Skill s WHERE s.skillName = :skillName"),#NamedQuery(name = "getSkillBySkillDescription", query = "SELECT s FROM Skill s WHERE s.skillDescription = :skillDescription"),
#NamedQuery(name = "getSkillBySkillId", query = "SELECT s FROM Skill s WHERE s.skillId = :skillId"),
#NamedQuery(name = "getSkill", query = "SELECT s FROM Skill s")})
public class Skill implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy=GenerationType.IDENTITY)
#Column(name="SKILL_ID")
private int skillId;
#Column(name="SKILL_DESCRIPTION")
private String skillDescription;
#Column(name="SKILL_NAME")
private String skillName;
//bi-directional many-to-one association to ObtainedSkill
#OneToMany(mappedBy="skill")
private List<ObtainedSkill> obtainedSkills;
public Skill() {
}
public int getSkillId() {
return this.skillId;
}
public void setSkillId(int skillId) {
this.skillId = skillId;
}
public String getSkillDescription() {
return this.skillDescription;
}
public void setSkillDescription(String skillDescription) {
this.skillDescription = skillDescription;
}
public String getSkillName() {
return this.skillName;
}
public void setSkillName(String skillName) {
this.skillName = skillName;
}
public List<ObtainedSkill> getObtainedSkills() {
return this.obtainedSkills;
}
public void setObtainedSkills(List<ObtainedSkill> obtainedSkills) {
this.obtainedSkills = obtainedSkills;
}
}
Obtained Skill entity
package xrm.model;
import java.io.Serializable;
import javax.persistence.*;
/**
* The persistent class for the OBTAINED_SKILL database table.
*
*/
#Entity
#Table(name="OBTAINED_SKILL")
#NamedQueries({#NamedQuery(name = "getObtainedSkillBySkill", query = "SELECT o FROM ObtainedSkill o WHERE o.skill.skillId = :skill_skillId"),
#NamedQuery(name = "getObtainedSkillByResourcez", query = "SELECT o FROM ObtainedSkill o WHERE o.resourcez.serialNumber = :resourcez_serialNumber"),
#NamedQuery(name = "getObtainedSkillBySkillLevel", query = "SELECT o FROM ObtainedSkill o WHERE o.skillLevel = :skillLevel"),
#NamedQuery(name = "getObtainedSkillByObtainedSkillId", query = "SELECT o FROM ObtainedSkill o WHERE o.obtainedSkillId = :obtainedSkillId"),
#NamedQuery(name = "getObtainedSkill", query = "SELECT o FROM ObtainedSkill o")})
public class ObtainedSkill implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy=GenerationType.IDENTITY)
#Column(name="OBTAINED_SKILL_ID")
private int obtainedSkillId;
#Column(name="SKILL_LEVEL")
private int skillLevel;
//bi-directional many-to-one association to Resourcez
#ManyToOne(cascade=CascadeType.ALL)
#JoinColumn(name="SERIAL_NUMBER")
private Resourcez resourcez;
//bi-directional many-to-one association to Skill
#ManyToOne (cascade=CascadeType.DETACH)
#JoinColumn(name="SKILL_ID")
private Skill skill;
public ObtainedSkill() {
}
public int getObtainedSkillId() {
return this.obtainedSkillId;
}
public void setObtainedSkillId(int obtainedSkillId) {
this.obtainedSkillId = obtainedSkillId;
}
public int getSkillLevel() {
return this.skillLevel;
}
public void setSkillLevel(int skillLevel) {
this.skillLevel = skillLevel;
}
public Resourcez getResourcez() {
return this.resourcez;
}
public void setResourcez(Resourcez resourcez) {
this.resourcez = resourcez;
}
public Skill getSkill() {
return this.skill;
}
public void setSkill(Skill skill) {
this.skill = skill;
}
}
Resource Entity
package xrm.model;
import java.io.Serializable;
import javax.persistence.*;
import java.util.Date;
import java.util.List;
/**
* The persistent class for the RESOURCEZ database table.
*
*/
#Entity
#NamedQueries({#NamedQuery(name = "getResourcezByUserInformation", query = "SELECT r FROM Resourcez r WHERE r.userInformation.ibmEmailAddress = :userInformation_ibmEmailAddress"),#NamedQuery(name = "getResourcezBySource", query = "SELECT r FROM Resourcez r WHERE r.source.sourceId = :source_sourceId"),
#NamedQuery(name = "getResourcezByRole", query = "SELECT r FROM Resourcez r WHERE r.role.roleId = :role_roleId"),
#NamedQuery(name = "getResourcezByLocation", query = "SELECT r FROM Resourcez r WHERE r.location.locationId = :location_locationId"),
#NamedQuery(name = "getResourcezByMiddleInitial", query = "SELECT r FROM Resourcez r WHERE r.middleInitial = :middleInitial"),
#NamedQuery(name = "getResourcezByLastName", query = "SELECT r FROM Resourcez r WHERE r.lastName = :lastName"),
#NamedQuery(name = "getResourcezByHireDate", query = "SELECT r FROM Resourcez r WHERE r.hireDate = :hireDate"),
#NamedQuery(name = "getResourcezByFirstName", query = "SELECT r FROM Resourcez r WHERE r.firstName = :firstName"),
#NamedQuery(name = "getResourcezByBirthday", query = "SELECT r FROM Resourcez r WHERE r.birthday = :birthday"),
#NamedQuery(name = "getResourcezBySerialNumber", query = "SELECT r FROM Resourcez r WHERE r.serialNumber = :serialNumber"),
#NamedQuery(name = "getResourcez", query = "SELECT r FROM Resourcez r")})
public class Resourcez implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#Column(name="SERIAL_NUMBER")
private String serialNumber;
#Temporal( TemporalType.DATE)
private Date birthday;
#Column(name="FIRST_NAME")
private String firstName;
#Temporal( TemporalType.DATE)
#Column(name="HIRE_DATE")
private Date hireDate;
#Column(name="LAST_NAME")
private String lastName;
#Column(name="MIDDLE_INITIAL")
private String middleInitial;
//bi-directional many-to-one association to Assignment
#OneToMany(mappedBy="resourcez", cascade=CascadeType.DETACH)
private List<Assignment> assignments;
//bi-directional many-to-one association to ObtainedCertification
#OneToMany(mappedBy="resourcez", cascade=CascadeType.ALL)
private List<ObtainedCertification> obtainedCertifications;
//bi-directional many-to-one association to ObtainedSkill
#OneToMany(mappedBy="resourcez", cascade=CascadeType.ALL)
private List<ObtainedSkill> obtainedSkills;
//bi-directional many-to-one association to PhoneNumber
#OneToMany(mappedBy="resourcez", cascade=CascadeType.ALL)
private List<PhoneNumber> phoneNumbers;
//bi-directional many-to-one association to PrivilegeRequest
#OneToMany(mappedBy="resourcez", cascade=CascadeType.ALL)
private List<PrivilegeRequest> privilegeRequests;
//bi-directional many-to-one association to Location
#ManyToOne
#JoinColumn(name="LOCATION_ID")
private Location location;
//bi-directional many-to-one association to Role
#ManyToOne
#JoinColumn(name="ROLE_ID")
private Role role;
//bi-directional many-to-one association to Source
#ManyToOne
#JoinColumn(name="SOURCE_ID")
private Source source;
//bi-directional many-to-one association to UserInformation
#ManyToOne
#JoinColumn(name="IBM_EMAIL_ADDRESS")
private UserInformation userInformation;
public Resourcez() {
}
public String getSerialNumber() {
return this.serialNumber;
}
public void setSerialNumber(String serialNumber) {
this.serialNumber = serialNumber;
}
public Date getBirthday() {
return this.birthday;
}
public void setBirthday(Date birthday) {
this.birthday = birthday;
}
public String getFirstName() {
return this.firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public Date getHireDate() {
return this.hireDate;
}
public void setHireDate(Date hireDate) {
this.hireDate = hireDate;
}
public String getLastName() {
return this.lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getMiddleInitial() {
return this.middleInitial;
}
public void setMiddleInitial(String middleInitial) {
this.middleInitial = middleInitial;
}
public List<Assignment> getAssignments() {
return this.assignments;
}
public void setAssignments(List<Assignment> assignments) {
this.assignments = assignments;
}
public List<ObtainedCertification> getObtainedCertifications() {
return this.obtainedCertifications;
}
public void setObtainedCertifications(List<ObtainedCertification> obtainedCertifications) {
this.obtainedCertifications = obtainedCertifications;
}
public List<ObtainedSkill> getObtainedSkills() {
return this.obtainedSkills;
}
public void setObtainedSkills(List<ObtainedSkill> obtainedSkills) {
this.obtainedSkills = obtainedSkills;
}
public List<PhoneNumber> getPhoneNumbers() {
return this.phoneNumbers;
}
public void setPhoneNumbers(List<PhoneNumber> phoneNumbers) {
this.phoneNumbers = phoneNumbers;
}
public List<PrivilegeRequest> getPrivilegeRequests() {
return this.privilegeRequests;
}
public void setPrivilegeRequests(List<PrivilegeRequest> privilegeRequests) {
this.privilegeRequests = privilegeRequests;
}
public Location getLocation() {
return this.location;
}
public void setLocation(Location location) {
this.location = location;
}
public Role getRole() {
return this.role;
}
public void setRole(Role role) {
this.role = role;
}
public Source getSource() {
return this.source;
}
public void setSource(Source source) {
this.source = source;
}
public UserInformation getUserInformation() {
return this.userInformation;
}
public void setUserInformation(UserInformation userInformation) {
this.userInformation = userInformation;
}
}
Skill Table
Obtained Skill Table
Resource Table
The first field is the Serial Number which is a varchar
The other collapsed fields are also varchars Middle and Last name.