Fight With Me!!!

导航

org.codehaus.jackson.map.JsonMappingException: No serializer found for class org.hibernate.proxy.pojo.javassist.

2011-08-16 13:26:58,484 [http-8080-1] ERROR [core.web.ExceptionInterceptor] - org.codehaus.jackson.map.JsonMappingException: No serializer found for class org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS) ) (through reference chain: com.hollycrm.lbs.entity.identity.Role_$$_javassist_7["hibernateLazyInitializer"]) java.lang.IllegalArgumentException: org.codehaus.jackson.map.JsonMappingException: No serializer found for class org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS) ) (through reference chain: com.hollycrm.lbs.entity.identity.Role_$$_javassist_7["hibernateLazyInitializer"]) at org.springside.modules.utils.web.struts2.Struts2Utils.renderJson(Struts2Utils.java:148 at com.hollycrm.lbs.web.account.RoleAction.get(RoleAction.java:96) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:452) at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:291) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:254) at core.web.ExceptionInterceptor.intercept(ExceptionInterceptor.java:24) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:263) at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:133) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:207) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:207) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:190) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:243) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:142) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:166) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:207) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:94) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:176) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:190) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:187) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) at org.apache.struts2.interceptor.MessageStoreInterceptor.intercept(MessageStoreInterceptor.java:204) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52) at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:485) at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77) at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91) at orre.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at orre.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.struts2.dispatcher.ActionContextCleanUp.doFilter(ActionContextCleanUp.java:102) at orre.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at orre.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:343) at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:109) at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355) at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:97) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355) at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:100) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355) at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:78) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355) at org.s2011-8-16 13:26:58 orre.StandardWrapperValve invoke 严重: Servlet.service() for servlet default threw exception java.lang.IllegalStateException at ornnector.ResponseFacade.sendError(ResponseFacade.java:407 at javax.servlet.(HttpServletResponseWrapper.java:108) at org.springframeworntext.SaveContextOnUpdateOrErrorResponseWrapper.sendError(SaveContextOnUpdateOrErrorResponseWrapper.java:64) at org.apache.struts2.dispatcher.Dispatcher.sendError(Dispatcher.java:771) at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:506) at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77) at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91) at orre.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at orre.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.struts2.dispatcher.ActionContextCleanUp.doFilter(ActionContextCleanUp.java:102) at orre.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at orre.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:343) at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:109) at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355) at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:97) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355) at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:100) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355) at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:78) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355) at org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter.doFilter(RememberMeAuthenticationFilter.java:119) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355) at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355) at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:35) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355) at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:177) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355) at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:187) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355) at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355) at org.springframeworntext.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:79) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355) at org.springframework.security.web.session.ConcurrentSessionFilter.doFilter(ConcurrentSessionFilter.java:109) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355) at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:149) at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237) at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167) at orre.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at orre.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) at orre.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at orre.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) at orre.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at orre.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at orre.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at orre.StandardContextValve.invoke(StandardContextValve.java:191) at orre.StandardHostValve.invoke(StandardHostValve.java:127) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at orre.StandardEngineValve.invoke(StandardEngineValve.java:109) at ornnector.CoyoteAdapter.service(CoyoteAdapter.java:298) at oryote.(Http11Processor.java:859) at oryote.$Http11ConnectionHandler.process(Http11Protocol.java:588) at org.apach.JIoEndpoint$Worker.run(JIoEndpoint.java:489) at java.lang.Thread.run(Unknown Source) 2011-8-16 13:26:58 orre.ApplicationDispatcher invoke 严重: Servlet.service() for servlet jsp threw exception javax.servlet.ServletException: File "/common/500.jsp" not found at org.apache.jasper.servlet.JspServlet.handleMissingResource(JspServlet.java:335) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260) at javax.servlet.(HttpServlet.java:717) at orre.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at orre.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at orre.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646) at orre.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:551) at orre.ApplicationDispatcher.include(ApplicationDispatcher.java:488) at orre.StandardHostValve.custom(StandardHostValve.java:416) at orre.StandardHostValve.throwable(StandardHostValve.java:270) at orre.StandardHostValve.invoke(StandardHostValve.java:141) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at orre.StandardEngineValve.invoke(StandardEngineValve.java:109) at ornnector.CoyoteAdapter.service(CoyoteAdapter.java:298) at oryote.(Http11Processor.java:859) at oryote.$Http11Connecpringframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter.doFilter(RememberMeAuthenticationFilter.java:119) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355) at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355) at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:35) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355) at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:177) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355) at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:187) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355) at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355) at org.springframeworntext.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:79) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355) at org.springframework.security.web.session.ConcurrentSessionFilter.doFilter(ConcurrentSessionFilter.java:109) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355) at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:149) at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237) at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167) at orre.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at orre.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) at orre.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at orre.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) at orre.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at orre.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at orre.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at orre.StandardContextValve.invoke(StandardContextValve.java:191) at orre.StandardHostValve.invoke(StandardHostValve.java:127) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at orre.StandardEngineValve.invoke(StandardEngineValve.java:109) at ornnector.CoyoteAdapter.service(CoyoteAdapter.java:298) at oryote.(Http11Processor.java:859) at oryote.$Http11ConnectionHandler.process(Http11Protocol.java:588) at org.apach.JIoEndpoint$Worker.run(JIoEndpoint.java:489) at java.lang.Thread.run(Unknown Source) Caused by: org.codehaus.jackson.map.JsonMappingException: No serializer found for class org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS) ) (through reference chain: com.hollycrm.lbs.entity.identity.Role_$$_javassist_7["hibernateLazyInitializer"]) at org.codehaus.jackson.map.ser.StdSerializerProvider$1.serialize(StdSerializerProvider.java:62) at org.codehaus.jackson.map.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:268) at org.codehaus.jackson.map.ser.BeanSerializer.serializeFields(BeanSerializer.java:160) at org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer.java:131) at org.codehaus.jackson.map.ser.StdSerializerProvider._serializeValue(StdSerializerProvider.java:297) at org.codehaus.jackson.map.ser.StdSerializerProvider.serializeValue(StdSerializerProvider.java:224) at org.codehaus.jackson.map.ObjectMapper._configAndWriteValue(ObjectMapper.java:1846) at org.codehaus.jackson.map.ObjectMapper.writeValue(ObjectMapper.java:1457) at org.springside.modules.utils.web.struts2.Struts2Utils.renderJson(Struts2Utils.java:146) ... 111 more tionHandler.process(Http11Protocol.java:588) at org.apach.JIoEndpoint$Worker.run(JIoEndpoint.java:489) at java.lang.Thread.run(Unknown Source) 2011-8-16 13:26:58 orre.StandardHostValve custom 严重: Exception Processing ErrorPage[exceptionType=java.lang.Throwable, location=/common/500.jsp] javax.servlet.ServletException: File "/common/500.jsp" not found at org.apache.jasper.servlet.JspServlet.handleMissingResource(JspServlet.java:335) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260) at javax.servlet.(HttpServlet.java:717) at orre.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at orre.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at orre.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646) at orre.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:551) at orre.ApplicationDispatcher.include(ApplicationDispatcher.java:488) at orre.StandardHostValve.custom(StandardHostValve.java:416) at orre.StandardHostValve.throwable(StandardHostValve.java:270) at orre.StandardHostValve.invoke(StandardHostValve.java:141) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at orre.StandardEngineValve.invoke(StandardEngineValve.java:109) at ornnector.CoyoteAdapter.service(CoyoteAdapter.java:298) at oryote.(Http11Processor.java:859) at oryote.$Http11ConnectionHandler.process(Http11Protocol.java:588) at org.apach.JIoEndpoint$Worker.run(JIoEndpoint.java:489) at java.lang.Thread.run(Unknown Source)

  引起以下问题的主要原因就是jackson把懒加载也作为pojo进行序列化了。
解决方法:在该实体类的所有关联集合类上加上

  @JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})就OK了

比如:

package com.hzboy.orm;


import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.codehaus.jackson.annotate.JsonIgnore;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.annotate.JsonManagedReference;

/**
 * 
 * @author xiefeng
 * 
 */
@Entity
@Table(name = "t_computer")
public class Computer extends BaseEntity {
    // 电脑类型
    private String computerType;
    // 电脑型号
    private String computerName;
    // cpu信息
    private String cpuInfo;
    // 内存信息
    private String ramInfo;
    // 硬盘大小
    private String storge;
    // 显卡类型
    private String diaplayType;
    // 主机编码
    private String hostID;
    // 显示器型号
    private String displayID;
    // 备注
    private String remark;
    // 出厂日期
    private Date time;
    // 当前使用人
    private User currentUser;
    // 使用人id
    private Integer userId;
    // 领用日期
    private Date startDate;
    // 所属部门
    private Department department;
    // 部门id
    private Integer departmentId;
    //用途
    private String purpose;
    //使用人姓名
    private String userName;
    
    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getPurpose() {
        return purpose;
    }

    public void setPurpose(String purpose) {
        this.purpose = purpose;
    }

    @Column(name = "computer_type")
    public String getComputerType() {
        return computerType;
    }

    public void setComputerType(String computerType) {
        this.computerType = computerType;
    }

    @Column(name = "computer_name")
    public String getComputerName() {
        return computerName;
    }

    public void setComputerName(String computerName) {
        this.computerName = computerName;
    }

    @Column(name = "cpu_info")
    public String getCpuInfo() {
        return cpuInfo;
    }

    public void setCpuInfo(String cpuInfo) {
        this.cpuInfo = cpuInfo;
    }
    
    @Column(name = "ram_info")
    public String getRamInfo() {
        return ramInfo;
    }

    public void setRamInfo(String ramInfo) {
        this.ramInfo = ramInfo;
    }

    public String getStorge() {
        return storge;
    }

    public void setStorge(String storge) {
        this.storge = storge;
    }

    @Column(name = "diaplay_type")
    public String getDiaplayType() {
        return diaplayType;
    }

    public void setDiaplayType(String diaplayType) {
        this.diaplayType = diaplayType;
    }

    @Column(name = "host_id")
    public String getHostID() {
        return hostID;
    }

    public void setHostID(String hostID) {
        this.hostID = hostID;
    }

    @Column(name = "display_id")
    public String getDisplayID() {
        return displayID;
    }

    public void setDisplayID(String displayID) {
        this.displayID = displayID;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    @Column(columnDefinition = "date")
    public Date getTime() {
        return time;
    }

    public void setTime(Date time) {
        this.time = time;
    }
    @ManyToOne(cascade = { CascadeType.PERSIST,
            CascadeType.MERGE, CascadeType.REFRESH }, fetch = FetchType.LAZY)
    @JoinColumn(name = "current_user_id")
    public User getCurrentUser() {
        return currentUser;
    }
    @JsonManagedReference
    public void setCurrentUser(User currentUser) {
        this.currentUser = currentUser;
    }

    @Transient
    public Integer getUserId() {
        return userId;
    }

    public void setUserId(Integer userId) {
        this.userId = userId;
    }
    @Column(name="start_date",columnDefinition = "date")
    public Date getStartDate() {
        return startDate;
    }

    public void setStartDate(Date startDate) {
        this.startDate = startDate;
    }
    @ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE }, fetch = FetchType.LAZY)  
    @JoinColumn(name = "dept_id")
    public Department getDepartment() {
        return department;
    }

    @JsonManagedReference
    public void setDepartment(Department department) {
        this.department = department;
    }

    @Transient
    public Integer getDepartmentId() {
        return departmentId;
    }

    public void setDepartmentId(Integer departmentId) {
        this.departmentId = departmentId;
    }

    
}

比如以上实体中引用了2个类:User  和  Department,那么这2个类必须加上    

@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})

 

如下:

package com.hzboy.orm;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.codehaus.jackson.annotate.JsonIgnore;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.annotate.JsonManagedReference;


/**
 * 系统用户实体类
 * @author tinner
 *
 */
@Entity(name = "com.hzboy.orm.User")
@Table(name = "sys_user")
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
public class User extends BaseEntity {

    /**
     * 
     */
    private static final long serialVersionUID = -1343842065506227012L;

    public User() {

    }

    public User(Integer id) {
        this.id = id;
    }

    // 登录名
    private String loginName;
    // 密码123456-b594510740d2ac4261c1b2fe87850d08
    private String pswd;
    // 姓名
    private String nickName;
    // 性别
    private Short sex;
    // 年龄段
    private String ageStage;
    // 是否系统管理员
    private boolean systemAdmin;
    //联系电话
    private  String  tel;
    //Email
    private  String  email;
    //是否工程师
    private  Boolean  isEnginner;
    //是否前端客户    是则显示前台html,但同时保留后台相关模块
    private  Boolean  isFrontUser;
    //相关部门
    private  Department  department;
    //相关部门前台描述
    private  String   departmentName;
    private  Integer  departmentId;
    //用户编号
    private  String  userCode;
    //附加用于导入
    private  String  idCode;
    //附加的部门信息  用于计算
    private  String  departmentCode;
    @Column(name = "login_name")
    public String getLoginName() {
        return loginName;
    }

    public void setLoginName(String loginName) {
        this.loginName = loginName;
    }

    @Column(name = "pswd")
    public String getPswd() {
        return pswd;
    }

    public void setPswd(String pswd) {
        this.pswd = pswd;
    }

    @Column(name = "nick_name")
    public String getNickName() {
        return nickName;
    }

    public void setNickName(String nickName) {
        this.nickName = nickName;
    }

    @Column(name = "sex")
    public Short getSex() {
        return sex;
    }

    public void setSex(Short sex) {
        this.sex = sex;
    }

    @Column(name = "age_stage")
    public String getAgeStage() {
        return ageStage;
    }

    public void setAgeStage(String ageStage) {
        this.ageStage = ageStage;
    }

    @Column(name = "system_admin")
    public boolean isSystemAdmin() {
        return systemAdmin;
    }

    public void setSystemAdmin(boolean systemAdmin) {
        this.systemAdmin = systemAdmin;
    }

    private List<Role> roles;

    @ManyToMany(fetch = FetchType.LAZY, cascade = (CascadeType.REMOVE))
    @JoinTable(name = "sys_user_role", joinColumns = { @JoinColumn(name = "user_id") }, inverseJoinColumns = { @JoinColumn(name = "role_id") })
    public List<Role> getRoles() {
        return roles;
    }

    public void setRoles(List<Role> roles) {
        this.roles = roles;
    }

    private Integer[] roleIds;

    @Transient
    public Integer[] getRoleIds() {
        return roleIds;
    }

    public void setRoleIds(Integer[] roleIds) {
        this.roleIds = roleIds;
    }
    @Column(name="email")
    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }
    @Column(name="is_enginner")
    public Boolean getIsEnginner() {
        return isEnginner;
    }

    
    public void setIsEnginner(Boolean isEnginner) {
        this.isEnginner = isEnginner;
    }
    @Column(name="is_front_user")
    public Boolean getIsFrontUser() {
        return isFrontUser;
    }

    public void setIsFrontUser(Boolean isFrontUser) {
        this.isFrontUser = isFrontUser;
    }

    public String getTel() {
        return tel;
    }

    public void setTel(String tel) {
        this.tel = tel;
    }
    @JsonIgnore 
    @ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE }, fetch = FetchType.LAZY)  
    @JoinColumn(name="department_id")
    public Department getDepartment() {
        return department;
    }
    @JsonManagedReference
    public void setDepartment(Department department) {
        this.department = department;
    }
    
    @Transient
    public String getDepartmentName() {
        return departmentName;
    }

    public void setDepartmentName(String departmentName) {
        this.departmentName = departmentName;
    }
    
    @Transient
    public Integer getDepartmentId() {
        return departmentId;
    }

    public void setDepartmentId(Integer departmentId) {
        this.departmentId = departmentId;
    }
    @Column(name="user_code")
    public String getUserCode() {
        return userCode;
    }

    public void setUserCode(String userCode) {
        this.userCode = userCode;
    }
    @Column(name="id_from_import")
    public String getIdCode() {
        return idCode;
    }

    public void setIdCode(String idCode) {
        this.idCode = idCode;
    }
    public String getDepartmentCode() {
        return departmentCode;
    }

    public void setDepartmentCode(String departmentCode) {
        this.departmentCode = departmentCode;
    }
}
package com.hzboy.orm;

import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.codehaus.jackson.annotate.JsonIgnore;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.annotate.JsonManagedReference;


/**
 * 部门信息
 * @author tinner
 *
 */
@Entity
@Table(name="sys_dpt")
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
public class Department   extends  BaseEntity{
        //部门名称
        private  String  name;
        //部门编号
        private  String  code;
        //父节点id
        private Department parent;
        //上级分类
        private Integer parentId;
        //相关客户
        private  Client  client;
        //附加用于导入
        private  String  idCode;
        
        public String getName() {
            return name;
        }
        public void setName(String name) {
            this.name = name;
        }
        public String getCode() {
            return code;
        }
        public void setCode(String code) {
            this.code = code;
        }
        private Set<Department> children = new LinkedHashSet<Department>();

         @JsonIgnore 
         @ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE }, fetch = FetchType.LAZY)  
         @JoinColumn(name="parent_id") 
        public Department getParent() {
            return parent;
        }
         @JsonManagedReference
        public void setParent(Department parent) {
            this.parent = parent;
        }
         
         @JsonManagedReference
         @OneToMany(mappedBy="parent",cascade=CascadeType.ALL)  
         public Set<Department> getChildren() {
             Iterator<Department> it = children.iterator();  
             while (it.hasNext()) {  
                 Department str = it.next();  
                 if(str.isDeleted())  {
                     it.remove();
                 }
             }  
             return children;
         }
         @JsonManagedReference
         public void setChildren(Set<Department> children) {
             this.children = children;
         }
         @Transient
        public Integer getParentId() {
            return parentId;
        }
        public void setParentId(Integer parentId) {
            this.parentId = parentId;
        }
        @JsonIgnore 
        @ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE }, fetch = FetchType.LAZY)  
        @JoinColumn(name="client_id") 
        public Client getClient() {
            return client;
        }
        @JsonManagedReference
        public void setClient(Client client) {
            this.client = client;
        }
        public String getIdCode() {
            return idCode;
        }
        public void setIdCode(String idCode) {
            this.idCode = idCode;
        }
        
}

 

posted on 2015-04-09 15:45  nickTimer  阅读(3108)  评论(0编辑  收藏  举报