[jboss-dev-forums] [Design of Persistence on JBoss] - cannot instatiate abstract class

jflf83 do-not-reply at jboss.com
Thu Jun 21 13:18:53 EDT 2007


Hello, I have problems when a I try to list the elements of an abstract class. the exceptions is:

Caused by: javax.ejb.EJBTransactionRolledbackException: javax.persistence.Persis
tenceException: org.hibernate.InstantiationException: Cannot instantiate abstrac
t class or interface: X

this problem happens with some elements of X, not with all elements

import java.util.Date;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.ManyToOne;
import javax.persistence.Transient;


@Entity
@Inheritance(strategy = InheritanceType.JOINED)
public abstract class X 
{
	public static final String SEM_ELEMENTO = " - ";
	
	private long id;

	private Date dataMovimentacao;


	private Date dataMovimentacaoSistema;

	private double quantidade;
	
	private long numeroMovimento;
	
	private String loginUsuario;
	
	private LinhaDeEstoque linhaDeEstoque = null;
	
	public X()
	{
		
	}
	
	public X(double consumoFinanceiro, Setor setor)
	{
		
	}

   public Date getDataMovimentacaoSistema()
	{
		return dataMovimentacaoSistema;
	}

	public void setDataMovimentacaoSistema(Date dataMovimentacaoSistema)
	{
		this.dataMovimentacaoSistema = dataMovimentacaoSistema;
	}

	public String getLoginUsuario() 
	{
		return loginUsuario;
	}

	public void setLoginUsuario(String loginUsuario)
	{
		this.loginUsuario = loginUsuario;
	}

	public long getNumeroMovimento()
	{
		return numeroMovimento;
	}

	public void setNumeroMovimento(long numeroMovimento) 
	{
		this.numeroMovimento = numeroMovimento;
	}

	public Date getDataMovimentacao() {
		return dataMovimentacao;
	}

	public void setDataMovimentacao(Date dataEntrada) {
		this.dataMovimentacao = dataEntrada;
	}

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	public long getId() {
		return id;
	}

	public void setId(long id)
	{
		this.id = id;
	}


	public double getQuantidade()
	{
		return quantidade;
	}

	public void setQuantidade(double quantidade)
	{
		this.quantidade = quantidade;
	}

	@ManyToOne
	public LinhaDeEstoque getLinhaDeEstoque()
	{
		return linhaDeEstoque;
	}

	public void setLinhaDeEstoque(LinhaDeEstoque linhaDeEstoque)
	{
		this.linhaDeEstoque = linhaDeEstoque;
	}
	
	@Transient
	public abstract String getTipoMovimentacao();
	
	@Transient
	public abstract String getValorMovimentacao();
	
	@Transient
	public abstract String getNumeroNotaFiscal();
	
	@Transient 
	public abstract double getValorEntrada();
	
	@Transient
	public abstract Object getSetor();
	@Transient
	public abstract double getConsumoFinanceiro();

}



this is the code of my classes

import javax.persistence.Entity;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;

@Entity
public abstract class Y extends X{

	public Y() 
	{
		super();
	}

	public Y(double consumoFinanceiro, Setor setor) 
	{
		super(consumoFinanceiro, setor);
	}

	

}

import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.Transient;

@Entity
public class Z extends X 
{
	public static final String ENTRADA = "Entrada";	

	private String numeroNotaFiscal;
	
	private Fornecedor fornecedor;
	
	private double valorEntrada;
	
	private String codigoFornecedor;
	

	public double getValorEntrada() { 
		return valorEntrada;
	}

	public void setValorEntrada(double valorEntrada) {
		this.valorEntrada = valorEntrada;
	}

	@Override
	public String getNumeroNotaFiscal()
	{
		return numeroNotaFiscal;
	}
	
	public void setNumeroNotaFiscal(String numeroNotaFiscal) 
	{
		this.numeroNotaFiscal = numeroNotaFiscal;
	}

	public void setFornecedor(Fornecedor fornecedor)
	{
		this.fornecedor = fornecedor;
	}

	@ManyToOne
	public Fornecedor getFornecedor()
	{
		return fornecedor;
	}

	public String getCodigoFornecedor() {
		return codigoFornecedor; 
	}

	public void setCodigoFornecedor(String codigoFornecedor) {
		this.codigoFornecedor = codigoFornecedor;
	}
	
	@Override
	@Transient
	public String getTipoMovimentacao() 
	{
		return ENTRADA;
	}
	
	@Override
	@Transient
	public String getValorMovimentacao()
	{
		return SEM_ELEMENTO;
	}

	@Override
	@Transient
	public Object getSetor()
	{
		return " - ";
	}
	
	@Override
	@Transient
	public double getConsumoFinanceiro() {
		// TODO Auto-generated method stub
		return 0;
	}
}

Someone can help me?
Thank you




View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4056606#4056606

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4056606



More information about the jboss-dev-forums mailing list