I have small project with Spring Data, MVC and Web Flow. Also I have 2 entities that I use in Spring Web Flow, so they MUST implement Serializable interface, but I noticed that Hibernate doesn't create tables, that implement it, for proving it I just copied my entity, removed "implements Serializable" created new class and pasted the entity code there, the new table was created. How it works ? How to create table from entity that implement Serializable, is it possible at all ?
The entities code:
#Table(name = "users")
#Entity
public class User implements Serializable{
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
#Column(name = "idUsers")
private int id;
#Column(name = "login")
#Size(min = 3, max = 15,message = "Неправильний розмір")
#NotEmpty(message = "Не може бути пустим!")
private String login;
#Size(min = 6, max = 21,message = "Неправильний розмір")
#NotEmpty(message = "Не може бути пустим!")
#Column(name = "password")
private String password;
#NotNull(message = "Не може бути пустим!")
#Column(name = "email")
private String email;
#Column(name = "photo")
private String path;
#Column(name = "about")
private String about;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
#OneToMany(
fetch = FetchType.EAGER,
mappedBy = "user",
cascade = CascadeType.ALL,
orphanRemoval = true
)
private Set<CommentsToBook> commentsToBooks;
public Set<CommentsToBook> getCommentsToBooks() {
return commentsToBooks;
}
public void setCommentsToBooks(Set<CommentsToBook> commentsToBooks) {
this.commentsToBooks = commentsToBooks;
}
public Set<BookOrder> getOrders() {
return orders;
}
public void setOrders(Set<BookOrder> orders) {
this.orders = orders;
}
#OneToMany(
fetch = FetchType.EAGER,
mappedBy = "user",
cascade = CascadeType.ALL,
orphanRemoval = true
)
private Set<BookOrder> orders;
public String getPath() {
return path;
}
public String getAbout() {
return about;
}
public void setAbout(String about) {
this.about = about;
}
public void setPath(String path) {
this.path = path;
}
public String getLogin() {
return login;
}
public void setLogin(String login) {
this.login = login;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}
And the second one:
#Entity
#Table(name = "booook_order")
public class BookOrder implements Serializable {
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
#Column(name = "id")
private int id;
#Column(name = "bank_card")
private String bankCardId;
#Column(name = "user_name")
private String custName;
public User getUser() {
return user;
}
#ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
#JoinTable(name = "book", joinColumns = {
#JoinColumn(name = "id")
},inverseJoinColumns = {#JoinColumn(name = "idlibrary")})
private Set<Book> booksList;
#Column(name ="novaposhta-vid")
private String NPVid;
public String getNPVid() {
return NPVid;
}
public void setNPVid(String NPVid) {
this.NPVid = NPVid;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
#Column(name = "city")
private String city;
public void setUser(User user) {
this.user = user;
}
#ManyToOne(cascade = CascadeType.ALL,
fetch = FetchType.EAGER)
#JoinColumn(name = "idUsers")
private User user;
public String getCustName() {
return custName;
}
public void setCustName(String custName) {
this.custName = custName;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public Set<Book> getBooksList() {
return booksList;
}
public void setBooksList(Set<Book> booksList) {
this.booksList = booksList;
}
public String getBankCardId() {
return bankCardId;
}
public void setBankCardId(String bankCardId) {
this.bankCardId = bankCardId;
}
}
Related
I have two table i.e. User and Organization having join . i have to write a method which will give users on basis of organisation name containing the input string.
User.java
#Entity
#Table(name = "USERS")
#EntityListeners(UsersEntityListener.class)
#NamedQueries({
#NamedQuery(name = "User.findAll", query = "SELECT u FROM User u")})
public class User extends Domain implements Serializable {
private static final long serialVersionUID = 1L;
#Basic(optional = false)
#Column(name = "FIRST_NAME", nullable = false)
private String firstName;
#Basic(optional = false)
#Column(name = "LAST_NAME", nullable = false)
private String lastName;
#Column(name = "MIDDLE_NAME")
private String middleName;
#Basic(optional = false)
#Column(name = "GENDER", nullable = false)
private String gender;
#Basic(optional = false)
#Column(name = "MOBILE", nullable = false)
private String mobile;
#Basic(optional = false)
#Column(name = "EMAIL", nullable = false)
private String email;
#Basic(optional = false)
#Column(name = "USERNAME", nullable = false)
private String username;
#Basic(optional = false)
#Column(name = "PASSWORD", nullable = false)
private String password;
#Column(name = "URL")
private String url;
#PrePersist
public void encryptPassword(){
this.setPassword(new BCryptPasswordEncoder().encode(getPassword()));
}
#OneToMany(cascade = CascadeType.ALL, mappedBy = "user")
private List<UserRole> userRoles;
#OneToOne(cascade = CascadeType.ALL, mappedBy = "user")
private Organization organization;
public User() {
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getMiddleName() {
return middleName;
}
public void setMiddleName(String middleName) {
this.middleName = middleName;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public String getMobile() {
return mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public Organization getOrganization() {
return organization;
}
public void setOrganization(Organization organization) {
this.organization = organization;
}
public List<UserRole> getUserRoles() {
return userRoles;
}
public void setUserRoles(List<UserRole> userRoles) {
this.userRoles = userRoles;
}
}
Organization.java
#Entity
#Table(name = "ORGANIZATIONS", uniqueConstraints = {
#UniqueConstraint(columnNames = {"USER_ID"})})
#NamedQueries({
#NamedQuery(name = "Organization.findAll", query = "SELECT o FROM Organization o")})
public class Organization extends Domain implements Serializable {
private static final long serialVersionUID = 1L;
#Basic(optional = false)
#Column(name = "ORGANIZATION", nullable = false, length = 256)
private String organization;
#Column(name = "WEBSITE")
private String website;
public String getWebsite() {
return website;
}
public void setWebsite(String website) {
this.website = website;
}
#OneToMany(cascade = CascadeType.ALL, mappedBy = "organization")
private List<Location> locations;
#OneToMany(cascade = CascadeType.ALL, mappedBy = "senderOrganization")
private List<PurchaseOrder> sendPurchaseOrders;
#OneToMany(cascade = CascadeType.ALL, mappedBy = "receiverOrganization")
private List<PurchaseOrder> receivedPurchaseOrders;
#OneToMany(cascade = CascadeType.ALL, mappedBy = "organization")
private List<Purchaser> purchasing;
#OneToMany(cascade = CascadeType.ALL, mappedBy = "senderOrganization")
private List<Quotation> sendQuotations;
#OneToMany(cascade = CascadeType.ALL, mappedBy = "receiverOrganization")
private List<Quotation> receivedQuotations;
#JoinColumn(name = "USER_ID", referencedColumnName = "ID", nullable = false)
#OneToOne(optional = false)
private User user;
#OneToMany(cascade = CascadeType.ALL, mappedBy = "senderOrganization")
private List<Enquiry> sendEnquiries;
#OneToMany(cascade = CascadeType.ALL, mappedBy = "receiverOrganization")
private List<Enquiry> receivedEnquiries;
#OneToMany(cascade = CascadeType.ALL, mappedBy = "organization")
private List<Supplier> supplying;
#OneToMany(cascade = CascadeType.ALL, mappedBy = "senderOrganization")
private List<Invoice> sendInvoices;
#OneToMany(cascade = CascadeType.ALL, mappedBy = "receiverOrganization")
private List<Invoice> receivedInvoices;
public Organization() {
}
public String getOrganization() {
return organization;
}
public void setOrganization(String organization) {
this.organization = organization;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public List<Location> getLocations() {
return locations;
}
public void setLocations(List<Location> locations) {
this.locations = locations;
}
public List<PurchaseOrder> getSendPurchaseOrders() {
return sendPurchaseOrders;
}
public void setSendPurchaseOrders(List<PurchaseOrder> sendPurchaseOrders) {
this.sendPurchaseOrders = sendPurchaseOrders;
}
public List<PurchaseOrder> getReceivedPurchaseOrders() {
return receivedPurchaseOrders;
}
public void setReceivedPurchaseOrders(List<PurchaseOrder> receivedPurchaseOrders) {
this.receivedPurchaseOrders = receivedPurchaseOrders;
}
public List<Purchaser> getPurchasing() {
return purchasing;
}
public void setPurchasing(List<Purchaser> purchasing) {
this.purchasing = purchasing;
}
public List<Quotation> getSendQuotations() {
return sendQuotations;
}
public void setSendQuotations(List<Quotation> sendQuotations) {
this.sendQuotations = sendQuotations;
}
public List<Quotation> getReceivedQuotations() {
return receivedQuotations;
}
public void setReceivedQuotations(List<Quotation> receivedQuotations) {
this.receivedQuotations = receivedQuotations;
}
public List<Enquiry> getSendEnquiries() {
return sendEnquiries;
}
public void setSendEnquiries(List<Enquiry> sendEnquiries) {
this.sendEnquiries = sendEnquiries;
}
public List<Enquiry> getReceivedEnquiries() {
return receivedEnquiries;
}
public void setReceivedEnquiries(List<Enquiry> receivedEnquiries) {
this.receivedEnquiries = receivedEnquiries;
}
public List<Supplier> getSupplying() {
return supplying;
}
public void setSupplying(List<Supplier> supplying) {
this.supplying = supplying;
}
public List<Invoice> getSendInvoices() {
return sendInvoices;
}
public void setSendInvoices(List<Invoice> sendInvoices) {
this.sendInvoices = sendInvoices;
}
public List<Invoice> getReceivedInvoices() {
return receivedInvoices;
}
public void setReceivedInvoices(List<Invoice> receivedInvoices) {
this.receivedInvoices = receivedInvoices;
}
#OneToMany(mappedBy = "organization")
private List<Tax> taxes;
public List<Tax> getTaxes() {
return taxes;
}
public void setTaxes(List<Tax> taxes) {
this.taxes = taxes;
}
#OneToMany(mappedBy = "organization")
private List<Identity> identities;
public List<Identity> getIdentities() {
return identities;
}
public void setIdentities(List<Identity> identities) {
this.identities = identities;
}
}
IUserRepository
#Repository
#RepositoryRestResource
public interface IUserRepository extends JpaRepository<User, UUID> {
Page<User> findByOrganizationContaining(#Param("organization") String organization, Pageable pageable);
}
I have created this method as
Page<User> findByOrganizationContaining(#Param("organization") String organization, Pageable pageable);
But its not working out as i wanna search it on the basis of organization name which is column in organization table.
you don't have name attribute in Organization, You have organization I think that is what you are referrring to. you can do something like this
Page<User> findByOrganization_Organization(String organization, Pageable pageable);
underscore(_) refers to nested fields. But for this to work, you need to fetch organization eagerly.
#OneToOne(cascade = CascadeType.ALL, mappedBy = "user", fetch=FetchType.EAGER)
private Organization organization;
Hello you can use either query method or something like this can help you out
Page<User> findByOrganization_Organization(#Param(organization)String organization, Pageable pageable);
I'm using servlets with JPA+Hibernate). I don't understand the error, unless I've tried other solutions suggested in this forum. In fact, I don't want to store the UserAccount class as an entity; but I just want to declare it in the Utilisateur class (the Ids of the Utilisateur class are declared in the useraccount class).
My code :
#Entity
#Table(name = "utilisateur")
public class Utilisateur implements Serializable {
#Id
private UserAccount userAccount;
private Civility civility;
private Address address;
private Contact contact;
#Column(name = "sessions")
private List<String> sessions;
#Column(name = "particularRules")
private boolean particularRules;
public Utilisateur(UserAccount pAccount, Civility pCivility,
Address pAddress, Contact pContact, List<String>
pSessions,
boolean particularRules) {
this.userAccount = pAccount;
this.civility = pCivility;
this.address = pAddress;
this.contact = pContact;
this.sessions = pSessions;
this.particularRules = particularRules;
}
public Civility getCivility() {
return civility;
}
public void setCivility(Civility civility) {
this.civility = civility;
}
public Address getAddress() {
return address;
}
public void setAddress(Address address) {
this.address = address;
}
public Contact getContact() {
return contact;
}
public void setContact(Contact contact) {
this.contact = contact;
}
public boolean isParticularRules() {
return particularRules;
}
public void setParticularRules(boolean particularRules) {
this.particularRules = particularRules;
}
public UserAccount getUserAccount() {
return userAccount;
}
public void setUserAccount(UserAccount userAccount) {
this.userAccount = userAccount;
}
public List<String> getSessions() {
return sessions;
}
public void setSessions(List<String> sessions) {
this.sessions = sessions;
}
}
#Embeddable
#Inheritance(strategy = InheritanceType.SINGLE_TABLE)
public class UserAccount implements Serializable {
public UserAccount() {
}
public UserAccount(String pId, String pEmail, String pwsd, Date pCreaDate, Date pLastModDate) {
this.identifier = pId;
this.email = pEmail;
this.password = pwsd;
this.creationDate = pCreaDate;
this.lastModificationDate = pLastModDate;
}
#OneToOne(mappedBy = "userAccount", cascade = CascadeType.ALL,
fetch = FetchType.EAGER, orphanRemoval = true, targetEntity =
Utilisateur.class)
private Utilisateur user;
#Column(name = "creationDate")
#Temporal(javax.persistence.TemporalType.DATE)
private Date creationDate;
#Column(name = "lastModificationDate")
#Temporal(javax.persistence.TemporalType.DATE)
private Date lastModificationDate;
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
#Column(name = "identifier", nullable = false)
private String identifier;
#Column(name = "email")
private String email;
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
#Column(name = "password", nullable = false)
private String password;
public String getIdentifier() {
return identifier;
}
public void setIdentifier(String identifier) {
this.identifier = identifier;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public Date getCreationDate() {
return creationDate;
}
public void setCreationDate(Date creationDate) {
this.creationDate = creationDate;
}
public Date getLastModificationDate() {
return lastModificationDate;
}
public void setLastModificationDate(Date lastModificationDate) {
this.lastModificationDate = lastModificationDate;
}
public Utilisateur getUser() {
return user;
}
public void setUser(Utilisateur user) {
this.user = user;
}
}
You must use an Embedded Primary Key.
See the answer to this question here in Stackoverflow How to create and handle composite primary key in JPA.
Best regards!
It may occur when Embedded Primary Key contains #EmbeddedId. Sub-composite key should be annotated with #Embedded instead.
I am stuck up with mapping exception. I have many to many relationship between Employee and Role. Here is the code.
Role class
#Entity
#Table(name = "role", catalog = "app")
public class Role implements java.io.Serializable {
#GeneratedValue(strategy = IDENTITY)
#Column(name = "roleId", unique = true, nullable = false)
private Integer roleId;
#Column(name = "title", nullable = false, length = 50)
private String title;
#ManyToMany(fetch = FetchType.LAZY, mappedBy = "roles")
private Set<Employee> employees = new HashSet<Employee>(0);
public Role() {
}
public Role(String title) {
this.title = title;
}
public Role(String title, Set<Employee> employees) {
this.title = title;
this.employees = employees;
}
public Integer getRoleId() {
return this.roleId;
}
public void setRoleId(Integer roleId) {
this.roleId = roleId;
}
public String getTitle() {
return this.title;
}
public void setTitle(String title) {
this.title = title;
}
public Set<Employee> getEmployees() {
return this.employees;
}
public void setEmployees(Set<Employee> employees) {
this.employees = employees;
}
}
and Employee class
#Entity
#Table(name = "employee", catalog = "app", uniqueConstraints = #UniqueConstraint(columnNames = "email"))
public class Employee implements java.io.Serializable {
#Id
#GeneratedValue(strategy = IDENTITY)
#Column(name = "empId", unique = true, nullable = false)
private Integer empId;
#Column(name = "name", nullable = false, length = 100)
private String name;
#Column(name = "email", unique = true, nullable = false, length = 50)
private String email;
#Column(name = "phone", nullable = false, length = 11)
private String phone;
#Column(name = "ip", nullable = false, length = 20)
private String ip;
#Column(name = "password", nullable = false, length = 200)
private String password;
#ManyToMany(fetch = FetchType.LAZY)
#JoinTable(name = "employee_role", catalog = "app", joinColumns = {
#JoinColumn(name = "empId", nullable = false, updatable = false) }, inverseJoinColumns = {
#JoinColumn(name = "roleId", nullable = false, updatable = false) })
private Set<Role> roles = new HashSet<Role>(0);
public Employee() {
}
public Integer getEmpId() {
return this.empId;
}
public void setEmpId(Integer empId) {
this.empId = empId;
}
public City getCity() {
return this.city;
}
public void setCity(City city) {
this.city = city;
}
public Posts getPosts() {
return this.posts;
}
public void setPosts(Posts posts) {
this.posts = posts;
}
public Teams getTeams() {
return this.teams;
}
public void setTeams(Teams teams) {
this.teams = teams;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public String getEmail() {
return this.email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPhone() {
return this.phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getIp() {
return this.ip;
}
public void setIp(String ip) {
this.ip = ip;
}
public String getPassword() {
return this.password;
}
public void setPassword(String password) {
this.password = password;
}
public Set<Role> getRoles() {
return this.roles;
}
public void setRoles(Set<Role> roles) {
this.roles = roles;
}
}
Here is the exception. Please also explain the exception
org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: org.company.app.models.Role.employees in org.company.app.models.Employee.roles
what is wrong?
It looks you miss #Id anotation for Role class
#Id
#Column(name = "roleId", unique = true, nullable = false)
private Integer roleId;
I need to save the child table values without retrieve the values.
POJO Class:
public class User {
private String firstName;
#Id
#SequenceGenerator(name = "userID", sequenceName = "userID")
#GeneratedValue(strategy = GenerationType.AUTO, generator = "userID")
#Column(name = "id")
private Long id;
private String lastName;
private Integer passwordReset;
#Column(name = "useremail", nullable = false, unique = true)
#Email
#NotEmpty
private String email;
#Column(name = "password", nullable = false)
private String password;
#OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
#JoinColumn(name = "user_id", referencedColumnName = "id")
private List<WashingOrder> orderList;
#Column(unique = true)
#NotEmpty(message = "{username}")
private String username;
public String getFirstName() {
return firstName;
}
public Long getId() {
return id;
}
public String getLastName() {
return lastName;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPassword() {
return password;
}
public String getUsername() {
return username;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public void setId(Long id) {
this.id = id;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public void setPassword(String password) {
this.password = password;
}
public void setUsername(String username) {
this.username = username;
}
public Integer getPasswordReset() {
return passwordReset;
}
public void setPasswordReset(Integer passwordReset) {
this.passwordReset = passwordReset;
}
public List<WashingOrder> getOrderList() {
return orderList;
}
public void setOrderList(List<WashingOrder> orderList) {
this.orderList = orderList;
}
}
public class WashingOrder {
#Id
#SequenceGenerator(name = "orderNo", sequenceName = "orderNo")
#GeneratedValue(strategy = GenerationType.AUTO, generator = "orderNo")
#Column(name = "orderNo")
private Long orderNo;
#Column(name = "totalClothes", nullable = false)
#NotNull
private Integer totalClothes;
#Column(name = "mensCloth", nullable = true)
private Integer mensCloth;
#Column(name = "womensCloth", nullable = true)
private Integer womensCloth;
#Column(name = "otherCloth", nullable = true)
private Integer otherClothes;
#Column(name = "deliveryDate", nullable = true)
/* #DateTimeFormat(pattern = "yyyy-mm-dd") */
private Date deliveryDate;
#Column(name = "status", nullable = true)
private String orderStatus;
public Long getOrderNo() {
return orderNo;
}
public void setOrderNo(Long orderNo) {
this.orderNo = orderNo;
}
public Integer getTotalClothes() {
return totalClothes;
}
public void setTotalClothes(Integer totalClothes) {
this.totalClothes = totalClothes;
}
public Integer getMensCloth() {
return mensCloth;
}
public void setMensCloth(Integer mensCloth) {
this.mensCloth = mensCloth;
}
public Integer getWomensCloth() {
return womensCloth;
}
public void setWomensCloth(Integer womensCloth) {
this.womensCloth = womensCloth;
}
public Integer getOtherClothes() {
return otherClothes;
}
public void setOtherClothes(Integer otherClothes) {
this.otherClothes = otherClothes;
}
public Date getDeliveryDate() {
return deliveryDate;
}
public void setDeliveryDate(Date deliveryDate) {
this.deliveryDate = deliveryDate;
}
public String getOrderStatus() {
return orderStatus;
}
public void setOrderStatus(String orderStatus) {
this.orderStatus = orderStatus;
}
}
Implementation:
Session session = sessionFactory.getCurrentSession();
long id = 1;
Query query = session.createQuery("from user where id =" + id);
User emp6 = (User) session.load(User.class, new Long(1));
User user = (User) query.uniqueResult();
List<WashingOrder> washingOrder = user.getOrderList();
washingOrder.add(order);
user.setOrderList(washingOrder);
session.save(user);
Long orderID = (long) 1;
return orderID;
Here if you check I am getting the order list first (user.getOrderList()) and then I am adding the new list and saving the user.
But I want to save the new order list of the user without retrieve the previous order list.
There is any possibility for the adding new order data without retrieve the previous order list of the particular user.
You need to change a mapping
public class User {
#OneToMany(mappedBy = "user", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
private List<WashingOrder> orderList;
}
public class WashingOrder {
#ManyToOne(fetch = FetchType.LAZY)
#JoinColumn(name = "user_id")
private User user;
}
Session session = sessionFactory.getCurrentSession();
User user = (User) session.load(User.class, 1L);
WashingOrder order = new WashingOrder();
order.setUser(user);
session.save(order);
You can try to use a fake User instead of loading
WashingOrder order = new WashingOrder();
order.setUser(new User(1L));
session.save(order);
Function in my DAO (findByUsername) is always returning 0 rows no matter if I change the entity class, even after removing annotation from the entity there is no exception, just 0 rows. This code is implemented in the spring based app according to some examples I have found.
DAO:
#Repository("userDao")
public class UserDao extends CustomHibernateDaoSupport {
public void save(User user) {
getHibernateTemplate().save(user);
}
public void delete(User user) {
getHibernateTemplate().delete(user);
}
public User findByUsername(String username) throws DataNotFoundException {
Session session = getSession();
Criteria crit = session.createCriteria(User.class);
System.out.println(username);
crit.add(Restrictions.eq("username", username));
crit.setMaxResults(1);
List<User> users = crit.list();
System.out.println(users);
if (users.size() < 1) {
throw new DataNotFoundException();
}
return users.get(0);
}
}
ENTITY:
#Entity
#Table(name = "users")
public class User {
private Integer id;
private String username;
private String password;
private boolean active;
private String activationCode;
private Date createdAt;
private String email;
private Set<Wall> walls = new HashSet<Wall>();
#Id
#GeneratedValue
#Column(name = "id", unique = true, nullable = false)
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
#Column(name = "username", unique = true, nullable = false)
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
#Column(name = "password")
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
#Column(name = "active")
public boolean isActive() {
return active;
}
public void setActive(boolean active) {
this.active = active;
}
#Column(name = "activation_code")
public String getActivationCode() {
return activationCode;
}
public void setActivationCode(String activationCode) {
this.activationCode = activationCode;
}
#Column(name = "created_at", columnDefinition = "DATETIME")
public Date getCreatedAt() {
return createdAt;
}
public void setCreatedAt(Date createdAt) {
this.createdAt = createdAt;
}
#Column(name = "email")
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
#ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
#JoinTable(name = "users_has_walls", joinColumns = {
#JoinColumn(name = "user_id", nullable = false, updatable = false) },
inverseJoinColumns = { #JoinColumn(name = "wall_id",
nullable = false, updatable = false) })
public Set<Wall> getWalls() {
return walls;
}
public void setWalls(Set<Wall> walls) {
this.walls = walls;
}
}
The solution was to change import declaration to
import javax.persistence.Entity;
instead of hibernate.
User entity class was not imported.