Hi

I've been using OpenEjb 3 for approximately 2 months now, and its great. The 
last time I worked with EJBs, it was EJB1 in 2001. EJB3 is great, but I'm 
still learning how to use it.

I'm having the following problem, with Inheritance.

I have an abstract class, named Project which has a OneToMany relationship 
with another class, FinancialPeriod. I am extending Project, and want to use 
a concrete subclass named PRProject. The basic class structure follows below:

@Entity
@Table(name = "PROJECT")
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorColumn(name = "PROJ_TYPE")
@DiscriminatorValue("Project")
@NamedQuery(name = "Project.findAll", query = "select p from Project p")
//public abstract class Project implements Serializable {
public class Project implements Serializable {

        @OneToMany(mappedBy = "project", cascade = CascadeType.ALL)
        protected List<FinancialPeriod> financialPeriods;
}

One subclass looks like this:

@Entity(name="PRProject")
@DiscriminatorValue("PRProject")
@PrimaryKeyJoinColumns({ @PrimaryKeyJoinColumn(name="ID", 
referencedColumnName="ID") })
@NamedQuery(name = "PRProject.findAll", query = "select p from PRProject p")

public class PRProject extends Project{
 // nothing noteworthy to display here (or should there be?)
}

The FinancialPeriod class looks as follows:

@Entity
@NamedQueries( {
                @NamedQuery(name = "FinancialPeriod.findAll", query = "select o 
from 
FinancialPeriod o"),
                @NamedQuery(name = "FinancialPeriod.findById", query = "select 
o from 
FinancialPeriod o where o.id = :id") })
@Table(name = "FINANCIALPERIOD")
public class FinancialPeriod implements Serializable {

        @ManyToOne(cascade = CascadeType.MERGE)
        @JoinColumn(name = "PROJECT_ID", referencedColumnName = "ID")
        protected Project project; 

}

What I am trying to do is this:       

        PRProject prProject = new PRProject("PR Project");
        prProject.setCluster(capeCluster);
        prProject.setDescription("blah blah blah");

        FinancialPeriod finp= new FinancialPeriod("2005-2007");
        prProject.addFinancialPeriod(finp);

        projectBean.persistEntity(prProject);

This gives a java.lang.NoClassDefFoundError if I use the subclass, but saves 
perfectly if I use a concrete instance of the superclass. The subclass is 
persisted if I don't add a reference to the FinancialPeriod. 

Can anyone point me in the right direction? I haven't been able to find 
anything using Google.

Thanks,
Gerard

Reply via email to