Hibernate pal

4 respostas
V

Pessoal criei um projeto web usando hibernate e criei meu xml e coloquei dentro da minha pasta src do projeto
entretanto algumas pessoas me falaram que esse arquivo precisa estár dentro do web.xml para funcionar. Mas
esse projeto eu estou rodando com 1 main e pedindo pra ele rode como java aplication. O que meu código faz
é um simples insert. Entretanto ele aparece essas informações e não insere nada.

4 Respostas

marcoamv3000

Você poderia postar os códigos para podermos ver o que realmente esta acontecendo e coloque também a mensagem do erro que o console mostra para você.

V

A mensagem de erro é mostruosa e essa aqui.

0 [main] INFO org.hibernate.cfg.annotations.Version - Hibernate Annotations 3.5.6-Final

16 [main] INFO org.hibernate.cfg.Environment - Hibernate 3.5.6-Final

16 [main] INFO org.hibernate.cfg.Environment - hibernate.properties not found

16 [main] INFO org.hibernate.cfg.Environment - Bytecode provider name : javassist

16 [main] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling

78 [main] INFO org.hibernate.annotations.common.Version - Hibernate Commons Annotations 3.2.0.Final

94 [main] INFO org.hibernate.cfg.Configuration - configuring from resource: /hibernate.cfg.xml

94 [main] INFO org.hibernate.cfg.Configuration - Configuration resource: /hibernate.cfg.xml

140 [main] INFO org.hibernate.cfg.Configuration - Configured SessionFactory: null

156 [main] INFO org.hibernate.cfg.search.HibernateSearchEventListenerRegister - Unable to find org.hibernate.search.event.FullTextIndexEventListener on the classpath. Hibernate Search is not enabled.

187 [main] INFO org.hibernate.cfg.AnnotationBinder - Binding entity from annotated class: br.com.formulariopesquisa.negocio.basicas.FuncionarioTeste

218 [main] INFO org.hibernate.cfg.annotations.EntityBinder - Bind entity br.com.formulariopesquisa.negocio.basicas.FuncionarioTeste on table funcionarios

250 [main] INFO org.hibernate.cfg.AnnotationConfiguration - Hibernate Validator not found: ignoring

281 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - Using Hibernate built-in connection pool (not for production use!)

281 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - Hibernate connection pool size: 20

281 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - autocommit mode: false

296 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - using driver: org.postgresql.Driver at URL: jdbc:postgresql://localhost:5432/pesquisa

296 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - connection properties: {user=postgres, password=****}

343 [main] INFO org.hibernate.cfg.SettingsFactory - RDBMS: PostgreSQL, version: 8.4.6

343 [main] INFO org.hibernate.cfg.SettingsFactory - JDBC driver: PostgreSQL Native Driver, version: PostgreSQL 9.0 JDBC4 (build 801)

359 [main] INFO org.hibernate.dialect.Dialect - Using dialect: org.hibernate.dialect.PostgreSQLDialect

359 [main] INFO org.hibernate.engine.jdbc.JdbcSupportLoader - Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException

359 [main] INFO org.hibernate.transaction.TransactionFactoryFactory - Using default transaction strategy (direct JDBC transactions)

374 [main] INFO org.hibernate.transaction.TransactionManagerLookupFactory - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)

374 [main] INFO org.hibernate.cfg.SettingsFactory - Automatic flush during beforeCompletion(): disabled

374 [main] INFO org.hibernate.cfg.SettingsFactory - Automatic session close at end of transaction: disabled

374 [main] INFO org.hibernate.cfg.SettingsFactory - JDBC batch size: 15

374 [main] INFO org.hibernate.cfg.SettingsFactory - JDBC batch updates for versioned data: disabled

374 [main] INFO org.hibernate.cfg.SettingsFactory - Scrollable result sets: enabled

374 [main] INFO org.hibernate.cfg.SettingsFactory - JDBC3 getGeneratedKeys(): enabled

374 [main] INFO org.hibernate.cfg.SettingsFactory - Connection release mode: auto

374 [main] INFO org.hibernate.cfg.SettingsFactory - Default batch fetch size: 1

374 [main] INFO org.hibernate.cfg.SettingsFactory - Generate SQL with comments: disabled

374 [main] INFO org.hibernate.cfg.SettingsFactory - Order SQL updates by primary key: disabled

374 [main] INFO org.hibernate.cfg.SettingsFactory - Order SQL inserts for batching: disabled

374 [main] INFO org.hibernate.cfg.SettingsFactory - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory

374 [main] INFO org.hibernate.hql.ast.ASTQueryTranslatorFactory - Using ASTQueryTranslatorFactory

374 [main] INFO org.hibernate.cfg.SettingsFactory - Query language substitutions: {}

374 [main] INFO org.hibernate.cfg.SettingsFactory - JPA-QL strict compliance: disabled

374 [main] INFO org.hibernate.cfg.SettingsFactory - Second-level cache: enabled

374 [main] INFO org.hibernate.cfg.SettingsFactory - Query cache: disabled

374 [main] INFO org.hibernate.cfg.SettingsFactory - Cache region factory : org.hibernate.cache.impl.NoCachingRegionFactory

374 [main] INFO org.hibernate.cfg.SettingsFactory - Optimize cache for minimal puts: disabled

374 [main] INFO org.hibernate.cfg.SettingsFactory - Structured second-level cache entries: disabled

374 [main] INFO org.hibernate.cfg.SettingsFactory - Statistics: disabled

374 [main] INFO org.hibernate.cfg.SettingsFactory - Deleted entity synthetic identifier rollback: disabled

374 [main] INFO org.hibernate.cfg.SettingsFactory - Default entity-mode: pojo

374 [main] INFO org.hibernate.cfg.SettingsFactory - Named query checking : enabled

374 [main] INFO org.hibernate.cfg.SettingsFactory - Check Nullability in Core (should be disabled when Bean Validation is on): enabled

390 [main] INFO org.hibernate.impl.SessionFactoryImpl - building session factory

515 [main] INFO org.hibernate.impl.SessionFactoryObjectFactory - Not binding factory to JNDI, no JNDI name configured
V

Código responsável por gerênciar minha sessão

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Configuration;



public class CreateSessionsFactory {

	private static SessionFactory sessionfactory;

	private CreateSessionsFactory() {

		inti();
	}

	private static void inti() {

		Configuration cfg = new AnnotationConfiguration();
		cfg.configure();
		sessionfactory = cfg.buildSessionFactory();

	}

	private static SessionFactory getSessionFactory() {

		if (sessionfactory == null) {
			inti();
		}
		return sessionfactory;
	}

	public static Session openSession() {

		Session sess = getSessionFactory().openSession();
		return sess;

	}
}
V

Xml de configuração ele está dentro da pasta src do meu projeto.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
		"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
		"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
	<session-factory >
		<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
		<property name="hibernate.connection.password">postgres</property>
		<property name="hibernate.connection.username">postgres</property>
		<property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/pesquisa</property>
		<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
	
	<!-- mapping classes --> 	
	<mapping class= "br.com.formulariopesquisa.negocio.basicas.FuncionarioTeste"/>
	
	</session-factory>
</hibernate-configuration>

E aqui em baixo a classe que persiste meu dados

package br.com.formulariopesquisa.persistencia;

import br.com.formulariopesquisa.negocio.basicas.FuncionarioTeste;
import br.com.formulariopesquisa.persistencia.CreateSessionsFactory;
import org.hibernate.Session;

public class RepositorioFuncionario {

	public RepositorioFuncionario() {

	}

	public void inserirFuncionario(FuncionarioTeste f) {

		Session session = CreateSessionsFactory.openSession();
		session.save(f);
		session.close();

	}

}
Criado 24 de janeiro de 2011
Ultima resposta 24 de jan. de 2011
Respostas 4
Participantes 2