@JsonIgnore and @JsonBackReference are being Ignored

后端 未结 6 2130
感情败类
感情败类 2020-12-31 15:13

I\'m working with RestEasy, Jboss 7 and EJB 3.1. I\'m creating a RESTful web service that returns data in JSON format.

The problem is that I have a @ManyToOne<

6条回答
  •  滥情空心
    2020-12-31 15:57

    i'm using spring 4.0.1 , hibernate 4.3.5 ,jackson 1.9.2 and STS IDE

    i had the same exception but solved by annotating the setter by @Transient idont know why but it works fine

    This is my entity classes User.class

        //i get that suggestion from some sites
        @JsonIgnoreProperties({ "hibernateLazyInitializer", "handler" })
        @Entity
        @Table(name = "user", catalog = "someSchema")    
        public class User implements java.io.Serializable {
    
            private String name;
            private String password;
            private String username;
            private Set telephones = new HashSet(0);
    
            @OneToMany(fetch = FetchType.LAZY, mappedBy = "user")
            public Set getTelephones() {
                return this.telephones;
            }
    
            public void setTelephones(Set telephones) {
                this.telephones = telephones;
            }
        }
    

    Telephone.class

    @Entity
    @Table(name = "telephone", catalog = "someSchema")
    public class Telephone implements java.io.Serializable {
    
    
        private User user;
        private String telephone;
    
        @ManyToOne(fetch = FetchType.LAZY)
    
        @JoinColumn(name = "user_id", nullable = false)
        public User getUser() {
            return this.user;
        }
    
    
        @Transient  
        public void setUser(User user) {
        this.user = user;
       }
    
    }
    

    concerning registering jackson to my application, i used xml config

       
            
                
                    
                        
                    
                
            
        
    

    and mapper class

    public class HibernateAwareObjectMapper extends ObjectMapper {
    
        public HibernateAwareObjectMapper() {
            Hibernate4Module hm = new Hibernate4Module();
            registerModule(hm);
        }
    }
    

提交回复
热议问题