Hibernate não funciona

15 respostas
E

Ola pessoal, venho mais uma vez pedir ajuda de vocês, semana passada abrir um forum com uma dúvida mais não resolveram meu problema espero que neste novo tópico me ajudem,
Primeiramente quero agradecer a todos que vem me ajudando sempre aqui.

bom mais vamos diretamente ao assunto, é o seguinte, estou tentando fazer um crud simples com hibernate via xml para ligaar as tabelas etc…

porem não está funcionando , vou colar todos meus arquivos aqui

Classe de Teste

package Negocio;

import Persistencia.FornecedorDAO;

public class Teste {

	public static void main(String[] args) {
		Fornecedor f = new Fornecedor();
		f.setNome("pedraummmmmm");
		FornecedorDAO fDAO = new FornecedorDAO();
		fDAO.insert(f);
		
			
		}
		

		
	}

Arquivo hibernate.properties

hibernate.dialect = org.hibernate.dialect.MySQLDialect
hibernate.connection.driver_class = com.mysql.jdbc.Driver
hibernate.connection.url = jdbc:mysql://localhost:3306/controleestoque
hibernate.connection.username = root
hibernate.connection.password =

hibernate.show_sql = true

hibernate.format_sql = true

Arquivo xml Fornecedor.hbm.xml

<?xml version="1.0" encoding="UTF-8"?>   
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">   
<hibernate-mapping>   
    <class name="Negocio.Fornecedor" table="fornecedor">   
        <id name="id" >
          <generator class="increment"/>    
        </id> 
    </class>   
</hibernate-mapping>

Classe Fornecedor

package Negocio;

public class Fornecedor {
	
	private int id;
	public int getId() {
		return id;
	}

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

	private String nome;

	public Fornecedor() {
	}

	public Fornecedor(String nome) {
		this.nome = nome;
	}

	public String getNome() {
		return nome;
	}

	public void setNome(String nome) {
		this.nome = nome;
	}
}

Classe FornecedorDAO

package Persistencia;

import java.util.List;

import org.hibernate.Session;


import Negocio.Fornecedor;

public class FornecedorDAO implements DAO<Fornecedor> {
	private Session session;
	
	public FornecedorDAO(){
		session = FabricaConexao.getSession();
	}
	
	
	@Override
	public void insert(Fornecedor forn) {
		session.save(forn);
	}
	
	
	@Override
	public void update(Fornecedor obj) {
		session.update(obj);
		session.flush();
	}

	@Override
	public void delete(Fornecedor obj) {
		session.delete(obj);
		session.flush();
	}


	@Override
	public List<Fornecedor> read() {
		return session.createCriteria(Fornecedor.class).list();
	}
}

Interface DAO

package Persistencia;

import java.util.List;

public interface DAO <T>{
	
	public void insert(T obj);
	public void update(T obj);
	public void delete(T obj);
	public List<T> read();
	
}

Classe FabricaConexao

package Persistencia;

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



public class FabricaConexao {

	private static SessionFactory factory;
	
	public static Session getSession(){
		Configuration  cfg = new Configuration();
		cfg.addClass(Negocio.Fornecedor.class);
		factory = cfg.buildSessionFactory();
		return factory.openSession();
	}
	
	
}

Quando eu executo está aplicação aparece o seguinte no console

12:18:44,265  INFO Environment:543 - Hibernate 3.3.0.SP1
12:18:44,296  INFO Environment:561 - loaded properties from resource hibernate.properties: {hibernate.connection.username=root, hibernate.connection.password=****, hibernate.dialect=org.hibernate.dialect.MySQLDialect, hibernate.show_sql=true, hibernate.connection.url=jdbc:mysql://localhost:3306/controleestoque, hibernate.bytecode.use_reflection_optimizer=false, hibernate.connection.driver_class=com.mysql.jdbc.Driver, hibernate.format_sql=true}
12:18:44,312  INFO Environment:709 - Bytecode provider name : javassist
12:18:44,359  INFO Environment:627 - using JDK 1.4 java.sql.Timestamp handling
12:18:45,109  INFO Configuration:618 - Reading mappings from resource: Negocio/Fornecedor.hbm.xml
12:18:45,109  INFO Configuration:563 - Reading mappings from resource: Negocio/Fornecedor.hbm.xml
12:18:46,046 DEBUG DTDEntityResolver:64 - trying to resolve system-id [http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd]
12:18:46,046 DEBUG DTDEntityResolver:66 - recognized hibernate namespace; attempting to resolve on classpath under org/hibernate/
12:18:46,046 DEBUG DTDEntityResolver:76 - located [http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd] in classpath
12:18:46,796  INFO HbmBinder:322 - Mapping class: Negocio.Fornecedor -> fornecedor
12:18:46,875 DEBUG HbmBinder:1289 - Mapped property: id -> id
12:18:46,937 DEBUG Configuration:1318 - Preparing to build session factory with filters : {}
12:18:46,953 DEBUG Configuration:1153 - processing extends queue
12:18:46,968 DEBUG Configuration:1157 - processing collection mappings
12:18:46,968 DEBUG Configuration:1168 - processing native query and ResultSetMapping mappings
12:18:46,968 DEBUG Configuration:1176 - processing association property references
12:18:46,968 DEBUG Configuration:1198 - processing foreign key constraints
12:18:47,281  INFO DriverManagerConnectionProvider:64 - Using Hibernate built-in connection pool (not for production use!)
12:18:47,281  INFO DriverManagerConnectionProvider:65 - Hibernate connection pool size: 20
12:18:47,281  INFO DriverManagerConnectionProvider:68 - autocommit mode: false
12:18:47,359  INFO DriverManagerConnectionProvider:103 - using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost:3306/controleestoque
12:18:47,359  INFO DriverManagerConnectionProvider:106 - connection properties: {user=root, password=}
12:18:47,359 DEBUG DriverManagerConnectionProvider:132 - opening new JDBC connection
12:18:48,375 DEBUG DriverManagerConnectionProvider:138 - created connection to: jdbc:mysql://localhost:3306/controleestoque, Isolation Level: 4
12:18:48,375  INFO SettingsFactory:116 - RDBMS: MySQL, version: 5.1.44-community
12:18:48,375  INFO SettingsFactory:117 - JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-5.1.12 ( Revision: ${bzr.revision-id} )
12:18:48,500  INFO Dialect:175 - Using dialect: org.hibernate.dialect.MySQLDialect
12:18:48,531  INFO TransactionFactoryFactory:59 - Using default transaction strategy (direct JDBC transactions)
12:18:48,546  INFO TransactionManagerLookupFactory:80 - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
12:18:48,546  INFO SettingsFactory:170 - Automatic flush during beforeCompletion(): disabled
12:18:48,546  INFO SettingsFactory:174 - Automatic session close at end of transaction: disabled
12:18:48,546  INFO SettingsFactory:181 - JDBC batch size: 15
12:18:48,546  INFO SettingsFactory:184 - JDBC batch updates for versioned data: disabled
12:18:48,562  INFO SettingsFactory:189 - Scrollable result sets: enabled
12:18:48,562 DEBUG SettingsFactory:193 - Wrap result sets: disabled
12:18:48,562  INFO SettingsFactory:197 - JDBC3 getGeneratedKeys(): enabled
12:18:48,562  INFO SettingsFactory:205 - Connection release mode: auto
12:18:48,562  INFO SettingsFactory:229 - Maximum outer join fetch depth: 2
12:18:48,562  INFO SettingsFactory:232 - Default batch fetch size: 1
12:18:48,562  INFO SettingsFactory:236 - Generate SQL with comments: disabled
12:18:48,562  INFO SettingsFactory:240 - Order SQL updates by primary key: disabled
12:18:48,562  INFO SettingsFactory:244 - Order SQL inserts for batching: disabled
12:18:48,578  INFO SettingsFactory:420 - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
12:18:48,593  INFO ASTQueryTranslatorFactory:47 - Using ASTQueryTranslatorFactory
12:18:48,593  INFO SettingsFactory:252 - Query language substitutions: {}
12:18:48,609  INFO SettingsFactory:257 - JPA-QL strict compliance: disabled
12:18:48,609  INFO SettingsFactory:262 - Second-level cache: enabled
12:18:48,609  INFO SettingsFactory:266 - Query cache: disabled
12:18:48,609  INFO SettingsFactory:405 - Cache region factory : org.hibernate.cache.impl.NoCachingRegionFactory
12:18:48,609  INFO SettingsFactory:276 - Optimize cache for minimal puts: disabled
12:18:48,609  INFO SettingsFactory:285 - Structured second-level cache entries: disabled
12:18:48,640  INFO SettingsFactory:305 - Echoing all SQL to stdout
12:18:48,656  INFO SettingsFactory:314 - Statistics: disabled
12:18:48,656  INFO SettingsFactory:318 - Deleted entity synthetic identifier rollback: disabled
12:18:48,656  INFO SettingsFactory:333 - Default entity-mode: pojo
12:18:48,656  INFO SettingsFactory:337 - Named query checking : enabled
12:18:48,937  INFO SessionFactoryImpl:187 - building session factory
12:18:48,953 DEBUG SessionFactoryImpl:205 - Session factory constructed with filter configurations : {}
12:18:48,953 DEBUG SessionFactoryImpl:209 - instantiating session factory with properties: {java.runtime.name=Java(TM) SE Runtime Environment, hibernate.connection.password=, sun.boot.library.path=C:\Arquivos de programas\Java\jre6\bin, java.vm.version=14.3-b01, hibernate.connection.username=root, java.vm.vendor=Sun Microsystems Inc., java.vendor.url=http://java.sun.com/, path.separator=;, java.vm.name=Java HotSpot(TM) Client VM, file.encoding.pkg=sun.io, user.country=BR, sun.java.launcher=SUN_STANDARD, sun.os.patch.level=Service Pack 3, java.vm.specification.name=Java Virtual Machine Specification, user.dir=C:\Documents and Settings\Administrador\workspace\Servlet, java.runtime.version=1.6.0_17-b04, java.awt.graphicsenv=sun.awt.Win32GraphicsEnvironment, java.endorsed.dirs=C:\Arquivos de programas\Java\jre6\lib\endorsed, os.arch=x86, java.io.tmpdir=C:\DOCUME~1\ADMINI~1\CONFIG~1\Temp\, line.separator=
, java.vm.specification.vendor=Sun Microsystems Inc., user.variant=, os.name=Windows XP, sun.jnu.encoding=Cp1252, java.library.path=C:\Arquivos de programas\Java\jre6\bin;.;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:/Arquivos de programas/Java/jre6/bin/client;C:/Arquivos de programas/Java/jre6/bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;, java.specification.name=Java Platform API Specification, java.class.version=50.0, sun.management.compiler=HotSpot Client Compiler, os.version=5.1, user.home=C:\Documents and Settings\Administrador, user.timezone=America/Sao_Paulo, java.awt.printerjob=sun.awt.windows.WPrinterJob, file.encoding=Cp1252, java.specification.version=1.6, hibernate.format_sql=true, hibernate.connection.driver_class=com.mysql.jdbc.Driver, user.name=Administrador, java.class.path=C:\Documents and Settings\Administrador\workspace\Servlet\build\classes;C:\Arquivos de programas\Apache Software Foundation\Tomcat 5.5\common\lib\commons-el.jar;C:\Arquivos de programas\Apache Software Foundation\Tomcat 5.5\common\lib\jasper-compiler-jdt.jar;C:\Arquivos de programas\Apache Software Foundation\Tomcat 5.5\common\lib\jasper-compiler.jar;C:\Arquivos de programas\Apache Software Foundation\Tomcat 5.5\common\lib\jasper-runtime.jar;C:\Arquivos de programas\Apache Software Foundation\Tomcat 5.5\common\lib\jsp-api.jar;C:\Arquivos de programas\Apache Software Foundation\Tomcat 5.5\common\lib\naming-factory-dbcp.jar;C:\Arquivos de programas\Apache Software Foundation\Tomcat 5.5\common\lib\naming-factory.jar;C:\Arquivos de programas\Apache Software Foundation\Tomcat 5.5\common\lib\naming-resources.jar;C:\Arquivos de programas\Apache Software Foundation\Tomcat 5.5\common\lib\servlet-api.jar;C:\Documents and Settings\Administrador\Meus documentos\Java\Ultilitarios\hibernate-entitymanager-3.4.0.GA\lib\test\slf4j-log4j12.jar;C:\Documents and Settings\Administrador\Meus documentos\Java\Ultilitarios\hibernate-entitymanager-3.4.0.GA\lib\test\antlr.jar;C:\Documents and Settings\Administrador\Meus documentos\Java\Ultilitarios\hibernate-entitymanager-3.4.0.GA\lib\test\asm.jar;C:\Documents and Settings\Administrador\Meus documentos\Java\Ultilitarios\hibernate-entitymanager-3.4.0.GA\lib\test\asm-attrs.jar;C:\Documents and Settings\Administrador\Meus documentos\Java\Ultilitarios\hibernate-entitymanager-3.4.0.GA\lib\test\cglib.jar;C:\Documents and Settings\Administrador\Meus documentos\Java\Ultilitarios\hibernate-entitymanager-3.4.0.GA\lib\test\commons-collections.jar;C:\Documents and Settings\Administrador\Meus documentos\Java\Ultilitarios\hibernate-entitymanager-3.4.0.GA\lib\test\junit.jar;C:\Documents and Settings\Administrador\Meus documentos\Java\Ultilitarios\hibernate-entitymanager-3.4.0.GA\lib\test\log4j.jar;C:\Documents and Settings\Administrador\Meus documentos\Java\Ultilitarios\hibernate-entitymanager-3.4.0.GA\lib\slf4j-api.jar;C:\Documents and Settings\Administrador\Meus documentos\Java\Ultilitarios\hibernate-entitymanager-3.4.0.GA\lib\dom4j.jar;C:\Documents and Settings\Administrador\Meus documentos\Java\Ultilitarios\hibernate-entitymanager-3.4.0.GA\lib\ejb3-persistence.jar;C:\Documents and Settings\Administrador\Meus documentos\Java\Ultilitarios\hibernate-entitymanager-3.4.0.GA\lib\hibernate-annotations.jar;C:\Documents and Settings\Administrador\Meus documentos\Java\Ultilitarios\hibernate-entitymanager-3.4.0.GA\lib\hibernate-commons-annotations.jar;C:\Documents and Settings\Administrador\Meus documentos\Java\Ultilitarios\hibernate-entitymanager-3.4.0.GA\lib\hibernate-core.jar;C:\Documents and Settings\Administrador\Meus documentos\Java\Ultilitarios\hibernate-entitymanager-3.4.0.GA\lib\javassist.jar;C:\Documents and Settings\Administrador\Meus documentos\Java\Ultilitarios\hibernate-entitymanager-3.4.0.GA\lib\jta.jar, hibernate.bytecode.use_reflection_optimizer=false, hibernate.show_sql=true, java.vm.specification.version=1.0, sun.arch.data.model=32, java.home=C:\Arquivos de programas\Java\jre6, hibernate.connection.url=jdbc:mysql://localhost:3306/controleestoque, hibernate.dialect=org.hibernate.dialect.MySQLDialect, java.specification.vendor=Sun Microsystems Inc., user.language=pt, awt.toolkit=sun.awt.windows.WToolkit, java.vm.info=mixed mode, sharing, java.version=1.6.0_17, java.ext.dirs=C:\Arquivos de programas\Java\jre6\lib\ext;C:\WINDOWS\Sun\Java\lib\ext, sun.boot.class.path=C:\Arquivos de programas\Java\jre6\lib\resources.jar;C:\Arquivos de programas\Java\jre6\lib\rt.jar;C:\Arquivos de programas\Java\jre6\lib\sunrsasign.jar;C:\Arquivos de programas\Java\jre6\lib\jsse.jar;C:\Arquivos de programas\Java\jre6\lib\jce.jar;C:\Arquivos de programas\Java\jre6\lib\charsets.jar;C:\Arquivos de programas\Java\jre6\classes, java.vendor=Sun Microsystems Inc., file.separator=\, java.vendor.url.bug=http://java.sun.com/cgi-bin/bugreport.cgi, sun.cpu.endian=little, sun.io.unicode.encoding=UnicodeLittle, sun.desktop=windows, sun.cpu.isalist=}
12:18:49,984 DEBUG AbstractEntityPersister:2766 - Static SQL for entity: Negocio.Fornecedor
12:18:49,984 DEBUG AbstractEntityPersister:2771 -  Version select: select id from fornecedor where id =?
12:18:49,984 DEBUG AbstractEntityPersister:2774 -  Snapshot select: select fornecedor_.id from fornecedor fornecedor_ where fornecedor_.id=?
12:18:49,984 DEBUG AbstractEntityPersister:2777 -  Insert 0: insert into fornecedor (id) values (?)
12:18:49,984 DEBUG AbstractEntityPersister:2778 -  Update 0: null
12:18:49,984 DEBUG AbstractEntityPersister:2779 -  Delete 0: delete from fornecedor where id=?
12:18:50,078 DEBUG EntityLoader:102 - Static select for entity Negocio.Fornecedor: select fornecedor0_.id as id0_0_ from fornecedor fornecedor0_ where fornecedor0_.id=?
12:18:50,078 DEBUG EntityLoader:102 - Static select for entity Negocio.Fornecedor: select fornecedor0_.id as id0_0_ from fornecedor fornecedor0_ where fornecedor0_.id=?
12:18:50,078 DEBUG EntityLoader:102 - Static select for entity Negocio.Fornecedor: select fornecedor0_.id as id0_0_ from fornecedor fornecedor0_ where fornecedor0_.id=? for update
12:18:50,078 DEBUG EntityLoader:102 - Static select for entity Negocio.Fornecedor: select fornecedor0_.id as id0_0_ from fornecedor fornecedor0_ where fornecedor0_.id=? for update
12:18:50,078 DEBUG EntityLoader:102 - Static select for entity Negocio.Fornecedor: select fornecedor0_.id as id0_0_ from fornecedor fornecedor0_ where fornecedor0_.id=? for update
12:18:50,140 DEBUG EntityLoader:57 - Static select for action ACTION_MERGE on entity Negocio.Fornecedor: select fornecedor0_.id as id0_0_ from fornecedor fornecedor0_ where fornecedor0_.id=?
12:18:50,156 DEBUG EntityLoader:57 - Static select for action ACTION_REFRESH on entity Negocio.Fornecedor: select fornecedor0_.id as id0_0_ from fornecedor fornecedor0_ where fornecedor0_.id=?
12:18:50,187 DEBUG SessionFactoryObjectFactory:62 - initializing class SessionFactoryObjectFactory
12:18:50,203 DEBUG SessionFactoryObjectFactory:99 - registered: 402882e42786746a01278674703b0000 (unnamed)
12:18:50,218  INFO SessionFactoryObjectFactory:105 - Not binding factory to JNDI, no JNDI name configured
12:18:50,218 DEBUG SessionFactoryImpl:340 - instantiated session factory
12:18:50,218 DEBUG SessionFactoryImpl:426 - Checking 0 named HQL queries
12:18:50,218 DEBUG SessionFactoryImpl:446 - Checking 0 named SQL queries
12:18:50,437 DEBUG SessionImpl:247 - opened session at timestamp: [telefone removido]
12:18:50,453 DEBUG IncrementGenerator:104 - fetching initial value: select max(id) from fornecedor
12:18:50,453 DEBUG AbstractBatcher:410 - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
12:18:50,453 DEBUG ConnectionManager:444 - opening JDBC connection
12:18:50,468 DEBUG SQL:111 - 
    select
        max(id) 
    from
        fornecedor
Hibernate: 
    select
        max(id) 
    from
        fornecedor
12:18:50,562 DEBUG IncrementGenerator:119 - first free id: 1
12:18:50,562 DEBUG AbstractBatcher:418 - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
12:18:50,578 DEBUG AbstractSaveEventListener:135 - generated identifier: 1, using strategy: org.hibernate.id.IncrementGenerator

Ai eu vo la no banco para ve r se inseriu e não inseriu nada

Porque pessoal?

Me ajudem ai

15 Respostas

rogelgarcia

Vc tem que dar um session.flush()

ou usar transacao

E

rogel muito obrigado por me ajudar eu pensei que so no update e delete que precisasse,bom vamos la

arrumei meu metodo insert com session.flush();

porem agora da o seguinte erro

13:05:26,453  INFO Environment:543 - Hibernate 3.3.0.SP1
13:05:26,484  INFO Environment:561 - loaded properties from resource hibernate.properties: {hibernate.connection.username=root, hibernate.connection.password=****, hibernate.dialect=org.hibernate.dialect.MySQLDialect, hibernate.show_sql=true, hibernate.connection.url=jdbc:mysql://localhost:3306/controleestoque, hibernate.bytecode.use_reflection_optimizer=false, hibernate.connection.driver_class=com.mysql.jdbc.Driver, hibernate.format_sql=true}
13:05:26,484  INFO Environment:709 - Bytecode provider name : javassist
13:05:26,562  INFO Environment:627 - using JDK 1.4 java.sql.Timestamp handling
13:05:26,796  INFO Configuration:618 - Reading mappings from resource: Negocio/Fornecedor.hbm.xml
13:05:26,812  INFO Configuration:563 - Reading mappings from resource: Negocio/Fornecedor.hbm.xml
13:05:27,421 DEBUG DTDEntityResolver:64 - trying to resolve system-id [http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd]
13:05:27,421 DEBUG DTDEntityResolver:66 - recognized hibernate namespace; attempting to resolve on classpath under org/hibernate/
13:05:27,437 DEBUG DTDEntityResolver:76 - located [http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd] in classpath
13:05:28,218  INFO HbmBinder:322 - Mapping class: Negocio.Fornecedor -> fornecedor
13:05:28,312 DEBUG HbmBinder:1289 - Mapped property: id -> id
13:05:28,421 DEBUG Configuration:1318 - Preparing to build session factory with filters : {}
13:05:28,421 DEBUG Configuration:1153 - processing extends queue
13:05:28,453 DEBUG Configuration:1157 - processing collection mappings
13:05:28,453 DEBUG Configuration:1168 - processing native query and ResultSetMapping mappings
13:05:28,453 DEBUG Configuration:1176 - processing association property references
13:05:28,453 DEBUG Configuration:1198 - processing foreign key constraints
13:05:28,703  INFO DriverManagerConnectionProvider:64 - Using Hibernate built-in connection pool (not for production use!)
13:05:28,703  INFO DriverManagerConnectionProvider:65 - Hibernate connection pool size: 20
13:05:28,796  INFO DriverManagerConnectionProvider:68 - autocommit mode: false
13:05:28,875  INFO DriverManagerConnectionProvider:103 - using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost:3306/controleestoque
13:05:28,875  INFO DriverManagerConnectionProvider:106 - connection properties: {user=root, password=}
13:05:28,875 DEBUG DriverManagerConnectionProvider:132 - opening new JDBC connection
13:05:29,906 DEBUG DriverManagerConnectionProvider:138 - created connection to: jdbc:mysql://localhost:3306/controleestoque, Isolation Level: 4
13:05:29,906  INFO SettingsFactory:116 - RDBMS: MySQL, version: 5.1.44-community
13:05:29,906  INFO SettingsFactory:117 - JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-5.1.12 ( Revision: ${bzr.revision-id} )
13:05:29,984  INFO Dialect:175 - Using dialect: org.hibernate.dialect.MySQLDialect
13:05:30,000  INFO TransactionFactoryFactory:59 - Using default transaction strategy (direct JDBC transactions)
13:05:30,015  INFO TransactionManagerLookupFactory:80 - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
13:05:30,015  INFO SettingsFactory:170 - Automatic flush during beforeCompletion(): disabled
13:05:30,015  INFO SettingsFactory:174 - Automatic session close at end of transaction: disabled
13:05:30,015  INFO SettingsFactory:181 - JDBC batch size: 15
13:05:30,015  INFO SettingsFactory:184 - JDBC batch updates for versioned data: disabled
13:05:30,015  INFO SettingsFactory:189 - Scrollable result sets: enabled
13:05:30,015 DEBUG SettingsFactory:193 - Wrap result sets: disabled
13:05:30,015  INFO SettingsFactory:197 - JDBC3 getGeneratedKeys(): enabled
13:05:30,015  INFO SettingsFactory:205 - Connection release mode: auto
13:05:30,031  INFO SettingsFactory:229 - Maximum outer join fetch depth: 2
13:05:30,031  INFO SettingsFactory:232 - Default batch fetch size: 1
13:05:30,031  INFO SettingsFactory:236 - Generate SQL with comments: disabled
13:05:30,031  INFO SettingsFactory:240 - Order SQL updates by primary key: disabled
13:05:30,031  INFO SettingsFactory:244 - Order SQL inserts for batching: disabled
13:05:30,031  INFO SettingsFactory:420 - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
13:05:30,046  INFO ASTQueryTranslatorFactory:47 - Using ASTQueryTranslatorFactory
13:05:30,046  INFO SettingsFactory:252 - Query language substitutions: {}
13:05:30,046  INFO SettingsFactory:257 - JPA-QL strict compliance: disabled
13:05:30,046  INFO SettingsFactory:262 - Second-level cache: enabled
13:05:30,046  INFO SettingsFactory:266 - Query cache: disabled
13:05:30,046  INFO SettingsFactory:405 - Cache region factory : org.hibernate.cache.impl.NoCachingRegionFactory
13:05:30,046  INFO SettingsFactory:276 - Optimize cache for minimal puts: disabled
13:05:30,046  INFO SettingsFactory:285 - Structured second-level cache entries: disabled
13:05:30,078  INFO SettingsFactory:305 - Echoing all SQL to stdout
13:05:30,078  INFO SettingsFactory:314 - Statistics: disabled
13:05:30,078  INFO SettingsFactory:318 - Deleted entity synthetic identifier rollback: disabled
13:05:30,078  INFO SettingsFactory:333 - Default entity-mode: pojo
13:05:30,078  INFO SettingsFactory:337 - Named query checking : enabled
13:05:30,250  INFO SessionFactoryImpl:187 - building session factory
13:05:30,250 DEBUG SessionFactoryImpl:205 - Session factory constructed with filter configurations : {}
13:05:30,250 DEBUG SessionFactoryImpl:209 - instantiating session factory with properties: {java.runtime.name=Java(TM) SE Runtime Environment, hibernate.connection.password=, sun.boot.library.path=C:\Arquivos de programas\Java\jre6\bin, java.vm.version=14.3-b01, hibernate.connection.username=root, java.vm.vendor=Sun Microsystems Inc., java.vendor.url=http://java.sun.com/, path.separator=;, java.vm.name=Java HotSpot(TM) Client VM, file.encoding.pkg=sun.io, user.country=BR, sun.java.launcher=SUN_STANDARD, sun.os.patch.level=Service Pack 3, java.vm.specification.name=Java Virtual Machine Specification, user.dir=C:\Documents and Settings\Administrador\workspace\Servlet, java.runtime.version=1.6.0_17-b04, java.awt.graphicsenv=sun.awt.Win32GraphicsEnvironment, java.endorsed.dirs=C:\Arquivos de programas\Java\jre6\lib\endorsed, os.arch=x86, java.io.tmpdir=C:\DOCUME~1\ADMINI~1\CONFIG~1\Temp\, line.separator=
, java.vm.specification.vendor=Sun Microsystems Inc., user.variant=, os.name=Windows XP, sun.jnu.encoding=Cp1252, java.library.path=C:\Arquivos de programas\Java\jre6\bin;.;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:/Arquivos de programas/Java/jre6/bin/client;C:/Arquivos de programas/Java/jre6/bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;, java.specification.name=Java Platform API Specification, java.class.version=50.0, sun.management.compiler=HotSpot Client Compiler, os.version=5.1, user.home=C:\Documents and Settings\Administrador, user.timezone=America/Sao_Paulo, java.awt.printerjob=sun.awt.windows.WPrinterJob, file.encoding=Cp1252, java.specification.version=1.6, hibernate.format_sql=true, hibernate.connection.driver_class=com.mysql.jdbc.Driver, user.name=Administrador, java.class.path=C:\Documents and Settings\Administrador\workspace\Servlet\build\classes;C:\Arquivos de programas\Apache Software Foundation\Tomcat 5.5\common\lib\commons-el.jar;C:\Arquivos de programas\Apache Software Foundation\Tomcat 5.5\common\lib\jasper-compiler-jdt.jar;C:\Arquivos de programas\Apache Software Foundation\Tomcat 5.5\common\lib\jasper-compiler.jar;C:\Arquivos de programas\Apache Software Foundation\Tomcat 5.5\common\lib\jasper-runtime.jar;C:\Arquivos de programas\Apache Software Foundation\Tomcat 5.5\common\lib\jsp-api.jar;C:\Arquivos de programas\Apache Software Foundation\Tomcat 5.5\common\lib\naming-factory-dbcp.jar;C:\Arquivos de programas\Apache Software Foundation\Tomcat 5.5\common\lib\naming-factory.jar;C:\Arquivos de programas\Apache Software Foundation\Tomcat 5.5\common\lib\naming-resources.jar;C:\Arquivos de programas\Apache Software Foundation\Tomcat 5.5\common\lib\servlet-api.jar;C:\Documents and Settings\Administrador\Meus documentos\Java\Ultilitarios\hibernate-entitymanager-3.4.0.GA\lib\test\slf4j-log4j12.jar;C:\Documents and Settings\Administrador\Meus documentos\Java\Ultilitarios\hibernate-entitymanager-3.4.0.GA\lib\test\antlr.jar;C:\Documents and Settings\Administrador\Meus documentos\Java\Ultilitarios\hibernate-entitymanager-3.4.0.GA\lib\test\asm.jar;C:\Documents and Settings\Administrador\Meus documentos\Java\Ultilitarios\hibernate-entitymanager-3.4.0.GA\lib\test\asm-attrs.jar;C:\Documents and Settings\Administrador\Meus documentos\Java\Ultilitarios\hibernate-entitymanager-3.4.0.GA\lib\test\cglib.jar;C:\Documents and Settings\Administrador\Meus documentos\Java\Ultilitarios\hibernate-entitymanager-3.4.0.GA\lib\test\commons-collections.jar;C:\Documents and Settings\Administrador\Meus documentos\Java\Ultilitarios\hibernate-entitymanager-3.4.0.GA\lib\test\junit.jar;C:\Documents and Settings\Administrador\Meus documentos\Java\Ultilitarios\hibernate-entitymanager-3.4.0.GA\lib\test\log4j.jar;C:\Documents and Settings\Administrador\Meus documentos\Java\Ultilitarios\hibernate-entitymanager-3.4.0.GA\lib\slf4j-api.jar;C:\Documents and Settings\Administrador\Meus documentos\Java\Ultilitarios\hibernate-entitymanager-3.4.0.GA\lib\dom4j.jar;C:\Documents and Settings\Administrador\Meus documentos\Java\Ultilitarios\hibernate-entitymanager-3.4.0.GA\lib\ejb3-persistence.jar;C:\Documents and Settings\Administrador\Meus documentos\Java\Ultilitarios\hibernate-entitymanager-3.4.0.GA\lib\hibernate-annotations.jar;C:\Documents and Settings\Administrador\Meus documentos\Java\Ultilitarios\hibernate-entitymanager-3.4.0.GA\lib\hibernate-commons-annotations.jar;C:\Documents and Settings\Administrador\Meus documentos\Java\Ultilitarios\hibernate-entitymanager-3.4.0.GA\lib\hibernate-core.jar;C:\Documents and Settings\Administrador\Meus documentos\Java\Ultilitarios\hibernate-entitymanager-3.4.0.GA\lib\javassist.jar;C:\Documents and Settings\Administrador\Meus documentos\Java\Ultilitarios\hibernate-entitymanager-3.4.0.GA\lib\jta.jar, hibernate.bytecode.use_reflection_optimizer=false, hibernate.show_sql=true, java.vm.specification.version=1.0, sun.arch.data.model=32, java.home=C:\Arquivos de programas\Java\jre6, hibernate.connection.url=jdbc:mysql://localhost:3306/controleestoque, hibernate.dialect=org.hibernate.dialect.MySQLDialect, java.specification.vendor=Sun Microsystems Inc., user.language=pt, awt.toolkit=sun.awt.windows.WToolkit, java.vm.info=mixed mode, sharing, java.version=1.6.0_17, java.ext.dirs=C:\Arquivos de programas\Java\jre6\lib\ext;C:\WINDOWS\Sun\Java\lib\ext, sun.boot.class.path=C:\Arquivos de programas\Java\jre6\lib\resources.jar;C:\Arquivos de programas\Java\jre6\lib\rt.jar;C:\Arquivos de programas\Java\jre6\lib\sunrsasign.jar;C:\Arquivos de programas\Java\jre6\lib\jsse.jar;C:\Arquivos de programas\Java\jre6\lib\jce.jar;C:\Arquivos de programas\Java\jre6\lib\charsets.jar;C:\Arquivos de programas\Java\jre6\classes, java.vendor=Sun Microsystems Inc., file.separator=\, java.vendor.url.bug=http://java.sun.com/cgi-bin/bugreport.cgi, sun.cpu.endian=little, sun.io.unicode.encoding=UnicodeLittle, sun.desktop=windows, sun.cpu.isalist=}
13:05:30,890 DEBUG AbstractEntityPersister:2766 - Static SQL for entity: Negocio.Fornecedor
13:05:30,890 DEBUG AbstractEntityPersister:2771 -  Version select: select id from fornecedor where id =?
13:05:30,890 DEBUG AbstractEntityPersister:2774 -  Snapshot select: select fornecedor_.id from fornecedor fornecedor_ where fornecedor_.id=?
13:05:30,890 DEBUG AbstractEntityPersister:2777 -  Insert 0: insert into fornecedor (id) values (?)
13:05:30,906 DEBUG AbstractEntityPersister:2778 -  Update 0: null
13:05:30,906 DEBUG AbstractEntityPersister:2779 -  Delete 0: delete from fornecedor where id=?
13:05:31,109 DEBUG EntityLoader:102 - Static select for entity Negocio.Fornecedor: select fornecedor0_.id as id0_0_ from fornecedor fornecedor0_ where fornecedor0_.id=?
13:05:31,109 DEBUG EntityLoader:102 - Static select for entity Negocio.Fornecedor: select fornecedor0_.id as id0_0_ from fornecedor fornecedor0_ where fornecedor0_.id=?
13:05:31,125 DEBUG EntityLoader:102 - Static select for entity Negocio.Fornecedor: select fornecedor0_.id as id0_0_ from fornecedor fornecedor0_ where fornecedor0_.id=? for update
13:05:31,125 DEBUG EntityLoader:102 - Static select for entity Negocio.Fornecedor: select fornecedor0_.id as id0_0_ from fornecedor fornecedor0_ where fornecedor0_.id=? for update
13:05:31,125 DEBUG EntityLoader:102 - Static select for entity Negocio.Fornecedor: select fornecedor0_.id as id0_0_ from fornecedor fornecedor0_ where fornecedor0_.id=? for update
13:05:31,250 DEBUG EntityLoader:57 - Static select for action ACTION_MERGE on entity Negocio.Fornecedor: select fornecedor0_.id as id0_0_ from fornecedor fornecedor0_ where fornecedor0_.id=?
13:05:31,265 DEBUG EntityLoader:57 - Static select for action ACTION_REFRESH on entity Negocio.Fornecedor: select fornecedor0_.id as id0_0_ from fornecedor fornecedor0_ where fornecedor0_.id=?
13:05:31,359 DEBUG SessionFactoryObjectFactory:62 - initializing class SessionFactoryObjectFactory
13:05:31,359 DEBUG SessionFactoryObjectFactory:99 - registered: 402882e427869f290127869f2e010000 (unnamed)
13:05:31,359  INFO SessionFactoryObjectFactory:105 - Not binding factory to JNDI, no JNDI name configured
13:05:31,359 DEBUG SessionFactoryImpl:340 - instantiated session factory
13:05:31,359 DEBUG SessionFactoryImpl:426 - Checking 0 named HQL queries
13:05:31,359 DEBUG SessionFactoryImpl:446 - Checking 0 named SQL queries
13:05:31,687 DEBUG SessionImpl:247 - opened session at timestamp: [telefone removido]
13:05:31,703 DEBUG IncrementGenerator:104 - fetching initial value: select max(id) from fornecedor
13:05:31,703 DEBUG AbstractBatcher:410 - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
13:05:31,703 DEBUG ConnectionManager:444 - opening JDBC connection
13:05:31,718 DEBUG SQL:111 - 
    select
        max(id) 
    from
        fornecedor
Hibernate: 
    select
        max(id) 
    from
        fornecedor
13:05:31,796 DEBUG IncrementGenerator:119 - first free id: 1
13:05:31,796 DEBUG AbstractBatcher:418 - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
13:05:31,796 DEBUG AbstractSaveEventListener:135 - generated identifier: 1, using strategy: org.hibernate.id.IncrementGenerator
13:05:31,906 DEBUG AbstractFlushingEventListener:134 - processing flush-time cascades
13:05:31,921 DEBUG AbstractFlushingEventListener:177 - dirty checking collections
13:05:31,921 DEBUG AbstractFlushingEventListener:108 - Flushed: 1 insertions, 0 updates, 0 deletions to 1 objects
13:05:31,921 DEBUG AbstractFlushingEventListener:114 - Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
13:05:31,937 DEBUG Printer:106 - listing entities:
13:05:31,937 DEBUG Printer:113 - Negocio.Fornecedor{id=1}
13:05:32,015 DEBUG AbstractBatcher:410 - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
13:05:32,015 DEBUG SQL:111 - 
    insert 
    into
        fornecedor
        (id) 
    values
        (?)
Hibernate: 
    insert 
    into
        fornecedor
        (id) 
    values
        (?)
13:05:32,015 DEBUG AbstractBatcher:66 - Executing batch size: 1
13:05:32,046 DEBUG AbstractBatcher:418 - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
Exception in thread "main" org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
	at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:126)
	at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:114)
	at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
	at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:275)
	at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:266)
	at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:167)
	at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
	at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
	at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1027)
	at Persistencia.FornecedorDAO.insert(FornecedorDAO.java:21)
	at Negocio.Teste.main(Teste.java:11)
Caused by: java.sql.BatchUpdateException: Field 'nome' doesn't have a default value
	at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:2018)
	at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1454)
	at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)
	at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)
	... 7 more
13:05:32,062 DEBUG JDBCExceptionReporter:92 - Could not execute JDBC batch update [insert into fornecedor (id) values (?)]
java.sql.BatchUpdateException: Field 'nome' doesn't have a default value
	at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:2018)
	at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1454)
	at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)
	at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)
	at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:266)
	at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:167)
	at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
	at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
	at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1027)
	at Persistencia.FornecedorDAO.insert(FornecedorDAO.java:21)
	at Negocio.Teste.main(Teste.java:11)
13:05:32,093  WARN JDBCExceptionReporter:100 - SQL Error: 1364, SQLState: HY000
13:05:32,093 ERROR JDBCExceptionReporter:101 - Field 'nome' doesn't have a default value
13:05:32,093 ERROR AbstractFlushingEventListener:324 - Could not synchronize database state with session
org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
	at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:126)
	at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:114)
	at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
	at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:275)
	at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:266)
	at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:167)
	at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
	at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
	at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1027)
	at Persistencia.FornecedorDAO.insert(FornecedorDAO.java:21)
	at Negocio.Teste.main(Teste.java:11)
Caused by: java.sql.BatchUpdateException: Field 'nome' doesn't have a default value
	at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:2018)
	at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1454)
	at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)
	at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)
	... 7 more
rogelgarcia

O campo nome é notnull e vc nao tá atribuindo nenhum valor pra ele?

E

Estou Sim okha minha classe teste o metodo main

public static void main(String[] args) {

Fornecedor f = new Fornecedor();

f.setNome(pedraummmmmm);

FornecedorDAO fDAO = new FornecedorDAO();

fDAO.insert(f);
}

eu sou nao estou mapeando o nome em Fornecedorhbm.xml mais como o nome do atributo e o mesmo nome da coluna nao precisa neh

kikostyle

Vc não mapeou “nome” no hbm

rogelgarcia

Por algum motivo… nao está mapeando o nome entao…

Tente mapear o nome do hbm pra ver se funciona

(Voce só nao precisa mapear quando estiver usando annotations… mas no hbm precisa… só nao precisa falar o nome da coluna… mas tem que falar que o field é mapeado)

ebortolatto

Outro detalhe que parece estar faltando é implementar java.io.Serializable na classe Fornecedor :slight_smile:

E

Ola pesso muito obrigado por esta me ajudando, porem está com erros ainda veja com ficou minha classe Fornecedor.hbm.xml (ainda axo que o erro esta nessa classe)

Fornecedor.hbm.xml

<?xml version="1.0" encoding="UTF-8"?>   
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">   
<hibernate-mapping>   
    <class name="Negocio.Fornecedor" table="fornecedor">   
        <id name="id" >
          <generator class="increment"/>    
        </id> 
        <property name="nome" column="nome" type="String"/>
    </class>   
</hibernate-mapping>

ai fui rodar e deu o seguinte erro

14:52:12,633  INFO Environment:543 - Hibernate 3.3.0.SP1
14:52:12,664  INFO Environment:561 - loaded properties from resource hibernate.properties: {hibernate.connection.username=root, hibernate.connection.password=****, hibernate.dialect=org.hibernate.dialect.MySQLDialect, hibernate.show_sql=true, hibernate.connection.url=jdbc:mysql://localhost:3306/controleestoque, hibernate.bytecode.use_reflection_optimizer=false, hibernate.connection.driver_class=com.mysql.jdbc.Driver, hibernate.format_sql=true}
14:52:12,664  INFO Environment:709 - Bytecode provider name : javassist
14:52:12,742  INFO Environment:627 - using JDK 1.4 java.sql.Timestamp handling
14:52:13,258  INFO Configuration:618 - Reading mappings from resource: Negocio/Fornecedor.hbm.xml
14:52:13,258  INFO Configuration:563 - Reading mappings from resource: Negocio/Fornecedor.hbm.xml
14:52:13,539 DEBUG DTDEntityResolver:64 - trying to resolve system-id [http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd]
14:52:13,539 DEBUG DTDEntityResolver:66 - recognized hibernate namespace; attempting to resolve on classpath under org/hibernate/
14:52:13,539 DEBUG DTDEntityResolver:76 - located [http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd] in classpath
14:52:14,008  INFO HbmBinder:322 - Mapping class: Negocio.Fornecedor -> fornecedor
14:52:14,055 DEBUG HbmBinder:1289 - Mapped property: id -> id
14:52:14,133 DEBUG HbmBinder:1289 - Mapped property: nome -> nome
14:52:14,133 DEBUG Configuration:1318 - Preparing to build session factory with filters : {}
14:52:14,133 DEBUG Configuration:1153 - processing extends queue
14:52:14,164 DEBUG Configuration:1157 - processing collection mappings
14:52:14,164 DEBUG Configuration:1168 - processing native query and ResultSetMapping mappings
14:52:14,164 DEBUG Configuration:1176 - processing association property references
14:52:14,164 DEBUG Configuration:1198 - processing foreign key constraints
Exception in thread "main" org.hibernate.MappingException: Could not determine type for: String, at table: fornecedor, for columns: [org.hibernate.mapping.Column(nome)]
	at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:292)
	at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:276)
	at org.hibernate.mapping.Property.isValid(Property.java:207)
	at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:458)
	at org.hibernate.mapping.RootClass.validate(RootClass.java:215)
	at org.hibernate.cfg.Configuration.validate(Configuration.java:1135)
	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1320)
	at Persistencia.FabricaConexao.getSession(FabricaConexao.java:16)
	at Persistencia.FornecedorDAO.<init>(FornecedorDAO.java:14)
	at Negocio.Teste.main(Teste.java:10)

ai eu percebi que tava dando alguma coisa errado com type String , por no banco ser varchar, ai eu tirei esse type String

ai ficou assim

Fornecedor.hbm.xml

<?xml version="1.0" encoding="UTF-8"?>   
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">   
<hibernate-mapping>   
    <class name="Negocio.Fornecedor" table="fornecedor">   
        <id name="id" >
          <generator class="increment"/>    
        </id> 
        <property name="nome" column="nome" />
    </class>   
</hibernate-mapping>

ai deu a seguinte mensagem

:06:38,164  INFO Environment:543 - Hibernate 3.3.0.SP1
15:06:38,180  INFO Environment:561 - loaded properties from resource hibernate.properties: {hibernate.connection.username=root, hibernate.connection.password=****, hibernate.dialect=org.hibernate.dialect.MySQLDialect, hibernate.show_sql=true, hibernate.connection.url=jdbc:mysql://localhost:3306/controleestoque, hibernate.bytecode.use_reflection_optimizer=false, hibernate.connection.driver_class=com.mysql.jdbc.Driver, hibernate.format_sql=true}
15:06:38,195  INFO Environment:709 - Bytecode provider name : javassist
15:06:38,211  INFO Environment:627 - using JDK 1.4 java.sql.Timestamp handling
15:06:38,601  INFO Configuration:618 - Reading mappings from resource: Negocio/Fornecedor.hbm.xml
15:06:38,601  INFO Configuration:563 - Reading mappings from resource: Negocio/Fornecedor.hbm.xml
15:06:38,945 DEBUG DTDEntityResolver:64 - trying to resolve system-id [http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd]
15:06:38,945 DEBUG DTDEntityResolver:66 - recognized hibernate namespace; attempting to resolve on classpath under org/hibernate/
15:06:38,945 DEBUG DTDEntityResolver:76 - located [http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd] in classpath
15:06:39,383  INFO HbmBinder:322 - Mapping class: Negocio.Fornecedor -> fornecedor
15:06:39,430 DEBUG HbmBinder:1289 - Mapped property: id -> id
15:06:39,492 DEBUG HbmBinder:1289 - Mapped property: nome -> nome
15:06:39,492 DEBUG Configuration:1318 - Preparing to build session factory with filters : {}
15:06:39,492 DEBUG Configuration:1153 - processing extends queue
15:06:39,523 DEBUG Configuration:1157 - processing collection mappings
15:06:39,523 DEBUG Configuration:1168 - processing native query and ResultSetMapping mappings
15:06:39,523 DEBUG Configuration:1176 - processing association property references
15:06:39,523 DEBUG Configuration:1198 - processing foreign key constraints
15:06:39,820  INFO DriverManagerConnectionProvider:64 - Using Hibernate built-in connection pool (not for production use!)
15:06:39,820  INFO DriverManagerConnectionProvider:65 - Hibernate connection pool size: 20
15:06:39,820  INFO DriverManagerConnectionProvider:68 - autocommit mode: false
15:06:39,851  INFO DriverManagerConnectionProvider:103 - using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost:3306/controleestoque
15:06:39,851  INFO DriverManagerConnectionProvider:106 - connection properties: {user=root, password=}
15:06:39,851 DEBUG DriverManagerConnectionProvider:132 - opening new JDBC connection
15:06:40,570 DEBUG DriverManagerConnectionProvider:138 - created connection to: jdbc:mysql://localhost:3306/controleestoque, Isolation Level: 4
15:06:40,617  INFO SettingsFactory:116 - RDBMS: MySQL, version: 5.1.44-community
15:06:40,617  INFO SettingsFactory:117 - JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-5.1.12 ( Revision: ${bzr.revision-id} )
15:06:40,742  INFO Dialect:175 - Using dialect: org.hibernate.dialect.MySQLDialect
15:06:40,758  INFO TransactionFactoryFactory:59 - Using default transaction strategy (direct JDBC transactions)
15:06:40,773  INFO TransactionManagerLookupFactory:80 - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
15:06:40,773  INFO SettingsFactory:170 - Automatic flush during beforeCompletion(): disabled
15:06:40,773  INFO SettingsFactory:174 - Automatic session close at end of transaction: disabled
15:06:40,773  INFO SettingsFactory:181 - JDBC batch size: 15
15:06:40,773  INFO SettingsFactory:184 - JDBC batch updates for versioned data: disabled
15:06:40,773  INFO SettingsFactory:189 - Scrollable result sets: enabled
15:06:40,773 DEBUG SettingsFactory:193 - Wrap result sets: disabled
15:06:40,773  INFO SettingsFactory:197 - JDBC3 getGeneratedKeys(): enabled
15:06:40,773  INFO SettingsFactory:205 - Connection release mode: auto
15:06:40,773  INFO SettingsFactory:229 - Maximum outer join fetch depth: 2
15:06:40,773  INFO SettingsFactory:232 - Default batch fetch size: 1
15:06:40,773  INFO SettingsFactory:236 - Generate SQL with comments: disabled
15:06:40,773  INFO SettingsFactory:240 - Order SQL updates by primary key: disabled
15:06:40,773  INFO SettingsFactory:244 - Order SQL inserts for batching: disabled
15:06:40,773  INFO SettingsFactory:420 - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
15:06:40,789  INFO ASTQueryTranslatorFactory:47 - Using ASTQueryTranslatorFactory
15:06:40,789  INFO SettingsFactory:252 - Query language substitutions: {}
15:06:40,789  INFO SettingsFactory:257 - JPA-QL strict compliance: disabled
15:06:40,789  INFO SettingsFactory:262 - Second-level cache: enabled
15:06:40,789  INFO SettingsFactory:266 - Query cache: disabled
15:06:40,789  INFO SettingsFactory:405 - Cache region factory : org.hibernate.cache.impl.NoCachingRegionFactory
15:06:40,789  INFO SettingsFactory:276 - Optimize cache for minimal puts: disabled
15:06:40,789  INFO SettingsFactory:285 - Structured second-level cache entries: disabled
15:06:40,820  INFO SettingsFactory:305 - Echoing all SQL to stdout
15:06:40,820  INFO SettingsFactory:314 - Statistics: disabled
15:06:40,820  INFO SettingsFactory:318 - Deleted entity synthetic identifier rollback: disabled
15:06:40,820  INFO SettingsFactory:333 - Default entity-mode: pojo
15:06:40,820  INFO SettingsFactory:337 - Named query checking : enabled
15:06:40,976  INFO SessionFactoryImpl:187 - building session factory
15:06:40,976 DEBUG SessionFactoryImpl:205 - Session factory constructed with filter configurations : {}
15:06:40,976 DEBUG SessionFactoryImpl:209 - instantiating session factory with properties: {java.runtime.name=Java(TM) SE Runtime Environment, hibernate.connection.password=, sun.boot.library.path=C:\Arquivos de programas\Java\jre6\bin, java.vm.version=14.3-b01, hibernate.connection.username=root, java.vm.vendor=Sun Microsystems Inc., java.vendor.url=http://java.sun.com/, path.separator=;, java.vm.name=Java HotSpot(TM) Client VM, file.encoding.pkg=sun.io, user.country=BR, sun.java.launcher=SUN_STANDARD, sun.os.patch.level=Service Pack 3, java.vm.specification.name=Java Virtual Machine Specification, user.dir=C:\Documents and Settings\Administrador\workspace\Servlet, java.runtime.version=1.6.0_17-b04, java.awt.graphicsenv=sun.awt.Win32GraphicsEnvironment, java.endorsed.dirs=C:\Arquivos de programas\Java\jre6\lib\endorsed, os.arch=x86, java.io.tmpdir=C:\DOCUME~1\ADMINI~1\CONFIG~1\Temp\, line.separator=
, java.vm.specification.vendor=Sun Microsystems Inc., user.variant=, os.name=Windows XP, sun.jnu.encoding=Cp1252, java.library.path=C:\Arquivos de programas\Java\jre6\bin;.;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:/Arquivos de programas/Java/jre6/bin/client;C:/Arquivos de programas/Java/jre6/bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;, java.specification.name=Java Platform API Specification, java.class.version=50.0, sun.management.compiler=HotSpot Client Compiler, os.version=5.1, user.home=C:\Documents and Settings\Administrador, user.timezone=America/Sao_Paulo, java.awt.printerjob=sun.awt.windows.WPrinterJob, file.encoding=Cp1252, java.specification.version=1.6, hibernate.format_sql=true, hibernate.connection.driver_class=com.mysql.jdbc.Driver, user.name=Administrador, java.class.path=C:\Documents and Settings\Administrador\workspace\Servlet\build\classes;C:\Arquivos de programas\Apache Software Foundation\Tomcat 5.5\common\lib\commons-el.jar;C:\Arquivos de programas\Apache Software Foundation\Tomcat 5.5\common\lib\jasper-compiler-jdt.jar;C:\Arquivos de programas\Apache Software Foundation\Tomcat 5.5\common\lib\jasper-compiler.jar;C:\Arquivos de programas\Apache Software Foundation\Tomcat 5.5\common\lib\jasper-runtime.jar;C:\Arquivos de programas\Apache Software Foundation\Tomcat 5.5\common\lib\jsp-api.jar;C:\Arquivos de programas\Apache Software Foundation\Tomcat 5.5\common\lib\naming-factory-dbcp.jar;C:\Arquivos de programas\Apache Software Foundation\Tomcat 5.5\common\lib\naming-factory.jar;C:\Arquivos de programas\Apache Software Foundation\Tomcat 5.5\common\lib\naming-resources.jar;C:\Arquivos de programas\Apache Software Foundation\Tomcat 5.5\common\lib\servlet-api.jar;C:\Documents and Settings\Administrador\Meus documentos\Java\Ultilitarios\hibernate-entitymanager-3.4.0.GA\lib\test\slf4j-log4j12.jar;C:\Documents and Settings\Administrador\Meus documentos\Java\Ultilitarios\hibernate-entitymanager-3.4.0.GA\lib\test\antlr.jar;C:\Documents and Settings\Administrador\Meus documentos\Java\Ultilitarios\hibernate-entitymanager-3.4.0.GA\lib\test\asm.jar;C:\Documents and Settings\Administrador\Meus documentos\Java\Ultilitarios\hibernate-entitymanager-3.4.0.GA\lib\test\asm-attrs.jar;C:\Documents and Settings\Administrador\Meus documentos\Java\Ultilitarios\hibernate-entitymanager-3.4.0.GA\lib\test\cglib.jar;C:\Documents and Settings\Administrador\Meus documentos\Java\Ultilitarios\hibernate-entitymanager-3.4.0.GA\lib\test\commons-collections.jar;C:\Documents and Settings\Administrador\Meus documentos\Java\Ultilitarios\hibernate-entitymanager-3.4.0.GA\lib\test\junit.jar;C:\Documents and Settings\Administrador\Meus documentos\Java\Ultilitarios\hibernate-entitymanager-3.4.0.GA\lib\test\log4j.jar;C:\Documents and Settings\Administrador\Meus documentos\Java\Ultilitarios\hibernate-entitymanager-3.4.0.GA\lib\slf4j-api.jar;C:\Documents and Settings\Administrador\Meus documentos\Java\Ultilitarios\hibernate-entitymanager-3.4.0.GA\lib\dom4j.jar;C:\Documents and Settings\Administrador\Meus documentos\Java\Ultilitarios\hibernate-entitymanager-3.4.0.GA\lib\ejb3-persistence.jar;C:\Documents and Settings\Administrador\Meus documentos\Java\Ultilitarios\hibernate-entitymanager-3.4.0.GA\lib\hibernate-annotations.jar;C:\Documents and Settings\Administrador\Meus documentos\Java\Ultilitarios\hibernate-entitymanager-3.4.0.GA\lib\hibernate-commons-annotations.jar;C:\Documents and Settings\Administrador\Meus documentos\Java\Ultilitarios\hibernate-entitymanager-3.4.0.GA\lib\hibernate-core.jar;C:\Documents and Settings\Administrador\Meus documentos\Java\Ultilitarios\hibernate-entitymanager-3.4.0.GA\lib\javassist.jar;C:\Documents and Settings\Administrador\Meus documentos\Java\Ultilitarios\hibernate-entitymanager-3.4.0.GA\lib\jta.jar, hibernate.bytecode.use_reflection_optimizer=false, hibernate.show_sql=true, java.vm.specification.version=1.0, sun.arch.data.model=32, java.home=C:\Arquivos de programas\Java\jre6, hibernate.connection.url=jdbc:mysql://localhost:3306/controleestoque, hibernate.dialect=org.hibernate.dialect.MySQLDialect, java.specification.vendor=Sun Microsystems Inc., user.language=pt, awt.toolkit=sun.awt.windows.WToolkit, java.vm.info=mixed mode, sharing, java.version=1.6.0_17, java.ext.dirs=C:\Arquivos de programas\Java\jre6\lib\ext;C:\WINDOWS\Sun\Java\lib\ext, sun.boot.class.path=C:\Arquivos de programas\Java\jre6\lib\resources.jar;C:\Arquivos de programas\Java\jre6\lib\rt.jar;C:\Arquivos de programas\Java\jre6\lib\sunrsasign.jar;C:\Arquivos de programas\Java\jre6\lib\jsse.jar;C:\Arquivos de programas\Java\jre6\lib\jce.jar;C:\Arquivos de programas\Java\jre6\lib\charsets.jar;C:\Arquivos de programas\Java\jre6\classes, java.vendor=Sun Microsystems Inc., file.separator=\, java.vendor.url.bug=http://java.sun.com/cgi-bin/bugreport.cgi, sun.cpu.endian=little, sun.io.unicode.encoding=UnicodeLittle, sun.desktop=windows, sun.cpu.isalist=}
15:06:41,586 DEBUG AbstractEntityPersister:2766 - Static SQL for entity: Negocio.Fornecedor
15:06:41,586 DEBUG AbstractEntityPersister:2771 -  Version select: select id from fornecedor where id =?
15:06:41,586 DEBUG AbstractEntityPersister:2774 -  Snapshot select: select fornecedor_.id, fornecedor_.nome as nome0_ from fornecedor fornecedor_ where fornecedor_.id=?
15:06:41,586 DEBUG AbstractEntityPersister:2777 -  Insert 0: insert into fornecedor (nome, id) values (?, ?)
15:06:41,586 DEBUG AbstractEntityPersister:2778 -  Update 0: update fornecedor set nome=? where id=?
15:06:41,648 DEBUG AbstractEntityPersister:2779 -  Delete 0: delete from fornecedor where id=?
15:06:41,758 DEBUG EntityLoader:102 - Static select for entity Negocio.Fornecedor: select fornecedor0_.id as id0_0_, fornecedor0_.nome as nome0_0_ from fornecedor fornecedor0_ where fornecedor0_.id=?
15:06:41,758 DEBUG EntityLoader:102 - Static select for entity Negocio.Fornecedor: select fornecedor0_.id as id0_0_, fornecedor0_.nome as nome0_0_ from fornecedor fornecedor0_ where fornecedor0_.id=?
15:06:41,758 DEBUG EntityLoader:102 - Static select for entity Negocio.Fornecedor: select fornecedor0_.id as id0_0_, fornecedor0_.nome as nome0_0_ from fornecedor fornecedor0_ where fornecedor0_.id=? for update
15:06:41,758 DEBUG EntityLoader:102 - Static select for entity Negocio.Fornecedor: select fornecedor0_.id as id0_0_, fornecedor0_.nome as nome0_0_ from fornecedor fornecedor0_ where fornecedor0_.id=? for update
15:06:41,773 DEBUG EntityLoader:102 - Static select for entity Negocio.Fornecedor: select fornecedor0_.id as id0_0_, fornecedor0_.nome as nome0_0_ from fornecedor fornecedor0_ where fornecedor0_.id=? for update
15:06:41,836 DEBUG EntityLoader:57 - Static select for action ACTION_MERGE on entity Negocio.Fornecedor: select fornecedor0_.id as id0_0_, fornecedor0_.nome as nome0_0_ from fornecedor fornecedor0_ where fornecedor0_.id=?
15:06:41,836 DEBUG EntityLoader:57 - Static select for action ACTION_REFRESH on entity Negocio.Fornecedor: select fornecedor0_.id as id0_0_, fornecedor0_.nome as nome0_0_ from fornecedor fornecedor0_ where fornecedor0_.id=?
15:06:41,851 DEBUG SessionFactoryObjectFactory:62 - initializing class SessionFactoryObjectFactory
15:06:41,851 DEBUG SessionFactoryObjectFactory:99 - registered: 402882e427870e1a0127870e1eac0000 (unnamed)
15:06:41,851  INFO SessionFactoryObjectFactory:105 - Not binding factory to JNDI, no JNDI name configured
15:06:41,851 DEBUG SessionFactoryImpl:340 - instantiated session factory
15:06:41,851 DEBUG SessionFactoryImpl:426 - Checking 0 named HQL queries
15:06:41,945 DEBUG SessionFactoryImpl:446 - Checking 0 named SQL queries
15:06:42,211 DEBUG SessionImpl:247 - opened session at timestamp: [telefone removido]
15:06:42,226 DEBUG IncrementGenerator:104 - fetching initial value: select max(id) from fornecedor
15:06:42,226 DEBUG AbstractBatcher:410 - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
15:06:42,226 DEBUG ConnectionManager:444 - opening JDBC connection
15:06:42,242 DEBUG SQL:111 - 
    select
        max(id) 
    from
        fornecedor
Hibernate: 
    select
        max(id) 
    from
        fornecedor
15:06:42,289 DEBUG IncrementGenerator:119 - first free id: 1
15:06:42,289 DEBUG AbstractBatcher:418 - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
15:06:42,289 DEBUG AbstractSaveEventListener:135 - generated identifier: 1, using strategy: org.hibernate.id.IncrementGenerator
15:06:42,414 DEBUG AbstractFlushingEventListener:134 - processing flush-time cascades
15:06:42,414 DEBUG AbstractFlushingEventListener:177 - dirty checking collections
15:06:42,445 DEBUG AbstractFlushingEventListener:108 - Flushed: 1 insertions, 0 updates, 0 deletions to 1 objects
15:06:42,445 DEBUG AbstractFlushingEventListener:114 - Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
15:06:42,445 DEBUG Printer:106 - listing entities:
15:06:42,445 DEBUG Printer:113 - Negocio.Fornecedor{id=1, nome=pedraummmmmm}
15:06:42,461 DEBUG AbstractBatcher:410 - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
15:06:42,461 DEBUG SQL:111 - 
    insert 
    into
        fornecedor
        (nome, id) 
    values
        (?, ?)
Hibernate: 
    insert 
    into
        fornecedor
        (nome, id) 
    values
        (?, ?)
15:06:42,461 DEBUG AbstractBatcher:66 - Executing batch size: 1
15:06:42,476 DEBUG AbstractBatcher:418 - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)

mais não inseriu nada no banco =S
e tbm implementei a interface mais continua tando o erro, eu axo que a interface e soh quando esta trabalhnado com anotaçoes noa é?

Observações (
o que significa essa tag em Fornecedor.hbm.xml

significa que o banco vai gerar auto incremento ?
ou significa que minha classe que vai gerar?

se for o banco que for gerar, é o mysql e axo que ele não tem o auto incremento esses erros pode ser algo relacionado com isso?

)

E

Pessoal preciso resolver isso com uma certa urgencia , por favor mais alguem?

rogelgarcia

Dá um session.flush… ou usa transacoes

Agora, se vc nao quer mais ter esse tipo de dor de cabeça chata… usa esse framework http://www.nextframework.org

Ele usa hibernate, mas nao dá esse tanto de pau… pq essas coisas chatas o framework já resolveu…

E

rogel ja dei um session.flush();

mesmo assim continua dando esse mesmo erro

E
olha meu metodo insert

<a class="mention" href="/u/override">@Override</a>

public void insert(Fornecedor forn) {

session.save(forn);

session.flush();

}

corrigindo meu ultimo post nao da erro apenas na inseri no banco

rogelgarcia

Agora complicou…

E

me ajudem ai pessoal por favor, necessito muito

E

Pessoal mais alguem pode me ajudar??

Criado 22 de março de 2010
Ultima resposta 23 de mar. de 2010
Respostas 15
Participantes 4