2015-01-16 3 views
0

확인 작동하지 @JsonIgnore 나는 데이터베이스에서 모든 결과를 얻는 및 응답 본문으로이 반환ResponseBody 개체에서 개체 목록을 가져옵니다.

@Entity 
@Table(name = "companies") 

public class Company implements Serializable { 

    private static final long serialVersionUID = 6255059577246367312L; 
    @Id 
    @GeneratedValue 
    private Long id_company; 
    private String name; 
    private String adress; 
    private String email; 
    private String phone; 
    @OneToMany(mappedBy = "company") 
    @JsonManagedReference 
    private List<User> user; 

    @Override 
    public String toString() { 
     return "Company [id_company=" + id_company + ", name=" + name 
       + ", adress=" + adress + ", email=" + email + ", phone=" 
       + phone + "]"; 
    } 

    public Company() { 
    } 

    public Company(Long id_company, String name, String adress, String email, 
      String phone) { 
     this.id_company = id_company; 
     this.name = name; 
     this.adress = adress; 
     this.email = email; 
     this.phone = phone; 
    } 

    public Long getId_company() { 
     return id_company; 
    } 

    public void setId_company(Long id_company) { 
     this.id_company = id_company; 
    } 

    public String getName() { 
     return name; 
    } 

    public void setName(String name) { 
     this.name = name; 
    } 

    public String getAdress() { 
     return adress; 
    } 

    public void setAdress(String adress) { 
     this.adress = adress; 
    } 

    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<User> getUser() { 
     return user; 
    } 

    public void setUser(List<User> user) { 
     this.user = user; 
    } 

} 

클래스 사용자

@Entity 
@Table(name = "users") 
public class User implements Serializable { 

    private static final long serialVersionUID = 1L; 
    @Id 
    @GeneratedValue 
    private Long id_user; 
    @Column(nullable = false) 
    private String email; 
    @Column(nullable = true) 
    private String password; 
    private String firstname; 
    private String lastname; 
    private Boolean enabled; 
    private String phone; 
    @ManyToOne(fetch = FetchType.LAZY) 
    @JoinColumn(name = "id_company") 
    private Company company; 
    @ManyToOne(fetch = FetchType.LAZY) 
    @JoinColumn(name = "id_rank") 
    @JsonBackReference 
    private Authority authorities; 
    @OneToMany(mappedBy = "create_by") 
    private List<Cms> create_by; 
    @OneToMany(mappedBy = "modified_by") 
    private List<Cms> modified_by; 
    @OneToMany(mappedBy = "id_issuer") 
    private List<Ticket> id_issuer; 
    @OneToMany(mappedBy = "id_responsible") 
    private List<Ticket> id_responsible; 
    @OneToMany(mappedBy = "id_author") 
    private List<IssueMsg> id_author; 
    public User() { 
    } 

    public User(String email, String password, String firstname, String lastname, String phone, Company company, Authority authority) { 
     this.email = email; 
     this.password = password; 
     this.firstname = firstname; 
     this.lastname = lastname; 
     this.enabled = true; 
     this.phone = phone; 
     this.authorities = authority; 
    } 

    @Override 
    public String toString() { 
     return "User [id_user=" + id_user + ", email=" + email + ", password=" 
       + password + ", firstname=" + firstname + ", lastname=" 
       + lastname + ", enabled=" + enabled + ", phone=" + phone 
       + "]"; 
    } 

    public Long getId_user() { 
     return id_user; 
    } 

    public void setId_user(Long id_user) { 
     this.id_user = id_user; 
    } 

    public String getEmail() { 
     return email; 
    } 

    public void setEmail(String email) { 
     this.email = email; 
    } 
    @JsonIgnore 
    public String getPassword() { 
     return password; 
    } 

    public void setPassword(String password) { 
     this.password = password; 
    } 

    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 Boolean getEnabled() { 
     return enabled; 
    } 

    public void setEnabled(Boolean enabled) { 
     this.enabled = enabled; 
    } 

    public String getPhone() { 
     return phone; 
    } 

    public void setPhone(String phone) { 
     this.phone = phone; 
    } 

    public Company getCompany() { 
     return company; 
    } 

    public void setCompany(Company company) { 
     this.company = company; 
    } 

    /** 
    * @return the authorities 
    */ 
    public Authority getAuthorities() { 
     return authorities; 
    } 

    /** 
    * @param authorities the authorities to set 
    */ 
    public void setAuthorities(Authority authority) { 
     this.authorities = authority; 
    } 
    @JsonIgnore 
    public List<Cms> getCreate_by() { 
     return create_by; 
    } 

    public void setCreate_by(List<Cms> create_by) { 
     this.create_by = create_by; 
    } 
    @JsonIgnore 
    public List<Cms> getModified_by() { 
     return modified_by; 
    } 

    public void setModified_by(List<Cms> modified_by) { 
     this.modified_by = modified_by; 
    } 
    @JsonIgnore 
    public List<Ticket> getId_issuer() { 
     return id_issuer; 
    } 

    public void setId_issuer(List<Ticket> id_issuer) { 
     this.id_issuer = id_issuer; 
    } 
    @JsonIgnore 
    public List<Ticket> getId_responsible() { 
     return id_responsible; 
    } 

    public void setId_responsible(List<Ticket> id_responsible) { 
     this.id_responsible = id_responsible; 
    } 
    @JsonIgnore 
    public List<IssueMsg> getId_author() { 
     return id_author; 
    } 

    public void setId_author(List<IssueMsg> id_author) { 
     this.id_author = id_author; 
    } 
} 

그리고 클래스 회사가 있습니다.

내 JSON 응답은 user.company.user 목록을 얻고 무엇이 필요하지 않습니다. 나는 게터 회사 사용자 @JsonIgnore에 추가하려고했지만, 난

com.fasterxml.jackson.databind.JsonMappingException: No serializer found for class org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS)) (through reference chain: java.util.ArrayList[1]->projektzespolowy.model.User["company"]->projektzespolowy.model.Company_$$_jvstcb8_2["handler"]) 

나는 수정 thix하지만 아무도 도움에 대해 많은 게시물을 읽을 오류가 점점. 회사에서이 사용자 목록을 무시할 수 있습니까?

답변

1

User#company이 게이 프트되어 있기 때문에이 예외가 발생한다고 생각합니다. 그래서 jackson은 최대 절전 모드 프록시를 직렬화하려고 시도합니다. 매핑에 fetch = FetchType.EAGER을 시도하거나 결과를 반환하기 전에 컨트롤러에서 user.getCompany()으로 전화하십시오.

+0

Thx이 작업 중입니다. 너는 좋은 눈을 가지고있다. – seti

+0

Np, 다행이다. –

관련 문제