-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: ClassCastException hibernate 3 annotations using inheritance
PostPosted: Fri Mar 18, 2005 3:36 pm 
Newbie

Joined: Thu Mar 17, 2005 12:10 am
Posts: 8
I get the following exception when I tried to use annotations with joined subclass inheritance:

Code:
Exception in thread "main" java.lang.ClassCastException: org.hibernate.mapping.JoinedSubclass
   at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:679)
   at org.hibernate.cfg.AnnotationBinder.processElementsOfAClass(AnnotationBinder.java:532)
   at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:382)
   at org.hibernate.cfg.AnnotationConfiguration.addAnnotatedClass(AnnotationConfiguration.java:44)
   at com.poss.saleswiz.ant.HibernateSchemaExporter.export(HibernateSchemaExporter.java:25)
   at com.poss.saleswiz.ant.HibernateSchemaExporter.main(HibernateSchemaExporter.java:52)


Here is my class structure

base class Employee with subclass Region manager.

Here's the Employee class:

Code:
package com.poss.saleswiz.framework.businessobject;

import javax.ejb.Column;
import javax.ejb.Entity;
import javax.ejb.Id;
import javax.ejb.Inheritance;
import javax.ejb.InheritanceType;
import javax.ejb.Table;

@Entity
@Table(name = "swiz_employee")
@Inheritance(strategy = InheritanceType.JOINED)
public class Employee {

    private String code;
    private String firstName;
    private String middleName;
    private String lastName;
   
    /**
     * @return Returns the code.
     */
    @Id
    @Column(name = "employee_code", nullable = false)
    public String getCode() {
        return code;
    }
   
    /**
     * @param inCode The code to set.
     */
    public void setCode(String inCode) {
        code = inCode;
    }
   
    /**
     * @return Returns the firstName.
     */
    @Column(name = "first_name", nullable = false)
    public String getFirstName() {
        return firstName;
    }
   
    /**
     * @param inFirstName The firstName to set.
     */
    public void setFirstName(String inFirstName) {
        firstName = inFirstName;
    }
   
    /**
     * @return Returns the lastName.
     */
    @Column(name = "last_name", nullable = false)
    public String getLastName() {
        return lastName;
    }
   
    /**
     * @param inLastName The lastName to set.
     */
    public void setLastName(String inLastName) {
        lastName = inLastName;
    }
   
    /**
     * @return Returns the middleName.
     */
    @Column(name = "middle_name")
    public String getMiddleName() {
        return middleName;
    }
   
    /**
     * @param inMiddleName The middleName to set.
     */
    public void setMiddleName(String inMiddleName) {
        middleName = inMiddleName;
    }
   
}


Here's the RegionManager class:

Code:
package com.poss.saleswiz.framework.businessobject;

import javax.ejb.CascadeType;
import javax.ejb.Column;
import javax.ejb.Entity;
import javax.ejb.GeneratorType;
import javax.ejb.Id;
import javax.ejb.Inheritance;
import javax.ejb.InheritanceJoinColumn;
import javax.ejb.InheritanceType;
import javax.ejb.JoinColumn;
import javax.ejb.ManyToOne;
import javax.ejb.Table;

@Entity
@Table(name = "swiz_region_manager")
@Inheritance(strategy = InheritanceType.JOINED)
@InheritanceJoinColumn(name = "employee_code")
public class RegionManager extends Employee {
   
    private Integer id;
    private Region region;
   
    /**
     * @return Returns the id.
     */   
    @Column(name = "assoc_id", nullable = false)
    @Id(generate = GeneratorType.AUTO)
    public Integer getId() {
        return id;
    }
   
    /**
     * @param inId The id to set.
     */
    public void setId(Integer inId) {
        id = inId;
    }
   
    /**
     * @return Returns the region.
     */
    @ManyToOne(cascade = CascadeType.ALL)
    @JoinColumn(name = "region_id")
    public Region getRegion() {
        return region;
    }
   
    /**
     * @param inRegion The region to set.
     */
    public void setRegion(Region inRegion) {
        region = inRegion;
    }

}


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 25, 2005 12:33 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Please wrap this test case ina zip file and post it to JIRA.

_________________
Emmanuel


Top
 Profile  
 
 Post subject: ejb 3 annotations, joined inheritance and ClassCastException
PostPosted: Thu Aug 04, 2005 11:03 am 
Newbie

Joined: Wed Jan 07, 2004 12:02 pm
Posts: 15
Location: Herne, Germany
It seems that I face the same problem. I couldn't find a JIRA issue for this and so I wonder if there is a solution for the problem available already. Or is a new JIRA entry still necessary?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 04, 2005 1:21 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
This is actually not a bug, you cannot use @Id on the subclasses. The new version raise a nicer exception

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 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.