Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Problem migrating from Eclipselink
PostPosted: Thu Jun 17, 2010 12:35 pm 
Newbie

Joined: Thu Jun 17, 2010 12:31 pm
Posts: 4
I'm trying to replace Eclispelink with Hibernate as my JPA provider, however I am unable to deploy my application, I get the following Exception:

Code:
java.lang.ClassCastException: org.hibernate.mapping.JoinedSubclass cannot be cast to org.hibernate.mapping.RootClass
        at org.hibernate.cfg.annotations.PropertyBinder.bind(PropertyBinder.java:209)
        at org.hibernate.cfg.annotations.PropertyBinder.makePropertyValueAndBind(PropertyBinder.java:200)
        at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:1979)
        at org.hibernate.cfg.AnnotationBinder.processIdPropertiesIfNotAlready(AnnotationBinder.java:762)
        at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:726)
        at org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:636)
        at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:359)
        at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1206)
        at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1449)
        at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:193)
        at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:1077)
        at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:673)
        at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:72)
        at org.glassfish.persistence.jpa.PersistenceUnitLoader.loadPU(PersistenceUnitLoader.java:181)
        at org.glassfish.persistence.jpa.PersistenceUnitLoader.<init>(PersistenceUnitLoader.java:96)
        at org.glassfish.persistence.jpa.JPADeployer.prepare(JPADeployer.java:121)
        at com.sun.enterprise.v3.server.ApplicationLifecycle.prepareModule(ApplicationLifecycle.java:644)
        at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:296)
        at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:183)
        at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:272)
        at com.sun.enterprise.v3.admin.CommandRunnerImpl$1.execute(CommandRunnerImpl.java:305)
        at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:320)
        at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1176)
        at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$900(CommandRunnerImpl.java:83)
        at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1235)
        at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1224)
        at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:365)
        at com.sun.enterprise.v3.admin.AdminAdapter.service(AdminAdapter.java:204)
        at com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:166)
        at com.sun.enterprise.v3.server.HK2Dispatcher.dispath(HK2Dispatcher.java:100)
        at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:245)
        at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:791)
        at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:693)
        at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:954)
        at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:170)
        at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:135)
        at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:102)
        at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:88)
        at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76)
        at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:53)
        at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:57)
        at com.sun.grizzly.ContextTask.run(ContextTask.java:69)
        at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:330)
        at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:309)
        at java.lang.Thread.run(Thread.java:619)


I'm running on glassfish v3.0.1 with the bundled Hibernate 3.5.0-03 OSGI bundle.

I don't know where to start with fixing this, any insight would be appreciated.

Thanks


Top
 Profile  
 
 Post subject: Re: Problem migrating from Eclipselink
PostPosted: Thu Jun 17, 2010 3:25 pm 
Newbie

Joined: Thu Jun 17, 2010 12:31 pm
Posts: 4
The stacktrace doesn't indicate which classes are causing the problem, but here are the classes that use the join table strategy:

Code:
package ca.triumf.mis.qms.workrequest.jpa;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import ca.triumf.mis.qms.workrequest.jpa.enums.WorkflowState;
import java.util.ArrayList;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Transient;
import org.hibernate.annotations.Type;

@Entity
@Table(name = "WR_WORKFLOW")
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorColumn(name = "WORKFLOW_TYPE")
@NamedQueries({
    @NamedQuery(name = "Workflow.findAll", query = "SELECT w FROM Workflow w"),
    @NamedQuery(name = "Workflow.findById", query = "SELECT w FROM Workflow w WHERE w.id = :id")})
public abstract class Workflow implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "ID")
    private Integer id;
    @JoinColumn(name = "REQUESTOR", referencedColumnName = "XA_NAME_ID")
    @ManyToOne
    private XaName requestor;
    @Column(name = "SUBMITTED_TS")
    @Temporal(TemporalType.DATE)
    private Date submittedTs;
    @Column(name = "CREATE_TS")
    @Temporal(TemporalType.DATE)
    private Date createTs;
    @JoinTable(name = "WR_WORKFLOW_REQUESTOR", joinColumns = {
        @JoinColumn(name = "WORKFLOW", referencedColumnName = "ID", nullable = false)}, inverseJoinColumns = {
        @JoinColumn(name = "REQUESTOR", referencedColumnName = "XA_NAME_ID", nullable = false)})
    @ManyToMany
    private List<XaName> xaNameList;//additional requestor list
    @JoinTable(name = "WR_WORKFLOW_WATCHER", joinColumns = {
        @JoinColumn(name = "WORKFLOW", referencedColumnName = "ID", nullable = false)}, inverseJoinColumns = {
        @JoinColumn(name = "USER", referencedColumnName = "XA_NAME_ID", nullable = false)})
    @ManyToMany
    private List<XaName> xaNameList1;//watcher list
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "workflow")
    private List<WorkflowHistory> workflowHistoryList;
    @OneToOne(cascade = CascadeType.ALL, mappedBy = "workflow")
    private Request request;
    @OneToOne(cascade = CascadeType.ALL, mappedBy = "workflow")
    private ProjectCharterSheet projectCharterSheet;
    @JoinColumn(name = "WORKFLOW_TYPE", referencedColumnName = "WORKFLOW_TYPE")
    @ManyToOne(optional = false)
    private WorkflowType workflowType;
    @JoinColumn(name = "STATE", referencedColumnName = "STATE")
    @Enumerated(EnumType.STRING)
    @ManyToOne(optional = false)
    private WorkflowState state;
    @JoinColumn(name = "AUTHOR", referencedColumnName = "XA_NAME_ID")
    @ManyToOne
    private XaName author;
    @Column(name = "PUBLIC_VISIBLE", nullable = false)
    @Type(type="yes_no")
    private boolean publicVisible;
    @Transient
    protected List<WorkflowAuthority> workflowAuthorityList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "workflow")
    private List<WorkflowFacilityAuthority> workflowFacilityAuthorityList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "workflow")
    private List<WorkflowServiceGroupAuthority> workflowServiceGroupAuthorityList;

    [getter/setters removed]
}


Code:
package ca.triumf.mis.qms.workrequest.jpa;

import java.io.Serializable;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.Future;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
import org.hibernate.annotations.Type;

@Entity
@Table(name = "WR_REQUEST")
@DiscriminatorValue(value = "Work Request")
@PrimaryKeyJoinColumn(name = "ID")
@NamedQueries({
    @NamedQuery(name = "Request.findAll", query = "SELECT r FROM Request r ORDER BY r.id"),
    @NamedQuery(name = "Request.findAllWorkingRequestsByUser", query = "SELECT r FROM Request r " +
            "LEFT JOIN FETCH r.projectCharterSheet " +
            "WHERE r.state =  ca.triumf.mis.qms.workrequest.jpa.enums.WorkflowState.Working " +
            "AND r.requestor = :xaName " +
            "ORDER BY r.createTs DESC"),
    @NamedQuery(name = "Request.findAllSubmitPendingRequests", query = "SELECT r FROM Request r " +
            "LEFT JOIN FETCH r.projectCharterSheet " +
            "WHERE (r.state = ca.triumf.mis.qms.workrequest.jpa.enums.WorkflowState.Pending OR r.state = ca.triumf.mis.qms.workrequest.jpa.enums.WorkflowState.Approved) " +
            "AND r.requestor = :xaName " +
            "ORDER BY r.createTs DESC"),
    @NamedQuery(name = "Request.findAllPendingRequests", query = "SELECT r FROM Request r WHERE r.state = ca.triumf.mis.qms.workrequest.jpa.enums.WorkflowState.Pending ORDER BY r.createTs DESC"),
    @NamedQuery(name = "Request.findPendingCCSRequestsByActiveAuthority", query = "SELECT r FROM Request r " +
            "JOIN r.facilityList f " +
            "JOIN f.authorities a " +
            "LEFT JOIN FETCH r.projectCharterSheet " +
            "WHERE r.state = ca.triumf.mis.qms.workrequest.jpa.enums.WorkflowState.Pending " +
            "AND (r.changeToCommission = true AND r.ccsApproved=false) " +
            "AND :xaName MEMBER OF a.xaNameList " +
            "AND f.active = true " +
            "AND a.active = true " +
            "ORDER BY r.createTs DESC"),
    @NamedQuery(name = "Request.findPendingNonCCSRequestsByActiveAuthority", query = "SELECT r FROM Request r " +
            "JOIN r.serviceGroupList g " +
            "JOIN g.authorities a " +
            "LEFT JOIN FETCH r.projectCharterSheet " +
            "WHERE r.state = ca.triumf.mis.qms.workrequest.jpa.enums.WorkflowState.Pending " +
            "AND ((r.changeToCommission = true AND r.ccsApproved=true) OR r.changeToCommission = false) " +
            "AND :xaName MEMBER OF a.xaNameList " +
            "AND g.active = true " +
            "AND a.active = true " +
            "ORDER BY r.createTs DESC"),
    @NamedQuery(name = "Request.findById", query = "SELECT r FROM Request r WHERE r.id = :id"),
    @NamedQuery(name = "Request.findByTitle", query = "SELECT r FROM Request r WHERE r.title LIKE :title AND (r.state =  ca.triumf.mis.qms.workrequest.jpa.enums.WorkflowState.Pending " +
    "OR r.state = ca.triumf.mis.qms.workrequest.jpa.enums.WorkflowState.Approved " +
            "OR r.state = ca.triumf.mis.qms.workrequest.jpa.enums.WorkflowState.Closed " +
            "OR r.state =  ca.triumf.mis.qms.workrequest.jpa.enums.WorkflowState.Abandoned " +
            "OR (r.state =  ca.triumf.mis.qms.workrequest.jpa.enums.WorkflowState.Working AND r.publicVisible = true))"),
    @NamedQuery(name = "Request.findByCommitmentTrackingNumber", query = "SELECT r FROM Request r WHERE r.commitmentTrackingNumber LIKE :commitmentTrackingNumber "),
    @NamedQuery(name = "Request.findByRequestorAndPublicVisible", query = "SELECT r FROM Request r WHERE r.state = ca.triumf.mis.qms.workrequest.jpa.enums.WorkflowState.Working AND r.requestor =:xaName AND r.publicVisible = true"),
    @NamedQuery(name = "Request.findByWorkRequestNumber", query = "SELECT r FROM Request r WHERE r.workRequestNumber = :workRequestNumber"),
    @NamedQuery(name = "Request.findByProjectAccount", query = "SELECT r FROM Request r WHERE r.projectAccount = :projectAccount"),
    @NamedQuery(name = "Request.findByProjectSubAccount", query = "SELECT r FROM Request r WHERE r.projectSubAccount LIKE :projectSubAccount"),
    @NamedQuery(name = "Request.findByDateRequired", query = "SELECT r FROM Request r WHERE r.dateRequired = :dateRequired"),
    @NamedQuery(name = "Request.findBySummary", query = "SELECT r FROM Request r WHERE r.summary = :summary"),
    @NamedQuery(name = "Request.findByChangeToCommission", query = "SELECT r FROM Request r WHERE r.changeToCommission = :changeToCommission")})
public class Request extends Workflow implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @Column(name = "ID", nullable = false)
    private Integer id;
    @Column(name = "TITLE", length = 500)
    @Size(max=500, message ="Title can not exceed 500 letters")
    private String title;
    @Column(name = "COMMITMENT_TRACKING_NUMBER")
    @Size(max=128, message ="Commitment Tracking Number can not exceed 128 letters/digits")
    private String commitmentTrackingNumber;
    @Column(name = "WORK_REQUEST_NUMBER")
    private Integer workRequestNumber;
    @Column(name = "PROJECT_SUB_ACCOUNT")
    @Size(max=128, message ="Project sub account can not exceed 128 letters/digits")
    private String projectSubAccount;
    @Column(name = "DATE_REQUIRED")
    @Temporal(TemporalType.DATE)
    private Date dateRequired;
    @Column(name = "SUMMARY", length = 500)
    @Size(max=500, message ="Summary can not exceed 500 letters")
    private String summary;
    @Column(name = "CHANGE_TO_COMMISSION")
    @Type(type="yes_no")
    private boolean changeToCommission;
    @Column(name = "CCS_APPROVED")
    @Type(type="yes_no")
    private boolean ccsApproved;
    @Column(name = "PROJECT_ACCOUNT")
    private Integer projectAccount;
    @JoinTable(name = "WR_REQUEST_ENGINEERING_GROUP", joinColumns = {
        @JoinColumn(name = "REQUEST", referencedColumnName = "ID", nullable = false)}, inverseJoinColumns = {
        @JoinColumn(name = "ENGINEERING_GROUP", referencedColumnName = "ID", nullable = false)})
    @ManyToMany
    private List<ServiceGroup> serviceGroupList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "request", orphanRemoval = true)
    private List<Document> documentList;
    @JoinTable(name = "WR_REQUEST_FACILITY", joinColumns = {
        @JoinColumn(name = "ID", referencedColumnName = "ID", nullable = false)}, inverseJoinColumns = {
        @JoinColumn(name = "FACILITY", referencedColumnName = "ID", nullable = false)})
    @ManyToMany
    private List<Facility> facilityList;
    @JoinColumn(name = "ID", referencedColumnName = "ID", nullable = false, insertable = false, updatable = false)
    @OneToOne(optional = false)
    private Workflow workflow;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "request", orphanRemoval = true)
    private List<Deliverable> deliverableList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "request", orphanRemoval = true)
    private List<Hazard> hazardList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "request1")
    private List<QuestionRequestAnswer> questionRequestAnswerList;

    [getter/setters removed]


There are two other object hierarchies, but they are set up pretty similarly as this one.


Top
 Profile  
 
 Post subject: Re: Problem migrating from Eclipselink
PostPosted: Thu Jun 17, 2010 4:57 pm 
Newbie

Joined: Thu Jun 17, 2010 12:31 pm
Posts: 4
Ok, after a bit of a debug session (thanks Jason!), I resolved the problems. They were:

1) Mapping the discriminator column to a property in the class
2) Mapping the PK to a property in a class where it is already mapped in the parent class
3) I had a ManyToOne annotation on a @enumerated property - left over cruft from a refactoring

Nevertheless, the fact that these errors where hidden behind the obscure stacktrace above made it very difficult to resolve. Some room for improvement there.

Brian


Top
 Profile  
 
 Post subject: Re: Problem migrating from Eclipselink
PostPosted: Wed May 16, 2012 7:34 am 
Newbie

Joined: Wed May 16, 2012 7:31 am
Posts: 1
Thank you Brian for sharing your solution/problem causes!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.