When I try to insert a composite object with 2 or more objects, I have the error described.
Hibernate version:
3.0
Mapping documents:
Code:
<hibernate-mapping>
<class name="src.model.PecaEstrutural" table="PECA_ESTRUTURAL">
<id name="id" column="PECA_ESTRUTURAL_ID">
<generator class="sequence">
<param name="sequence">PECA_ESTRUTURAL_GEN</param>
</generator>
</id>
<discriminator column="TIPO"/>
<version name="versao" column="VERSAO" />
<property name="descricao" unique="true" not-null="true" />
<property name="quantidadeCharutos" column="QTD_CHARUTOS" not-null="true" />
<idbag name="itens" lazy="true" cascade="all-delete-orphan"
table="ITEM_PECA_ESTRUTURAL">
<collection-id type="integer"
column="ITEM_PECA_ESTRUTURAL_ID">
<generator class="sequence">
<param name="sequence">
ITEM_PECA_ESTRUTURAL_GEN
</param>
</generator>
</collection-id>
<key column="PECA_ESTRUTURAL_ID" not-null="true" />
<composite-element class="src.model.ItemPecaEstrutural">
<property name="quantidade" />
<property name="total" />
<many-to-one name="descricaoMaterial" column="DESCRICAO_MATERIAL_ID" />
</composite-element>
</idbag>
<subclass
name="src.model.Tesoura"
discriminator-value="Tesoura">
</subclass>
<subclass
name="src.model.Portico"
discriminator-value="Portico">
</subclass>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():Code:
Session sessao = HibernateUtil.getSession();
Transaction trans = sessao.beginTransaction();
//cria objeto composto
PecaEstrutural pecaEstrutural = new Portico();
pecaEstrutural.setDescricao("Portico teste 50metros de vão");
pecaEstrutural.setQuantidadeCharutos(4);
sessao.saveOrUpdate(pecaEstrutural);
List lista = pecaEstrutural.getItens();
//cria primeira composição
ItemPecaEstrutural item1 = new ItemPecaEstrutural();
item1.setQuantidade(44);
item1.setTotal(new BigDecimal("334.43"));
DescricaoMaterial descricaoMaterial1 = new DescricaoMaterial();
sessao.load(descricaoMaterial1,new Integer(1));
item1.setDescricaoMaterial(descricaoMaterial1);
pecaEstrutural.addItem(item1);
//cria segunda composição
ItemPecaEstrutural item2 = new ItemPecaEstrutural();
item2.setQuantidade(34);
item2.setTotal(new BigDecimal("4.43"));
DescricaoMaterial descricaoMaterial2 = new DescricaoMaterial();
sessao.load(descricaoMaterial2,new Integer(2));
item2.setDescricaoMaterial(descricaoMaterial2);
pecaEstrutural.addItem(item2);
Integer pk = pecaEstrutural.getId();
trans.commit();
sessao.close();
Full stack trace of any exception that occurs:Code:
Initializing c3p0 pool... com.mchange.v2.c3p0.PoolBackedDataSource@134263a [ connectionPoolDataSource -> com.mchange.v2.c3p0.WrapperConnectionPoolDataSource@5db5ae [ acquireIncrement -> 1, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, idleConnectionTestPeriod -> 3000, initialPoolSize -> 5, maxIdleTime -> 300, maxPoolSize -> 20, maxStatements -> 50, maxStatementsPerConnection -> 0, minPoolSize -> 5, nestedDataSource -> com.mchange.v2.c3p0.DriverManagerDataSource@2d59a3 [ description -> null, driverClass -> null, factoryClassLocation -> null, jdbcUrl -> jdbc:firebirdsql://servidor:3050/c:\SOR\BANCO.FDB, properties -> {user=******, password=******, lc_ctype=WIN1252} ] , preferredTestQuery -> null, propertyCycle -> 300, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, usesTraditionalReflectiveProxies -> false ] , factoryClassLocation -> null, numHelperThreads -> 3, poolOwnerIdentityToken -> 134263a ]
11:04:27,695Hibernate: select gen_id( PECA_ESTRUTURAL_GEN, 1 ) from RDB$DATABASE
Hibernate: select descricaom0_.DESCRICAO_MATERIAL_ID as DESCRICAO1_0_, descricaom0_.VERSAO as VERSAO2_0_, descricaom0_.nome as nome2_0_, descricaom0_.UNIDADE_MEDIDA as UNIDADE4_2_0_ from DESCRICAO_MATERIAL descricaom0_ where descricaom0_.DESCRICAO_MATERIAL_ID=?
Hibernate: insert into PECA_ESTRUTURAL (VERSAO, descricao, QTD_CHARUTOS, TIPO, PECA_ESTRUTURAL_ID) values (?, ?, ?, 'Portico', ?)
Hibernate: select gen_id(
ITEM_PECA_ESTRUTURAL_GEN
, 1 ) from RDB$DATABASE
Hibernate: insert into ITEM_PECA_ESTRUTURAL (PECA_ESTRUTURAL_ID, ITEM_PECA_ESTRUTURAL_ID, quantidade, total, DESCRICAO_MATERIAL_ID) values (?, ?, ?, ?, ?)
Hibernate: select descricaom0_.DESCRICAO_MATERIAL_ID as DESCRICAO1_0_, descricaom0_.VERSAO as VERSAO2_0_, descricaom0_.nome as nome2_0_, descricaom0_.UNIDADE_MEDIDA as UNIDADE4_2_0_ from DESCRICAO_MATERIAL descricaom0_ where descricaom0_.DESCRICAO_MATERIAL_ID=?
Hibernate: update PECA_ESTRUTURAL set VERSAO=?, descricao=?, QTD_CHARUTOS=? where PECA_ESTRUTURAL_ID=? and VERSAO=?
Hibernate: select gen_id(
ITEM_PECA_ESTRUTURAL_GEN
, 1 ) from RDB$DATABASE
Problem with checked-in Statement, discarding.
java.lang.NullPointerException
at org.firebirdsql.jdbc.AbstractPreparedStatement.clearParameters(AbstractPreparedStatement.java:349)
at com.mchange.v2.c3p0.stmt.GooGooStatementCache.refreshStatement(GooGooStatementCache.java:410)
at com.mchange.v2.c3p0.stmt.GooGooStatementCache.checkinStatement(GooGooStatementCache.java:129)
at com.mchange.v2.c3p0.impl.NewPooledConnection.checkinStatement(NewPooledConnection.java:143)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.close(NewProxyPreparedStatement.java:1670)
at org.hibernate.jdbc.AbstractBatcher.closePreparedStatement(AbstractBatcher.java:393)
at org.hibernate.jdbc.AbstractBatcher.closeStatement(AbstractBatcher.java:195)
at org.hibernate.id.SequenceGenerator.generate(SequenceGenerator.java:91)
at org.hibernate.collection.PersistentIdentifierBag.preInsert(PersistentIdentifierBag.java:294)
at org.hibernate.persister.collection.AbstractCollectionPersister.insertRows(AbstractCollectionPersister.java:1007)
at org.hibernate.action.CollectionUpdateAction.execute(CollectionUpdateAction.java:48)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:239)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:223)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:139)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274)11:04:48,69511:04:48,695
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:675)
at src.testeGerenciarPecaEstrutural.main(testeGerenciarPecaEstrutural.java:53)
org.firebirdsql.jdbc.FBSQLException: This statement is already closed.
at org.firebirdsql.jdbc.AbstractStatement.close(AbstractStatement.java:225)
at com.mchange.v1.db.sql.StatementUtils.attemptClose(StatementUtils.java:38)
at com.mchange.v2.c3p0.stmt.GooGooStatementCache$1.run(GooGooStatementCache.java:246)
at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:354)
11:04:48,715org.hibernate.exception.GenericJDBCException: could not get next sequence value
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:82)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:70)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.id.SequenceGenerator.generate(SequenceGenerator.java:96)
at org.hibernate.collection.PersistentIdentifierBag.preInsert(PersistentIdentifierBag.java:294)
at org.hibernate.persister.collection.AbstractCollectionPersister.insertRows(AbstractCollectionPersister.java:1007)
at org.hibernate.action.CollectionUpdateAction.execute(CollectionUpdateAction.java:48)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:239)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:223)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:139)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:675)
at src.testeGerenciarPecaEstrutural.main(testeGerenciarPecaEstrutural.java:53)
Caused by: org.firebirdsql.jdbc.FBSQLException: This statement is already closed.
at org.firebirdsql.jdbc.AbstractStatement.close(AbstractStatement.java:225)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.close(NewProxyPreparedStatement.java:1674)
at org.hibernate.jdbc.AbstractBatcher.closePreparedStatement(AbstractBatcher.java:393)
at org.hibernate.jdbc.AbstractBatcher.closeStatement(AbstractBatcher.java:195)
at org.hibernate.id.SequenceGenerator.generate(SequenceGenerator.java:91)
... 10 more
Name and version of the database you are using:
Firebird 1.5