Log4J - Problema com Hibernate Exception ao persistir um objeto

2 respostas
mausexdd

log4j:WARN No appenders could be found for logger (org.hibernate.cfg.annotations.Version). log4j:WARN Please initialize the log4j system properly. Exception in thread "main" java.lang.NullPointerException at br.com.syscomm.mauricio.persistencia.fabricante.FabricanteDAOHibernate.salvarOuAlterar(FabricanteDAOHibernate.java:32) at teste.main(teste.java:66)

Pessoal ao tentar persistir minha classe estou tento este estranho erro . Já verifiquei as libs me parece estar tudo ok , alguém já passou por isso?

Objeto

Fabricante fab = new Fabricante("AMBEV", "12345678");
FabricanteDAOHibernate fabDAO = new FabricanteDAOHibernate();
fabDAO.salvarOuAlterar(fab);

Método persistencia

public void salvarOuAlterar(Fabricante fabSalvarAlterar) {
		try {
			session = HibernateUtil.getSession();
			tx = session.beginTransaction();
			session.saveOrUpdate(fabSalvarAlterar);
			tx.commit();
		} catch (Exception e) {
			if (tx != null) {
				try {
					tx.rollback();
				} catch (HibernateException he) {
					he.getCause();
					he.getMessage();
				}
			}
		} finally {
			try {
				session.close();
			} catch (HibernateException he) {
				throw he;
			}
		}

	}

//HibernateUtil

private static SessionFactory sessionFactory;

	public static SessionFactory getSessionFactory() {
		if (sessionFactory == null) {
			AnnotationConfiguration cfg = new AnnotationConfiguration();
			Configuration config = cfg.configure("hibernate.cfg.xml");
			sessionFactory = config.buildSessionFactory();
		}
		return sessionFactory;
	}

	public static Session getSession() {
		Session sessao = getSessionFactory().openSession();
		return sessao;
	}

o estranho é que também retorna como nullPointerEx .

Alguma sugestão?

2 Respostas

luxu

vc tem algum construtor na classe Fabricante q recebe 2 parâmetros?

mausexdd
@Entity
@Table(name = "TAB_FABRICANTE")
@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
public class Fabricante {
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "ID_FABRICANTE")
	private Integer id;
	@Column(name = "PRODUTOS_FABRICANTE")
	@OneToMany(mappedBy = "fabricante", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	private List<Produto> listaProdutos;
	@Column
	@OneToMany(mappedBy = "fabricante", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
	private List<Fornecedor> listaFornecedores;
    @OneToOne(cascade = CascadeType.ALL, optional = false, fetch = FetchType.LAZY)
	@PrimaryKeyJoinColumn
	@Column(name = "END_FABRICANTE")
	private Endereco enderecoFabricante;

//Meu Construtor que recebe 2 parametrôs

public Fabricante(String nome, String cnpj) {
		super(nome, cnpj);
		// TODO Auto-generated constructor stub
	}
Criado 2 de abril de 2012
Ultima resposta 3 de abr. de 2012
Respostas 2
Participantes 2