Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- When I start the server I get this error in the log:
- Caused by: org.springframework.beans.factory.BeanCreationException:
- Could not autowire field: private com.ideafactory.mvc.customers.model.CustomerRepository com.ideafactory.mvc.customers.admin.AddressController.customerRepository;
- nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'customerRepository': Invocation of init method failed;
- nested exception is org.springframework.data.mapping.PropertyReferenceException: No property flush found for type Customer!
- package com.ideafactory.mvc.customers.model;
- import org.hibernate.annotations.Type;
- import org.hibernate.validator.constraints.Email;
- import org.hibernate.validator.constraints.NotEmpty;
- import org.springframework.security.core.GrantedAuthority;
- import org.springframework.security.core.authority.SimpleGrantedAuthority;
- import org.springframework.security.core.userdetails.UserDetails;
- import javax.persistence.*;
- import java.util.ArrayList;
- import java.util.Collection;
- import java.util.Date;
- import java.util.List;
- @Entity(name = "customer")
- @Table(name = "customers")
- public class Customer implements UserDetails {
- private static final long serialVersionUID = 1L;
- @Id
- @GeneratedValue(strategy = GenerationType.AUTO)
- private Long id;
- @Basic
- @Column(nullable = false)
- private String preferredName;
- @Basic
- @Column(nullable = false)
- private String firstName;
- @Basic
- @NotEmpty
- private String lastName;
- @Basic
- @Column(unique = true)
- @NotEmpty
- @Email
- private String email;
- @Basic
- @Column(nullable = false)
- private String password;
- @Basic
- @Column(nullable = true)
- private Date dateOfBirth;
- @Basic
- @Column(nullable = true)
- private String bio;
- @Basic
- @Column(nullable = true)
- private String website;
- @Basic
- @Column(nullable = true)
- private Date lastLogin;
- @Basic
- @Column(nullable = true)
- private Date lastLogout;
- @Enumerated(EnumType.STRING)
- private CustomerStatus status;
- @Basic
- @Column(nullable = false)
- private Date createdAt;
- @Basic
- @Column(nullable = false)
- private Date lastModified;
- @Type(type = "org.hibernate.type.NumericBooleanType")
- private boolean requiresReset;
- @Type(type="org.hibernate.type.NumericBooleanType")
- private boolean subscriber;
- @Enumerated(EnumType.STRING)
- private Gender gender;
- @Basic
- private String phoneNumber;
- @OneToMany(fetch = FetchType.EAGER, mappedBy = "customer")
- private List<Address> addressBook;
- public String getPreferredName() {
- return preferredName;
- }
- public void setPreferredName(String preferredName) {
- this.preferredName = preferredName;
- }
- public boolean isSubscriber() {
- return subscriber;
- }
- public void setSubscriber(boolean subscriber) {
- this.subscriber = subscriber;
- }
- public boolean isRequiresReset() {
- return requiresReset;
- }
- public Date getCreatedAt() {
- return createdAt;
- }
- public void setCreatedAt(Date createdAt) {
- this.createdAt = createdAt;
- }
- public Date getLastModified() {
- return lastModified;
- }
- public void setLastModified(Date lastModified) {
- this.lastModified = lastModified;
- }
- public boolean getRequiresReset() {
- return requiresReset;
- }
- public void setRequiresReset(boolean requiresReset) {
- this.requiresReset = requiresReset;
- }
- @ManyToMany
- @JoinTable(
- name="customer_roles",
- joinColumns={@JoinColumn(name="customerId", referencedColumnName="id")},
- inverseJoinColumns={@JoinColumn(name="roleId", referencedColumnName="id")})
- private List<Role> roles;
- @Transient
- public boolean isPersisted() {
- return (this.id != null);
- }
- public Long getId() {
- return id;
- }
- public void setId(Long id) {
- this.id = id;
- }
- public String getFirstName() {
- return firstName;
- }
- public void setFirstName(String name) {
- this.firstName = 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 void setPassword(String password)
- {
- this.password = password;
- }
- @Override
- public Collection<? extends GrantedAuthority> getAuthorities() {
- Collection<GrantedAuthority> authorities = new ArrayList<>();
- List<Role> userRoles = this.getRoles();
- if(userRoles != null)
- {
- for (Role role : userRoles) {
- SimpleGrantedAuthority authority = new SimpleGrantedAuthority(role.getRoleName());
- authorities.add(authority);
- }
- }
- return authorities;
- }
- @Override
- public String getUsername()
- {
- return getEmail();
- }
- @Override
- public String getPassword()
- {
- return this.password;
- }
- @Override
- public boolean isAccountNonExpired()
- {
- return true;
- }
- @Override
- public boolean isAccountNonLocked()
- {
- return true;
- }
- @Override
- public boolean isCredentialsNonExpired()
- {
- return true;
- }
- @Override
- public boolean isEnabled()
- {
- return true;
- }
- public List<Role> getRoles() {
- return roles;
- }
- public void setRoles(List<Role> roles) {
- this.roles = roles;
- }
- @PrePersist
- void createdAt() {
- this.createdAt = this.lastModified = new Date();
- }
- @PreUpdate
- void updatedAt() {
- this.createdAt = new Date();
- }
- public Date getDateOfBirth() {
- return dateOfBirth;
- }
- public void setDateOfBirth(Date dateOfBirth) {
- this.dateOfBirth = dateOfBirth;
- }
- public String getBio() {
- return bio;
- }
- public void setBio(String bio) {
- this.bio = bio;
- }
- public String getWebsite() {
- return website;
- }
- public void setWebsite(String website) {
- this.website = website;
- }
- public Date getLastLogin() {
- return lastLogin;
- }
- public void setLastLogin(Date lastLogin) {
- this.lastLogin = lastLogin;
- }
- public Date getLastLogout() {
- return lastLogout;
- }
- public void setLastLogout(Date lastLogout) {
- this.lastLogout = lastLogout;
- }
- public CustomerStatus getStatus() {
- return status;
- }
- public void setStatus(CustomerStatus status) {
- this.status = status;
- }
- public Gender getGender() {
- return gender;
- }
- public void setGender(Gender gender) {
- this.gender = gender;
- }
- public String getPhoneNumber() {
- return phoneNumber;
- }
- public void setPhoneNumber(String phoneNumber) {
- this.phoneNumber = phoneNumber;
- }
- public List<Address> getAddressBook() {
- return addressBook;
- }
- public void setAddressBook(List<Address> addressBook) {
- this.addressBook = addressBook;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement