You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by Gerard Pretorius <g....@gmail.com> on 2007/11/27 20:56:44 UTC

General EJB3: Problem persisting subclass X when adding a reference to another entity mapped to X's superclass.

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

Re: General EJB3: Problem persisting subclass X when adding a reference to another entity mapped to X's superclass.

Posted by Jacek Laskowski <ja...@laskowski.net.pl>.
On Nov 27, 2007 10:18 PM, Gerard Pretorius <g....@gmail.com> wrote:

> It works perfectly now. False alarm.

Great. I like such errors the most ;-) Keep asking whenever you find
an issue even if you think it could eventually be a false alarm. It
lets us know there're real end users out there...

Jacek

-- 
Jacek Laskowski
http://www.JacekLaskowski.pl

Re: General EJB3: Problem persisting subclass X when adding a reference to another entity mapped to X's superclass.

Posted by Gerard Pretorius <g....@gmail.com>.
On Tuesday 27 November 2007 22:48:48 Jacek Laskowski wrote:
> On Nov 27, 2007 8:56 PM, Gerard Pretorius <g....@gmail.com> wrote:
> > 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.
>
> Nothing sprung to my mind so before I decide to reproduce it for
> myself, could you send the entire stack trace of the exception.
>
> Jacek

Hi Jacek

I committed my source to svn, did a fresh checkout, manually cleaned my tomcat 
webapps/ folder and I'm no longer having the problem. Even though I was doing 
an  'mvn clean install', something must have been causing the problem, 
because I'm using exactly the same code.

It works perfectly now. False alarm.

Thanks,
Gerard

Re: General EJB3: Problem persisting subclass X when adding a reference to another entity mapped to X's superclass.

Posted by Jacek Laskowski <ja...@laskowski.net.pl>.
On Nov 27, 2007 8:56 PM, Gerard Pretorius <g....@gmail.com> wrote:

> 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.

Nothing sprung to my mind so before I decide to reproduce it for
myself, could you send the entire stack trace of the exception.

Jacek

-- 
Jacek Laskowski
http://www.JacekLaskowski.pl