由于equals方法的实施有问题,无法检查对象xxx

时间:2014-05-20 14:14:53

标签: java hibernate exception wicket

我得到了这个例外,我不知道还有什么可以检查,因为我所尝试的一切都没用......

例外是:

2014-05-20 16:05:25,284 WARN  [20812305@qtp-19256634-0 CheckingObjectOutputStream] Wasn't possible to check the object 'class de.mycompany.study.core.data.base.User_$$_javassist_38' possible due an problematic implementation of equals method
org.hibernate.LazyInitializationException: could not initialize proxy - no Session
    at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:164) ~[hibernate-core-4.2.4.Final.jar:4.2.4.Final]
    at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:285) ~[hibernate-core-4.2.4.Final.jar:4.2.4.Final]
    at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(JavassistLazyInitializer.java:185) ~[hibernate-core-4.2.4.Final.jar:4.2.4.Final]
    at de.mycompany.study.core.data.base.User_$$_javassist_38.equals(Nutzer_$$_javassist_38.java) ~[study-core-1.1.0.jar:?]
    at java.util.Vector.indexOf(Vector.java:404) ~[?:1.7.0_09]
    at java.util.Vector.contains(Vector.java:363) ~[?:1.7.0_09]
    at org.apache.wicket.core.util.objects.checker.CheckingObjectOutputStream.check(CheckingObjectOutputStream.java:341) [wicket-core-6.9.0.jar:6.9.0]
    at org.apache.wicket.core.util.objects.checker.CheckingObjectOutputStream.checkFields(CheckingObjectOutputStream.java:645) [wicket-core-6.9.0.jar:6.9.0]
    at org.apache.wicket.core.util.objects.checker.CheckingObjectOutputStream.internalCheck(CheckingObjectOutputStream.java:569) [wicket-core-6.9.0.jar:6.9.0]
    at org.apache.wicket.core.util.objects.checker.CheckingObjectOutputStream.check(CheckingObjectOutputStream.java:361) [wicket-core-6.9.0.jar:6.9.0]
    at org.apache.wicket.core.util.objects.checker.CheckingObjectOutputStream.checkFields(CheckingObjectOutputStream.java:645) [wicket-core-6.9.0.jar:6.9.0]
    at org.apache.wicket.core.util.objects.checker.CheckingObjectOutputStream.internalCheck(CheckingObjectOutputStream.java:569) [wicket-core-6.9.0.jar:6.9.0]
    at org.apache.wicket.core.util.objects.checker.CheckingObjectOutputStream.check(CheckingObjectOutputStream.java:361) [wicket-core-6.9.0.jar:6.9.0]
    at org.apache.wicket.core.util.objects.checker.CheckingObjectOutputStream.checkFields(CheckingObjectOutputStream.java:645) [wicket-core-6.9.0.jar:6.9.0]
    at org.apache.wicket.core.util.objects.checker.CheckingObjectOutputStream.internalCheck(CheckingObjectOutputStream.java:569) [wicket-core-6.9.0.jar:6.9.0]
    at org.apache.wicket.core.util.objects.checker.CheckingObjectOutputStream.check(CheckingObjectOutputStream.java:361) [wicket-core-6.9.0.jar:6.9.0]
    at org.apache.wicket.core.util.objects.checker.CheckingObjectOutputStream.internalCheck(CheckingObjectOutputStream.java:432) [wicket-core-6.9.0.jar:6.9.0]
    at org.apache.wicket.core.util.objects.checker.CheckingObjectOutputStream.check(CheckingObjectOutputStream.java:361) [wicket-core-6.9.0.jar:6.9.0]
    at org.apache.wicket.core.util.objects.checker.CheckingObjectOutputStream.checkFields(CheckingObjectOutputStream.java:645) [wicket-core-6.9.0.jar:6.9.0]
    at org.apache.wicket.core.util.objects.checker.CheckingObjectOutputStream.internalCheck(CheckingObjectOutputStream.java:569) [wicket-core-6.9.0.jar:6.9.0]
    at org.apache.wicket.core.util.objects.checker.CheckingObjectOutputStream.check(CheckingObjectOutputStream.java:361) [wicket-core-6.9.0.jar:6.9.0]
    at org.apache.wicket.core.util.objects.checker.CheckingObjectOutputStream.internalCheck(CheckingObjectOutputStream.java:432) [wicket-core-6.9.0.jar:6.9.0]
    at org.apache.wicket.core.util.objects.checker.CheckingObjectOutputStream.check(CheckingObjectOutputStream.java:361) [wicket-core-6.9.0.jar:6.9.0]
    at org.apache.wicket.core.util.objects.checker.CheckingObjectOutputStream.checkFields(CheckingObjectOutputStream.java:645) [wicket-core-6.9.0.jar:6.9.0]
    at org.apache.wicket.core.util.objects.checker.CheckingObjectOutputStream.internalCheck(CheckingObjectOutputStream.java:569) [wicket-core-6.9.0.jar:6.9.0]
    at org.apache.wicket.core.util.objects.checker.CheckingObjectOutputStream.check(CheckingObjectOutputStream.java:361) [wicket-core-6.9.0.jar:6.9.0]
    at org.apache.wicket.core.util.objects.checker.CheckingObjectOutputStream.internalCheck(CheckingObjectOutputStream.java:432) [wicket-core-6.9.0.jar:6.9.0]
    at org.apache.wicket.core.util.objects.checker.CheckingObjectOutputStream.check(CheckingObjectOutputStream.java:361) [wicket-core-6.9.0.jar:6.9.0]
    at org.apache.wicket.core.util.objects.checker.CheckingObjectOutputStream.checkFields(CheckingObjectOutputStream.java:645) [wicket-core-6.9.0.jar:6.9.0]
    at org.apache.wicket.core.util.objects.checker.CheckingObjectOutputStream.internalCheck(CheckingObjectOutputStream.java:569) [wicket-core-6.9.0.jar:6.9.0]
    at org.apache.wicket.core.util.objects.checker.CheckingObjectOutputStream.check(CheckingObjectOutputStream.java:361) [wicket-core-6.9.0.jar:6.9.0]
    at org.apache.wicket.core.util.objects.checker.CheckingObjectOutputStream.writeObjectOverride(CheckingObjectOutputStream.java:713) [wicket-core-6.9.0.jar:6.9.0]
    at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:342) [?:1.7.0_09]
    at org.apache.wicket.serialize.java.JavaSerializer$SerializationCheckerObjectOutputStream.writeObjectOverride(JavaSerializer.java:268) [wicket-core-6.9.0.jar:6.9.0]
    at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:342) [?:1.7.0_09]
    at org.apache.wicket.serialize.java.JavaSerializer.serialize(JavaSerializer.java:78) [wicket-core-6.9.0.jar:6.9.0]
    at org.apache.wicket.pageStore.DefaultPageStore.serializePage(DefaultPageStore.java:376) [wicket-core-6.9.0.jar:6.9.0]
    at org.apache.wicket.pageStore.DefaultPageStore.storePage(DefaultPageStore.java:150) [wicket-core-6.9.0.jar:6.9.0]
    at org.apache.wicket.page.PageStoreManager$PersistentRequestAdapter.storeTouchedPages(PageStoreManager.java:384) [wicket-core-6.9.0.jar:6.9.0]
    at org.apache.wicket.page.RequestAdapter.commitRequest(RequestAdapter.java:181) [wicket-core-6.9.0.jar:6.9.0]
    at org.apache.wicket.page.AbstractPageManager.commitRequest(AbstractPageManager.java:98) [wicket-core-6.9.0.jar:6.9.0]
    at org.apache.wicket.page.PageManagerDecorator.commitRequest(PageManagerDecorator.java:73) [wicket-core-6.9.0.jar:6.9.0]
    at org.apache.wicket.page.PageAccessSynchronizer$2.commitRequest(PageAccessSynchronizer.java:281) [wicket-core-6.9.0.jar:6.9.0]
    at org.apache.wicket.Application$2.onDetach(Application.java:1628) [wicket-core-6.9.0.jar:6.9.0]
    at org.apache.wicket.request.cycle.RequestCycleListenerCollection$3.notify(RequestCycleListenerCollection.java:105) [wicket-core-6.9.0.jar:6.9.0]
    at org.apache.wicket.request.cycle.RequestCycleListenerCollection$3.notify(RequestCycleListenerCollection.java:101) [wicket-core-6.9.0.jar:6.9.0]
    at org.apache.wicket.util.listener.ListenerCollection$1.notify(ListenerCollection.java:120) [wicket-util-6.9.0.jar:6.9.0]
    at org.apache.wicket.util.listener.ListenerCollection.reversedNotify(ListenerCollection.java:144) [wicket-util-6.9.0.jar:6.9.0]
    at org.apache.wicket.util.listener.ListenerCollection.reversedNotifyIgnoringExceptions(ListenerCollection.java:113) [wicket-util-6.9.0.jar:6.9.0]
    at org.apache.wicket.request.cycle.RequestCycleListenerCollection.onDetach(RequestCycleListenerCollection.java:100) [wicket-core-6.9.0.jar:6.9.0]
    at org.apache.wicket.request.cycle.RequestCycle.onDetach(RequestCycle.java:640) [wicket-core-6.9.0.jar:6.9.0]
    at org.apache.wicket.request.cycle.RequestCycle.detach(RequestCycle.java:589) [wicket-core-6.9.0.jar:6.9.0]
    at org.apache.wicket.request.cycle.RequestCycle.processRequestAndDetach(RequestCycle.java:293) [wicket-core-6.9.0.jar:6.9.0]
    at org.apache.wicket.protocol.http.WicketFilter.processRequestCycle(WicketFilter.java:259) [wicket-core-6.9.0.jar:6.9.0]
    at org.apache.wicket.protocol.http.WicketFilter.processRequest(WicketFilter.java:201) [wicket-core-6.9.0.jar:6.9.0]
    at org.apache.wicket.protocol.http.WicketServlet.doGet(WicketServlet.java:137) [wicket-core-6.9.0.jar:6.9.0]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:707) [servlet-api-2.5-20081211.jar:?]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:820) [servlet-api-2.5-20081211.jar:?]
    at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:502) [jetty-6.1.15.jar:6.1.15]
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1148) [jetty-6.1.15.jar:6.1.15]
    at org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:180) [spring-orm-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1139) [jetty-6.1.15.jar:6.1.15]
    at org.apache.logging.log4j.core.web.Log4jServletFilter.doFilter(Log4jServletFilter.java:66) [log4j-core-2.0-beta9.jar:2.0-beta9]
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1139) [jetty-6.1.15.jar:6.1.15]
    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:378) [jetty-6.1.15.jar:6.1.15]
    at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216) [jetty-6.1.15.jar:6.1.15]
    at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181) [jetty-6.1.15.jar:6.1.15]
    at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765) [jetty-6.1.15.jar:6.1.15]
    at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:417) [jetty-6.1.15.jar:6.1.15]
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152) [jetty-6.1.15.jar:6.1.15]
    at org.mortbay.jetty.Server.handle(Server.java:324) [jetty-6.1.15.jar:6.1.15]
    at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:535) [jetty-6.1.15.jar:6.1.15]
    at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:865) [jetty-6.1.15.jar:6.1.15]
    at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:539) [jetty-6.1.15.jar:6.1.15]
    at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212) [jetty-6.1.15.jar:6.1.15]
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404) [jetty-6.1.15.jar:6.1.15]
    at org.mortbay.jetty.bio.SocketConnector$Connection.run(SocketConnector.java:228) [jetty-6.1.15.jar:6.1.15]
    at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:520) [jetty-util-6.1.15.jar:6.1.15]

起初我认为这是Hibernate代理的一些问题,但是引发了同样的异常:

2014-05-20 16:05:25,300 WARN  [20812305@qtp-19256634-0 CheckingObjectOutputStream] Wasn't possible to check the object 'class org.hibernate.collection.internal.PersistentSet' possible due an problematic implementation of equals method
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: de.mycompany.study.core.data.base.User.roles, could not initialize proxy - no Session

嗯,也许它是一样的,$$ _ javassist_38是“角色”集合的代理。

有什么想法吗?

编辑:此异常仅在应用程序中的某个点抛出,执行与抛出异常时非常相似的事情不会引发异常......

编辑2:这是相关代码:

    @Entity(name = "user")
    @Audited
    public class User extends DataObjectAudit {

        private static final long serialVersionUID = 1L;

        private Center center = null;
        private Set<UserProjectCenterRole> roles = new HashSet<UserProjectCenterRole>();
        private Boolean active = null;
        /* other properties */

        public User() {
            super();
        }

        @OneToMany(mappedBy = "user", fetch = FetchType.LAZY, orphanRemoval = true)
        @Cascade(value = { CascadeType.MERGE, CascadeType.PERSIST, CascadeType.DELETE, CascadeType.SAVE_UPDATE })
        @Filters({ @Filter(name = "deletedFilter", condition = "deleted <> :deletedParam") })
        @NotAudited
        public Set<UserProjectCenterRole> getRoles() {
            return roles;
        }

        @ManyToOne(optional = true, fetch = FetchType.LAZY)
        @NotAudited
        public Center getCenter() {
            return center;
        }

        @Basic
        public Boolean getActive() {
            return active;
        }
}

    @MappedSuperclass
    @FilterDef(name = "deletedFilter", parameters = {@ParamDef(name = "deletedParam", type = "boolean")})
    @Filters( { @Filter(name = "deletedFilter", condition = "deleted <> :deletedParam") })
    public abstract class DataObjectAudit extends DataObjectPrimaryKey implements IAuditableObject {

    private static final long serialVersionUID = 1L;

    @DisableTracking
    private User createdBy;
    @DisableTracking
    private User editedBy;

    public DataObjectAudit() {
    }

    @ManyToOne(optional = true, fetch = FetchType.LAZY)
    @JoinColumn(name = "created_by")
    @Index(name = "created_by")
    @NotAudited
    @Override
    public User getCreatedBy() {
        return createdBy;
    }

    @ManyToOne(optional = true, fetch = FetchType.LAZY)
    @JoinColumn(name = "edited_by")
    @NotAudited 
    @Override
    public User getEditedBy() {
        return editedBy;
    }
}

@MappedSuperclass
public abstract class DataObjectPrimaryKey extends DataObject implements Serializable{

    private static final long serialVersionUID = 1L;

    private Long id = null;

    @Id
    @GeneratedValue
    @Basic
    public Long getId() {
        return id;
    }

    @Override
    @Lazy
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (!getUnlazyClassName(getClass()).equals(getUnlazyClassName(obj.getClass()))) {
            return false;
        }
        DataObjectPrimaryKey other = (DataObjectPrimaryKey) obj;
        if ((getId() == null) && (other.getId() != null)) {
            return false;
        } else if ((getId() != null) || (other.getId() == null)) {
            return false;
        } else if ((getId() == null) && (other.getId() == null)) {
            return super.equals(obj);
        } else { 
            return getId().equals(other.getId());
        }
    }

    @Override
    @Lazy
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = (prime * result) + ((getId() == null) ? super.hashCode() : getId().hashCode());
        return result;
    }

    private static String getUnlazyClassName(Class<?> clazz) {
        String className = clazz.getName();
        if (className.contains("_$$")) {
            className = className.substring(0, className.indexOf("_$$"));
        }

        return className;
    }
}

2 个答案:

答案 0 :(得分:1)

要注意的一些事项:

1)是否根据javadoc始终如一地实现了?

2)你实现了与你的equals一致的hashcode()吗?

答案 1 :(得分:1)

最后我找到了异常的原因......并且它与这3个类中的任何一个都没有关系......

这是一个没有实现Serializable的类,并且被用作可序列化类中的类属性...

我不知道的是为什么错误并没有指向实际有问题的班级......