Hibernate em RCP nao funciona

2 respostas
G

Boa tarde, estou elaborando um programa em padrao hibernate e quando vou puxar do banco para preencher uma tabela que fica em uma view da o seguinte erro

java.lang.NoClassDefFoundError: org/hibernate/Session
....

aqui está minha view

public class TableServerView extends ViewPart{
	public final static String ID = "br.com.md2net.gi.view.TableServerView";
ServerDAO dao = new ServerDAO();
	List<Server> items = dao.getServerList();
	
	private Table table;
	
	@Override
	public void createPartControl(Composite parent) {
			createTable(parent, new String[] {"Nome","Ip","Ambiente"});
	}

	public void createTable(Composite parent,String columns[]){
        table = new Table(parent,SWT.BORDER |SWT.MULTI | SWT.FULL_SELECTION);
        GridData tableData = new GridData(GridData.FILL_BOTH);
        table.setLayoutData(tableData);

        for(String s : columns){
            TableColumn cln = new TableColumn(table,SWT.LEFT);
            cln.setText(s);
            cln.pack();
        }
        
       fillTable();
        
        for(TableColumn c : table.getColumns()){
            c.pack();
        }
        
        table.setLinesVisible(true);
        table.setHeaderVisible(true);
        
    }
	
	 private void fillTable() {
	    	    	
	        for(Server s : items){
	        	TableItem item = new TableItem(table,SWT.NONE);
	        	item.setText(new String[]{s.getNome(),s.getIp(),s.getAmbiente().toString()});
	        }
	 }
	

	@Override
	public void setFocus() {
		// TODO Auto-generated method stub
		
	}

e aqui está minha classe DAO

public class ServerDAO {
	private SessionFactory sessionFactory;
	private Logger logger;
	
	public ServerDAO() {
		sessionFactory = new Configuration().configure().buildSessionFactory();
		PropertyConfigurator.configure("log4j.properties");
		logger = Logger.getLogger(ServerDAO.class);
	}
	
	public void insert(Server e){
		try{
			logger.info("Inserindo novo servidor " + e.toString());
			
			Session session = sessionFactory.getCurrentSession();
			session.beginTransaction();
		
			session.save(e);
		
			session.getTransaction().commit();
			sessionFactory.close();
			
			logger.info("Servidor inserido com sucesso.");
		}catch (Exception ex){
			logger.error("Não foi possível inserir um novo Servidor. Motivo:\n" + ex.getMessage());
		}
	}
	
	public Server getServer(int codigo){
		try{
			logger.info("Obtendo Servidor código " + codigo + " do banco de dados.");
			
			Session session = sessionFactory.getCurrentSession();
			session.beginTransaction();
			
			Server e = (Server) session.get(Server.class, codigo);
			
			sessionFactory.close();
			
			logger.info("Servidor obtido com sucesso.");
			
			return e;
		}catch (Exception ex){
			logger.error("Erro ao obter Servidor com código " + codigo + ". Motivo:\n" + ex.getMessage());
		}
			
		return null;
	}
	
	@SuppressWarnings("unchecked")
	public List<Server> getServerList(){
		try{
			logger.info("Obtendo a lista de Servidores do banco de dados.");
			
			Session session = sessionFactory.getCurrentSession();
			session.beginTransaction();
			
			List<Server> Servers = session.createCriteria(Server.class).list();
			
			sessionFactory.close();
			
			logger.info("Lista de Servidores obtida com sucesso.");
			
			return Servers;
		}catch (Exception e){
			logger.error("Não foi possível obter a lista de Servidores.\nMotivo: " + e.getMessage());
		}
		
		return null;
	}
	
	public void update(Server e){
		try{
			logger.info("Atualizando dados do Servidor: " + e.toString());
			
			Session session = sessionFactory.getCurrentSession();
			session.beginTransaction();
		
			session.update(e);
		
			session.getTransaction().commit();
			sessionFactory.close();
			
			logger.info("Atualização do Servidor realizada com sucesso.");
		}catch (Exception ex){
			logger.error("Não foi possível atualizar o Servidor " + e.toString() + ". Motivo:\n" + ex.getMessage());
		}
	}
	
	public void delete(Server e){
		try{
			logger.info("Excluindo Servidor: " + e.toString());
			
			Session session = sessionFactory.getCurrentSession();
			session.beginTransaction();
		
			session.delete(e);
		
			session.getTransaction().commit();
			sessionFactory.close();
			
			logger.info("Exclusão do Servidor efetuada com sucesso.");
		}catch (Exception ex){
			logger.error("Não foi possível excluir o Servidor " + e.toString() + ". Motivo:\n" + ex.getMessage());
		}
	}
}

2 Respostas

Ataxexe

Talvez as bibliotecas do hibernate não estão marcadas para exportação. A melhor prática é criar um plugin com as bibliotecas e adicionar ao seu aplicativo RCP.

G

cara era exatamente isso ^^ auhahuauha eu fui ver agora =0
mto obrigado

mas agora estou com outro problema se alguem puder me ajudar, é o seguinte fiz uma tela de cadastro de servidor e cada servidor tem um ambiente, dai eu to fazendo buscando esses ambientes em um combo porem quando vou buscar do combo nao consigo setar no server pois o ambiente é um object.

minha classe server

public class Server {
	private int codigo;
	private Enviroment ambiente;
	private String ip;
	private String nome;
	private Collection<Application> aplicacoes;
	
	public Server() {

	}

	public Server(Enviroment ambiente, String ip, String nome) {
		super();
		this.ambiente = ambiente;
		this.ip = ip;
		this.nome = nome;
	}

	public Server(int codigo, Enviroment ambiente, String ip, String nome,
			Collection<Application> aplicacoes) {
		super();
		this.codigo = codigo;
		this.ambiente = ambiente;
		this.ip = ip;
		this.nome = nome;
		this.aplicacoes = aplicacoes;
	}

	public Collection<Application> getAplicacoes() {
		return aplicacoes;
	}

	public void setAplicacoes(Collection<Application> aplicacoes) {
		this.aplicacoes = aplicacoes;
	}

	public int getCodigo() {
		return codigo;
	}

	public void setCodigo(int codigo) {
		this.codigo = codigo;
	}

	public Enviroment getAmbiente() {
		return ambiente;
	}

	public void setAmbiente(Enviroment ambiente) {
		this.ambiente = ambiente;
	}

	public String getIp() {
		return ip;
	}

	public void setIp(String ip) {
		this.ip = ip;
	}

	public String getNome() {
		return nome;
	}

	public void setNome(String nome) {
		this.nome = nome;
	}
	
	@Override
	public String toString() {
		return this.ip;
	}
}

minha dialog em que eu cadastro o server

EnviromentDAO dao = new EnviromentDAO();
	
	List<Enviroment> items = dao.getEnviromentList();
	
	private Text ipText;
	private Text nameText;
	private Text descriptionText;
	private Combo enviromentCombo;
	
	public RegisterServerDialog(Shell parentShell) {
		super(parentShell);
		this.setBlockOnOpen(true);
	}
	
	@Override
	protected void configureShell(Shell newShell) {
		super.configureShell(newShell);
		newShell.setText("Cadastro de Sistema");
		
	}
		
	@Override
	protected Control createDialogArea(Composite parent) {
		Composite composite = new Composite(parent,SWT.NONE);
		composite.setLayoutData(new GridData(GridData.FILL_BOTH));
		GridLayout layout = new GridLayout(2, false);
		composite.setLayout(layout);
		layout.marginLeft =20;
		layout.numColumns = 2;
		layout.horizontalSpacing = 30;
		GridData d = new GridData();
		d.widthHint=200;
		
		Label nameLabel = new Label(composite, SWT.NONE);
		nameLabel.setText("Nome servidor ");
		nameText = new Text(composite,SWT.BORDER);
		nameText.setLayoutData(d);
		
		Label ipLabel = new Label(composite, SWT.NONE);
		ipLabel.setText("Ip do servidor ");
		ipText = new Text(composite,SWT.BORDER);
		ipText.setLayoutData(d);
		
		Label enviromentLabel = new Label(composite,SWT.NONE);
		enviromentLabel.setText("Ambiente do servidor ");
		enviromentCombo = new Combo(composite,SWT.DROP_DOWN | SWT.READ_ONLY);

		for(Enviroment e : items){
			enviromentCombo.add(e.getTipo());
		}
		Label descriptionLabel = new Label(composite,SWT.NONE);
		descriptionLabel.setText("Descrição do servidor ");
		
		GridData e = new GridData();
		e.widthHint=200;
		e.heightHint = 50;
		
		descriptionText = new Text(composite,SWT.MULTI | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL);
		descriptionText.setLayoutData(e);
		
		return super.createDialogArea(parent);
	}
	
	@Override
	protected void okPressed() {
		ServerDAO server = new ServerDAO();
		Server e = new Server();
		int c = enviromentCombo.getSelectionIndex();
		Enviroment env = dao.getEnviroment(enviromentCombo.getItem(c));
		e.setNome(nameText.getText());
		e.setIp(ipText.getText());
		e.setAmbiente(env);
		server.insert(e);
				
	}
Criado 14 de outubro de 2009
Ultima resposta 14 de out. de 2009
Respostas 2
Participantes 2