Mysql query in java - java

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();

Related

Why JPA entity throws exception when rowKey attribute is the primary key?

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.

ManyToOne Relation in JPA namedQuery

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.

Deployment Error caused by Entity (Ecommerce)

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;
}

How to make a query using columns of a JoinTable in Rest Webservice with netbeans

How I can to do this query:
#NamedQuery(name = "Scuser.findFriends", query = "SELECT s FROM Scuser s, friends f WHERE f.firstid = :iduser and s.iduser = f.secondid")
in this class:
#Entity
#Table(name = "scuser")
#XmlRootElement
#NamedQueries({
#NamedQuery(name = "Scuser.findAll", query = "SELECT s FROM Scuser s"),
#NamedQuery(name = "Scuser.findByIduser", query = "SELECT s FROM Scuser s WHERE s.iduser = :iduser"),
#NamedQuery(name = "Scuser.findByUpassword", query = "SELECT s FROM Scuser s WHERE s.upassword = :upassword"),
#NamedQuery(name = "Scuser.findByUname", query = "SELECT s FROM Scuser s WHERE s.uname = :uname"),
#NamedQuery(name = "Scuser.findByTpoints", query = "SELECT s FROM Scuser s WHERE s.tpoints = :tpoints"),
// #NamedQuery(name = "Scuser.findFriends", query = "SELECT s FROM Scuser s, friends f WHERE f.firstid = :iduser and s.iduser = f.secondid"),
#NamedQuery(name = "Scuser.findByUnameUpassword", query = "SELECT s FROM Scuser s WHERE s.uname = :uname and s.upassword = :upassword")})
public class Scuser implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#Basic(optional = false)
#NotNull
#Size(min = 1, max = 2147483647)
#Column(name = "iduser")
private String iduser;
#Size(max = 200)
#Column(name = "upassword")
private String upassword;
#Size(max = 200)
#Column(name = "uname")
private String uname;
// #Max(value=?) #Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation
#Column(name = "tpoints")
private Double tpoints;
#JoinTable(name = "friends", joinColumns = {
#JoinColumn(name = "firstid", referencedColumnName = "iduser")}, inverseJoinColumns = {
#JoinColumn(name = "secondid", referencedColumnName = "iduser")})
#ManyToMany
private Collection<Scuser> scuserCollection;
#ManyToMany(mappedBy = "scuserCollection")
private Collection<Scuser> scuserCollection1;
#ManyToMany(mappedBy = "scuserCollection")
private Collection<Beach> beachCollection;
public Scuser() {
}
public Scuser(String iduser) {
this.iduser = iduser;
}
public String getIduser() {
return iduser;
}
public void setIduser(String iduser) {
this.iduser = iduser;
}
public String getUpassword() {
return upassword;
}
public void setUpassword(String upassword) {
this.upassword = upassword;
}
public String getUname() {
return uname;
}
public void setUname(String uname) {
this.uname = uname;
}
public Double getTpoints() {
return tpoints;
}
public void setTpoints(Double tpoints) {
this.tpoints = tpoints;
}
#XmlTransient
public Collection<Scuser> getScuserCollection() {
return scuserCollection;
}
public void setScuserCollection(Collection<Scuser> scuserCollection) {
this.scuserCollection = scuserCollection;
}
#XmlTransient
public Collection<Scuser> getScuserCollection1() {
return scuserCollection1;
}
public void setScuserCollection1(Collection<Scuser> scuserCollection1) {
this.scuserCollection1 = scuserCollection1;
}
#XmlTransient
public Collection<Beach> getBeachCollection() {
return beachCollection;
}
public void setBeachCollection(Collection<Beach> beachCollection) {
this.beachCollection = beachCollection;
}
#Override
public int hashCode() {
int hash = 0;
hash += (iduser != null ? iduser.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 Scuser)) {
return false;
}
Scuser other = (Scuser) object;
if ((this.iduser == null && other.iduser != null) || (this.iduser != null && !this.iduser.equals(other.iduser))) {
return false;
}
return true;
}
#Override
public String toString() {
return "REST.Scuser[ iduser=" + iduser + " ]";
}
}
If I understand correctly, you have the ID of a user, and you want to get the friends of the user identified by this ID. The easiest way is to do
Scuser user = em.find(User.class, userId);
Collection<Scuser> friends = user.getScuserCollection();
If you want to do it using a JPQL query, you just need
select friend from Scuser user
inner join user.scuserCollection friend
where user.id = :userId
Note that your mapping isn't right: scuserCollection1 and beachCollection are both mapped by the same attribute. You should also choose better names for your associations (like friends for example, instead of scuserCollection).

How to get save() on my model in java?

Netbeans was kind enough to generate this class for me. But I'm wondering how I save data to the database?
I would think it would be like....
Content $content = new Content();
$content->setName();
$content->save();
But I don't see any save functionality or anything that hints that this content can be saved. I could write queries and such to do so, but with the annotations it created it seems like it has support already built in.
#Entity
#Table(name = "content")
#XmlRootElement
#NamedQueries({
#NamedQuery(name = "Content.findAll", query = "SELECT c FROM Content c"),
#NamedQuery(name = "Content.findById", query = "SELECT c FROM Content c WHERE c.id = :id"),
#NamedQuery(name = "Content.findByUserId", query = "SELECT c FROM Content c WHERE c.userId = :userId")})
public class Content implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
#Basic(optional = false)
#NotNull
#Column(name = "id")
private Integer id;
#Basic(optional = false)
#NotNull
#Column(name = "user_id")
private int userId;
#Basic(optional = false)
#NotNull
#Lob
#Size(min = 1, max = 65535)
#Column(name = "body")
private String body;
public Content() {
}
public Content(Integer id) {
this.id = id;
}
public Content(Integer id, int userId, String body) {
this.id = id;
this.userId = userId;
this.body = body;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public int getUserId() {
return userId;
}
public void setUserId(int userId) {
this.userId = userId;
}
public String getBody() {
return body;
}
public void setBody(String body) {
this.body = body;
}
#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 Content)) {
return false;
}
Content other = (Content) 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 "model.Content[ id=" + id + " ]";
}
}

Categories

Resources