quando emite um:
session.commit()
aparece um execption e
session.rollback()
erro
quando emite um:
session.commit()
aparece um execption e
session.rollback()
erro
Confira se algo na chave de sua entidade não é null.
session.commit ???
não seria isto?
Trasaction tx = session.beginTransaction();
---
---
tx.commit(); <-- Transaction q dá commit e não a session
Abraços 8)
Wanderson
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"\\debian\doctos\downloads\hibernate\hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="agenda.Bairro" table="TBBAIR" dynamic-insert="true" dynamic-update="true" >
<id name="bairId" type="int" >
<generator class="sequence">
<param name="sequence">genBairId</param>
</generator>
</id>
<property name="bairNome" type="string" unique="true" not-null="true" />
</class>
</hibernate-mapping>
esse é o meu xml.
session.commit ???não seria isto?
Code:
Trasaction tx =
session.beginTransaction();
tx.commit(); <-- Transaction q dá commit e não a sessionAbraços
Wanderson
é isso, Wanderson, eu abreviei demais.
ai vai mais código, para poder ser analizado.
public void incluir() {
final Bairro bairro = new Bairro();
bairro.setBairNome(bairNome.getText());
bairro.setBairId(30);
Session ss = sf.openSession();
Transaction tx = null;
try {
tx = ss.beginTransaction();
ss.save(bairro);
ss.flush();
tx.commit();
} catch (RuntimeException re) {
if(tx != null) tx.rollback();
throw re;
} finally {
ss.close();
}
}
esta linha está comentada.
aqui vai o log gerado
[quote]
2005-05-18 10:15:29,265 INFO hibernate.cfg.Environment -> Hibernate 3.0.3
2005-05-18 10:15:29,265 INFO hibernate.cfg.Environment -> hibernate.properties not found
2005-05-18 10:15:29,343 INFO hibernate.cfg.Environment -> using CGLIB reflection optimizer
2005-05-18 10:15:29,343 INFO hibernate.cfg.Environment -> using JDK 1.4 java.sql.Timestamp handling
2005-05-18 10:15:29,546 INFO hibernate.cfg.Configuration -> configuring from resource: /hibernate.cfg.xml
2005-05-18 10:15:29,546 INFO hibernate.cfg.Configuration -> Configuration resource: /hibernate.cfg.xml
2005-05-18 10:15:29,796 DEBUG hibernate.cfg.Configuration -> connection.driver_class=org.firebirdsql.jdbc.FBDriver
2005-05-18 10:15:29,796 DEBUG hibernate.cfg.Configuration -> connection.url=jdbc:firebirdsql:192.168.1.100:teste.agenda
2005-05-18 10:15:29,796 DEBUG hibernate.cfg.Configuration -> connection.username=SYSDBA
2005-05-18 10:15:29,796 DEBUG hibernate.cfg.Configuration -> connection.password=masterke
2005-05-18 10:15:29,796 DEBUG hibernate.cfg.Configuration -> connection.lc_ctype=iso8859_1
2005-05-18 10:15:29,796 DEBUG hibernate.cfg.Configuration -> dialect=org.hibernate.dialect.FirebirdDialect
2005-05-18 10:15:29,796 INFO hibernate.cfg.Configuration -> Configured SessionFactory: null
2005-05-18 10:15:29,796 DEBUG hibernate.cfg.Configuration -> properties: {hibernate.connection.password=masterke, java.runtime.name=Java™ 2 Runtime Environment, Standard Edition, hibernate.connection.lc_ctype=iso8859_1, sun.boot.library.path=C:\Arquivos de programas\Java\jre1.5.0_02\bin, java.vm.version=1.5.0_02-b09, hibernate.connection.username=SYSDBA, java.vm.vendor=Sun Microsystems Inc., java.vendor.url=http://java.sun.com/, path.separator=;, java.vm.name=Java HotSpot™ Client VM, <a href="http://file.encoding.pkg=sun.io">file.encoding.pkg=sun.io</a>, user.country=BR, sun.os.patch.level=Service Pack 4, java.vm.specification.name=Java Virtual Machine Specification, user.dir=\debian\eclipse\agenda, java.runtime.version=1.5.0_02-b09, java.awt.graphicsenv=sun.awt.Win32GraphicsEnvironment, java.endorsed.dirs=C:\Arquivos de programas\Java\jre1.5.0_02\lib\endorsed, os.arch=x86, java.io.tmpdir=C:\DOCUME~1\moreira\CONFIG~1\Temp, line.separator=
, java.vm.specification.vendor=Sun Microsystems Inc., user.variant=, os.name=Windows 2000, sun.jnu.encoding=Cp1252, java.library.path=C:\Arquivos de programas\Java\jre1.5.0_02\bin;.;C:\WINNT\system32;C:\WINNT;
C:\WINNT\system32;C:\WINNT;C:\WINNT\System32\Wbem, java.specification.name=Java Platform API Specification, java.class.version=49.0, sun.management.compiler=HotSpot Client Compiler, os.version=5.0, connection.lc_ctype=iso8859_1, connection.password=masterke, user.home=C:\Documents and Settings\moreira, user.timezone=America/Sao_Paulo, connection.username=SYSDBA, java.awt.printerjob=sun.awt.windows.WPrinterJob, file.encoding=Cp1252, java.specification.version=1.5, hibernate.connection.driver_class=org.firebirdsql.jdbc.FBDriver, user.name=moreira, java.class.path=\debian\eclipse\agenda\bin;H:\sicinfo\lib\firebirdsql-full.jar;
\debian\programas\hibernate-3.0\hibernate3.jar;
\debian\programas\hibernate-3.0\lib\asm.jar;
\debian\programas\hibernate-3.0\lib\log4j-1.2.9.jar;
\debian\programas\hibernate-3.0\lib\commons-logging-1.0.4.jar;
\debian\programas\hibernate-3.0\lib\oscache-2.1.jar;
\debian\programas\hibernate-3.0\lib\cglib-2.1.jar;
\debian\programas\hibernate-3.0\lib\commons-collections-2.1.1.jar;
\debian\programas\hibernate-3.0\lib\concurrent-1.3.2.jar;
\debian\programas\hibernate-3.0\lib\dom4j-1.6.jar;
\debian\programas\hibernate-3.0\lib\jaas.jar;
\debian\programas\hibernate-3.0\lib\jta.jar;
\debian\programas\hibernate-3.0\lib\ant-swing-1.6.3.jar;
\debian\programas\hibernate-3.0\lib\ehcache-1.1.jar, java.vm.specification.version=1.0, java.home=C:\Arquivos de programas\Java\jre1.5.0_02, sun.arch.data.model=32, hibernate.dialect=org.hibernate.dialect.FirebirdDialect, hibernate.connection.url=jdbc:firebirdsql:192.168.1.100:teste.agenda, user.language=pt, java.specification.vendor=Sun Microsystems Inc., awt.toolkit=sun.awt.windows.WToolkit, hibernate.cglib.use_reflection_optimizer=true, java.vm.info=mixed mode, sharing, java.version=1.5.0_02, java.ext.dirs=C:\Arquivos de programas\Java\jre1.5.0_02\lib\ext, sun.boot.class.path=
C:\Arquivos de programas\Java\jre1.5.0_02\lib\rt.jar;
C:\Arquivos de programas\Java\jre1.5.0_02\lib\i18n.jar;
C:\Arquivos de programas\Java\jre1.5.0_02\lib\sunrsasign.jar;
C:\Arquivos de programas\Java\jre1.5.0_02\lib\jsse.jar;
C:\Arquivos de programas\Java\jre1.5.0_02\lib\jce.jar;
C:\Arquivos de programas\Java\jre1.5.0_02\lib\charsets.jar;
C:\Arquivos de programas\Java\jre1.5.0_02\classes, java.vendor=Sun Microsystems Inc., connection.driver_class=org.firebirdsql.jdbc.FBDriver, file.separator=, java.vendor.url.bug=http://java.sun.com/cgi-bin/bugreport.cgi, sun.io.unicode.encoding=UnicodeLittle, sun.cpu.endian=little, sun.desktop=windows, connection.url=jdbc:firebirdsql:192.168.1.100:teste.agenda, dialect=org.hibernate.dialect.FirebirdDialect, sun.cpu.isalist=pentium_pro+mmx pentium_pro pentium+mmx pentium i486 i386 i86}
2005-05-18 10:15:29,812 INFO hibernate.cfg.Configuration -> Mapping resource: agenda/Bairro.hbm.xml
2005-05-18 10:15:30,187 INFO hibernate.cfg.HbmBinder -> Mapping class: agenda.Bairro -> TBBAIR
2005-05-18 10:15:30,203 DEBUG hibernate.cfg.HbmBinder -> Mapped property: bairId -> bairId
2005-05-18 10:15:30,218 DEBUG hibernate.cfg.HbmBinder -> Mapped property: bairNome -> bairNome
2005-05-18 10:15:30,218 DEBUG hibernate.cfg.Configuration -> Preparing to build session factory with filters : {}
2005-05-18 10:15:30,218 INFO hibernate.cfg.Configuration -> processing extends queue
2005-05-18 10:15:30,218 INFO hibernate.cfg.Configuration -> processing collection mappings
2005-05-18 10:15:30,218 INFO hibernate.cfg.Configuration -> processing association property references
2005-05-18 10:15:30,218 INFO hibernate.cfg.Configuration -> processing foreign key constraints
2005-05-18 10:15:30,375 INFO hibernate.connection.DriverManagerConnectionProvider -> Using Hibernate built-in connection pool (not for production use!)
2005-05-18 10:15:30,375 INFO hibernate.connection.DriverManagerConnectionProvider -> Hibernate connection pool size: 20
2005-05-18 10:15:30,375 INFO hibernate.connection.DriverManagerConnectionProvider -> autocommit mode: false
2005-05-18 10:15:30,375 INFO hibernate.connection.DriverManagerConnectionProvider -> using driver: org.firebirdsql.jdbc.FBDriver at URL: jdbc:firebirdsql:192.168.1.100:teste.agenda
2005-05-18 10:15:30,375 INFO hibernate.connection.DriverManagerConnectionProvider -> connection properties: {user=SYSDBA, password=masterke, lc_ctype=iso8859_1}
2005-05-18 10:15:30,375 DEBUG hibernate.connection.DriverManagerConnectionProvider -> total checked-out connections: 0
2005-05-18 10:15:30,375 DEBUG hibernate.connection.DriverManagerConnectionProvider -> opening new JDBC connection
2005-05-18 10:15:30,421 DEBUG hibernate.connection.DriverManagerConnectionProvider -> created connection to: jdbc:firebirdsql:192.168.1.100:teste.agenda, Isolation Level: 2
2005-05-18 10:15:30,453 INFO hibernate.cfg.SettingsFactory -> RDBMS: Firebird, version: LI-V6.3.1.4481 Firebird 1.5
2005-05-18 10:15:30,453 INFO hibernate.cfg.SettingsFactory -> JDBC driver: JayBird JCA/JDBC driver, version: 1.5
2005-05-18 10:15:30,453 DEBUG hibernate.connection.DriverManagerConnectionProvider -> returning connection to pool, pool size: 1
2005-05-18 10:15:30,515 INFO hibernate.dialect.Dialect -> Using dialect: org.hibernate.dialect.FirebirdDialect
2005-05-18 10:15:30,531 INFO hibernate.transaction.TransactionFactoryFactory -> Using default transaction strategy (direct JDBC transactions)
2005-05-18 10:15:30,531 INFO hibernate.transaction.TransactionManagerLookupFactory -> No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
2005-05-18 10:15:30,531 INFO hibernate.cfg.SettingsFactory -> Automatic flush during beforeCompletion(): disabled
2005-05-18 10:15:30,531 INFO hibernate.cfg.SettingsFactory -> Automatic session close at end of transaction: disabled
2005-05-18 10:15:30,531 INFO hibernate.cfg.SettingsFactory -> Scrollable result sets: enabled
2005-05-18 10:15:30,531 DEBUG hibernate.cfg.SettingsFactory -> Wrap result sets: disabled
2005-05-18 10:15:30,531 INFO hibernate.cfg.SettingsFactory -> JDBC3 getGeneratedKeys(): disabled
2005-05-18 10:15:30,531 INFO hibernate.cfg.SettingsFactory -> Connection release mode: null
2005-05-18 10:15:30,531 INFO hibernate.cfg.SettingsFactory -> Default batch fetch size: 1
2005-05-18 10:15:30,531 INFO hibernate.cfg.SettingsFactory -> Generate SQL with comments: disabled
2005-05-18 10:15:30,531 INFO hibernate.cfg.SettingsFactory -> Order SQL updates by primary key: disabled
2005-05-18 10:15:30,531 INFO hibernate.cfg.SettingsFactory -> Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
2005-05-18 10:15:30,546 INFO hql.ast.ASTQueryTranslatorFactory -> Using ASTQueryTranslatorFactory
2005-05-18 10:15:30,546 INFO hibernate.cfg.SettingsFactory -> Query language substitutions: {}
2005-05-18 10:15:30,546 INFO hibernate.cfg.SettingsFactory -> Second-level cache: enabled
2005-05-18 10:15:30,546 INFO hibernate.cfg.SettingsFactory -> Query cache: disabled
2005-05-18 10:15:30,546 INFO hibernate.cfg.SettingsFactory -> Cache provider: org.hibernate.cache.EhCacheProvider
2005-05-18 10:15:30,562 INFO hibernate.cfg.SettingsFactory -> Optimize cache for minimal puts: disabled
2005-05-18 10:15:30,562 INFO hibernate.cfg.SettingsFactory -> Structured second-level cache entries: enabled
2005-05-18 10:15:30,562 DEBUG hibernate.exception.SQLExceptionConverterFactory -> Using dialect defined converter
2005-05-18 10:15:30,578 INFO hibernate.cfg.SettingsFactory -> Statistics: disabled
2005-05-18 10:15:30,578 INFO hibernate.cfg.SettingsFactory -> Deleted entity synthetic identifier rollback: disabled
2005-05-18 10:15:30,578 INFO hibernate.cfg.SettingsFactory -> Default entity-mode: pojo
2005-05-18 10:15:30,843 INFO hibernate.impl.SessionFactoryImpl -> building session factory
2005-05-18 10:15:30,843 DEBUG hibernate.impl.SessionFactoryImpl -> Session factory constructed with filter configurations : {}
2005-05-18 10:15:30,843 DEBUG hibernate.impl.SessionFactoryImpl -> instantiating session factory with properties: {hibernate.connection.password=masterke, java.runtime.name=Java™ 2 Runtime Environment, Standard Edition, hibernate.connection.lc_ctype=iso8859_1, sun.boot.library.path=C:\Arquivos de programas\Java\jre1.5.0_02\bin, java.vm.version=1.5.0_02-b09, hibernate.connection.username=SYSDBA, java.vm.vendor=Sun Microsystems Inc., java.vendor.url=http://java.sun.com/, path.separator=;, java.vm.name=Java HotSpot™ Client VM, <a href="http://file.encoding.pkg=sun.io">file.encoding.pkg=sun.io</a>, user.country=BR, sun.os.patch.level=Service Pack 4, java.vm.specification.name=Java Virtual Machine Specification, user.dir=\debian\eclipse\agenda, java.runtime.version=1.5.0_02-b09, java.awt.graphicsenv=sun.awt.Win32GraphicsEnvironment, java.endorsed.dirs=C:\Arquivos de programas\Java\jre1.5.0_02\lib\endorsed, os.arch=x86, java.io.tmpdir=C:\DOCUME~1\moreira\CONFIG~1\Temp, line.separator=
, java.vm.specification.vendor=Sun Microsystems Inc., user.variant=, os.name=Windows 2000, sun.jnu.encoding=Cp1252, java.library.path=
C:\Arquivos de programas\Java\jre1.5.0_02\bin;.;
C:\WINNT\system32;C:\WINNT;C:\WINNT\system32;C:\WINNT;
C:\WINNT\System32\Wbem, java.specification.name=Java Platform API Specification, java.class.version=49.0, sun.management.compiler=HotSpot Client Compiler, os.version=5.0, connection.lc_ctype=iso8859_1, connection.password=masterke, user.home=C:\Documents and Settings\moreira, user.timezone=America/Sao_Paulo, connection.username=SYSDBA, java.awt.printerjob=sun.awt.windows.WPrinterJob, file.encoding=Cp1252, java.specification.version=1.5, hibernate.connection.driver_class=org.firebirdsql.jdbc.FBDriver, user.name=moreira, java.class.path=
\debian\eclipse\agenda\bin;
H:\sicinfo\lib\firebirdsql-full.jar;
\debian\programas\hibernate-3.0\hibernate3.jar;
\debian\programas\hibernate-3.0\lib\asm.jar;
\debian\programas\hibernate-3.0\lib\log4j-1.2.9.jar;
\debian\programas\hibernate-3.0\lib\commons-logging-1.0.4.jar;
\debian\programas\hibernate-3.0\lib\oscache-2.1.jar;
\debian\programas\hibernate-3.0\lib\cglib-2.1.jar;
\debian\programas\hibernate-3.0\lib\commons-collections-2.1.1.jar;
\debian\programas\hibernate-3.0\lib\concurrent-1.3.2.jar;
\debian\programas\hibernate-3.0\lib\dom4j-1.6.jar;
\debian\programas\hibernate-3.0\lib\jaas.jar;
\debian\programas\hibernate-3.0\lib\jta.jar;
\debian\programas\hibernate-3.0\lib\ant-swing-1.6.3.jar;
\debian\programas\hibernate-3.0\lib\ehcache-1.1.jar, java.vm.specification.version=1.0, java.home=C:\Arquivos de programas\Java\jre1.5.0_02, sun.arch.data.model=32, hibernate.dialect=org.hibernate.dialect.FirebirdDialect, hibernate.connection.url=jdbc:firebirdsql:192.168.1.100:teste.agenda, user.language=pt, java.specification.vendor=Sun Microsystems Inc., awt.toolkit=sun.awt.windows.WToolkit, hibernate.cglib.use_reflection_optimizer=true, java.vm.info=mixed mode, sharing, java.version=1.5.0_02, java.ext.dirs=C:\Arquivos de programas\Java\jre1.5.0_02\lib\ext, sun.boot.class.path=C:\Arquivos de programas\Java\jre1.5.0_02\lib\rt.jar;C:\Arquivos de programas\Java\jre1.5.0_02\lib\i18n.jar;C:\Arquivos de programas\Java\jre1.5.0_02\lib\sunrsasign.jar;C:\Arquivos de programas\Java\jre1.5.0_02\lib\jsse.jar;C:\Arquivos de programas\Java\jre1.5.0_02\lib\jce.jar;C:\Arquivos de programas\Java\jre1.5.0_02\lib\charsets.jar;C:\Arquivos de programas\Java\jre1.5.0_02\classes, java.vendor=Sun Microsystems Inc., connection.driver_class=org.firebirdsql.jdbc.FBDriver, file.separator=, java.vendor.url.bug=http://java.sun.com/cgi-bin/bugreport.cgi, sun.io.unicode.encoding=UnicodeLittle, sun.cpu.endian=little, sun.desktop=windows, connection.url=jdbc:firebirdsql:192.168.1.100:teste.agenda, dialect=org.hibernate.dialect.FirebirdDialect, sun.cpu.isalist=pentium_pro+mmx pentium_pro pentium+mmx pentium i486 i386 i86}
2005-05-18 10:15:30,843 DEBUG sf.ehcache.CacheManager -> Creating new CacheManager with default config
2005-05-18 10:15:30,859 DEBUG sf.ehcache.CacheManager -> Configuring ehcache from classpath.
2005-05-18 10:15:30,859 WARN ehcache.config.Configurator -> No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file://debian/programas/hibernate-3.0/lib/ehcache-1.1.jar!/ehcache-failsafe.xml
2005-05-18 10:15:30,875 DEBUG ehcache.config.Configuration$DiskStore -> Disk Store Path: C:\DOCUME~1\moreira\CONFIG~1\Temp
2005-05-18 10:15:31,468 DEBUG persister.entity.BasicEntityPersister -> Static SQL for entity: agenda.Bairro
2005-05-18 10:15:31,468 DEBUG persister.entity.BasicEntityPersister -> Version select: select bairId from TBBAIR where bairId =?
2005-05-18 10:15:31,468 DEBUG persister.entity.BasicEntityPersister -> Snapshot select: select bairro_.bairId, bairro_.bairNome as bairNome0_ from TBBAIR bairro_ where bairro_.bairId=?
2005-05-18 10:15:31,468 DEBUG persister.entity.BasicEntityPersister -> Insert 0: insert into TBBAIR (bairNome, bairId) values (?, ?)
2005-05-18 10:15:31,468 DEBUG persister.entity.BasicEntityPersister -> Update 0: update TBBAIR set bairNome=? where bairId=?
2005-05-18 10:15:31,468 DEBUG persister.entity.BasicEntityPersister -> Delete 0: delete from TBBAIR where bairId=?
2005-05-18 10:15:31,515 DEBUG loader.entity.EntityLoader -> Static select for entity agenda.Bairro: select bairro0_.bairId as bairId0_, bairro0_.bairNome as bairNome0_0_ from TBBAIR bairro0_ where bairro0_.bairId=?
2005-05-18 10:15:31,515 DEBUG loader.entity.EntityLoader -> Static select for entity agenda.Bairro: select bairro0_.bairId as bairId0_, bairro0_.bairNome as bairNome0_0_ from TBBAIR bairro0_ where bairro0_.bairId=?
2005-05-18 10:15:31,515 DEBUG loader.entity.EntityLoader -> Static select for entity agenda.Bairro: select bairro0_.bairId as bairId0_, bairro0_.bairNome as bairNome0_0_ from TBBAIR bairro0_ where bairro0_.bairId=? with lock
2005-05-18 10:15:31,515 DEBUG loader.entity.EntityLoader -> Static select for entity agenda.Bairro: select bairro0_.bairId as bairId0_, bairro0_.bairNome as bairNome0_0_ from TBBAIR bairro0_ where bairro0_.bairId=? with lock
2005-05-18 10:15:31,515 DEBUG hibernate.impl.SessionFactoryObjectFactory -> initializing class SessionFactoryObjectFactory
2005-05-18 10:15:31,531 DEBUG hibernate.impl.SessionFactoryObjectFactory -> registered: 402881e903eff1cb0103eff1cf3b0000 (unnamed)
2005-05-18 10:15:31,531 INFO hibernate.impl.SessionFactoryObjectFactory -> Not binding factory to JNDI, no JNDI name configured
2005-05-18 10:15:31,531 DEBUG hibernate.impl.SessionFactoryImpl -> instantiated session factory
2005-05-18 10:15:31,531 INFO hibernate.impl.SessionFactoryImpl -> Checking 0 named queries
2005-05-18 10:15:50,531 DEBUG hibernate.impl.SessionImpl -> opened session at timestamp: 4572865128316928
2005-05-18 10:15:50,531 DEBUG hibernate.transaction.JDBCTransaction -> begin
2005-05-18 10:15:50,531 DEBUG hibernate.jdbc.AbstractBatcher -> opening JDBC connection
2005-05-18 10:15:50,531 DEBUG hibernate.connection.DriverManagerConnectionProvider -> total checked-out connections: 0
2005-05-18 10:15:50,531 DEBUG hibernate.connection.DriverManagerConnectionProvider -> using pooled JDBC connection, pool size: 0
2005-05-18 10:15:50,531 DEBUG hibernate.transaction.JDBCTransaction -> current autocommit status: false
2005-05-18 10:15:50,546 DEBUG event.def.DefaultSaveOrUpdateEventListener -> saving transient instance
2005-05-18 10:15:50,546 DEBUG hibernate.jdbc.AbstractBatcher -> about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
2005-05-18 10:15:50,546 DEBUG org.hibernate.SQL -> select gen_id( genBairId, 1 ) from RDB$DATABASE
2005-05-18 10:15:50,546 DEBUG hibernate.jdbc.AbstractBatcher -> preparing statement
2005-05-18 10:15:50,734 DEBUG hibernate.id.SequenceGenerator -> Sequence identifier generated: 24
2005-05-18 10:15:50,734 DEBUG hibernate.jdbc.AbstractBatcher -> about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
2005-05-18 10:15:50,734 DEBUG hibernate.jdbc.AbstractBatcher -> closing statement
2005-05-18 10:15:50,734 DEBUG event.def.AbstractSaveEventListener -> generated identifier: 24, using strategy: org.hibernate.id.SequenceGenerator
2005-05-18 10:15:50,734 DEBUG event.def.AbstractSaveEventListener -> saving [agenda.Bairro#24]
2005-05-18 10:15:50,765 DEBUG event.def.AbstractFlushingEventListener -> flushing session
2005-05-18 10:15:50,765 DEBUG event.def.AbstractFlushingEventListener -> processing flush-time cascades
2005-05-18 10:15:50,765 DEBUG event.def.AbstractFlushingEventListener -> dirty checking collections
2005-05-18 10:15:50,765 DEBUG event.def.AbstractFlushingEventListener -> Flushing entities and processing referenced collections
2005-05-18 10:15:53,125 DEBUG hibernate.transaction.JDBCTransaction -> rollback
2005-05-18 10:15:53,125 DEBUG hibernate.jdbc.JDBCContext -> before transaction completion
2005-05-18 10:15:53,125 DEBUG hibernate.impl.SessionImpl -> before transaction completion
2005-05-18 10:15:53,140 DEBUG hibernate.transaction.JDBCTransaction -> rolled back JDBC Connection
2005-05-18 10:15:53,140 DEBUG hibernate.jdbc.JDBCContext -> after transaction completion
2005-05-18 10:15:53,140 DEBUG hibernate.impl.SessionImpl -> after transaction completion
2005-05-18 10:15:53,140 DEBUG hibernate.impl.SessionImpl -> closing session
2005-05-18 10:15:53,140 DEBUG hibernate.jdbc.AbstractBatcher -> closing JDBC connection (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)
Exception in thread “AWT-EventQueue-0” org.hibernate.HibernateException: identifier of an instance of agenda.Bairro altered from 24 to 24
at org.hibernate.event.def.DefaultFlushEntityEventListener.checkId(DefaultFlushEntityEventListener.java:51)
at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:82)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:190)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:70)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:726)
at agenda.BairroCadastro.setIncluir(BairroCadastro.java:56)
at meujava.MComandoSalvar.actionPerformed(MComandoSalvar.java:28)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
2005-05-18 10:15:53,140 DEBUG hibernate.connection.DriverManagerConnectionProvider -> returning connection to pool, pool size: 1
2005-05-18 10:15:53,140 DEBUG hibernate.jdbc.JDBCContext -> after transaction completion
2005-05-18 10:15:53,140 DEBUG hibernate.impl.SessionImpl -> after transaction completion
Amiguinho, troque sequence por native.
Vamos ver o q acontece.
Sequence segundo uma resposta q li aqui no guj, quando é carregado o hibernate ele pega o ultimo numero id (campo sequencial) da tabela.
Não sei se é isto, mas troque para a gente ver.
Eu achava q tinha a ver com sequences do Oracle, Postgresql… agora sei lá…
Qq coisa poste o erro ai de novo.
Abraços
Wanderson
colocque
<param name="native">genBairId</param>
quando uso native aparece esse erro
Caused by: org.firebirdsql.jdbc.FBSQLException: GDS Exception. 335544343. invalid request BLR at offset 78
generator HIBERNATE_SEQUENCE is not defined
Meu amigo, percebi em seu dialeto que vc esta utilizando firebird.
Esse exemplo deve referir-se ao postgres ou outro banco que ofereça suporte a sequence. No firebird vc precisa fazer xunxos com trigger.
Tente fazer o seguinte atribuindo a id manualmente:
<generator class=“assigned”/>
sequence
uses a sequence in DB2, PostgreSQL, Oracle, SAP DB, McKoi or a generator in Interbase. The returned
identifier is of type long, short or int
/*
* Created on 14/05/2005 21:56:23
*/
package agenda;
public class Bairro {
private long bairId;
private String bairNome;
public long getBairId() { return bairId; }
public void setBairId(long arg0) { bairId = arg0; }
public String getBairNome() { return bairNome; }
public void setBairNome(String arg0) { bairNome = arg0; }
}
questão resolvida, (com a ajuda direta do LIPE, e a aparticipação do pessoal do guj, que me dão a oportunidade de participar dela)
na classe Bairro.class
substitui o tipo primitivo de bairId - int para o objeto Integer,
e em bairro.hbm.xml
substitui em <id type=“int”…> para <id type=“java.lang.Integer”…>
valeu.
Só pra constar.
Acho muito melhor utilizar os wrappers ao invés dos tipod primitivos.