This is the continuation of my last thread, related to the use of of select generator.
I changed it to sequence, that worked. I can follow what was suggested in other thread and change my trigger to see if the id is not null, so it wouldn't get the next value from sequence, letting the one that was inserted. But I wanted to use the select generator, so I'm posting the error again.
PS: i have some errors using Oracle9Dialect, related to "inner join" in the sql code.
Hibernate version:
3.0RC1
Mapping documents:
<?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="gov.tresc.admsist.model.Usuario" table="USUARIO"
schema="ADMSIST">
<id name="id" column="IDO_USUARIO" type="long" >
<generator class="select">
<param name="key">login</param>
</generator>
</id>
<property name="nome" column="NOME_USUARIO" type="string" length="70"
not-null="true"/>
<property name="login" column="LOGIN" type="string" length="70"
not-null="true"/>
<property name="email" column="E_MAIL" type="string" length="70"
not-null="true"/>
</class>
</hibernate-mapping>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.connection.url">jdbc:oracle:thin:@setubal.tre-sc.gov.br:1521:des</property>
<property name="hibernate.connection.username">admsist</property>
<property name="hibernate.connection.password">admsist</property>
<property name="dialect">org.hibernate.dialect.OracleDialect</property>
<property name="show_sql">true</property>
<property name="transaction.factory_class">
org.hibernate.transaction.JDBCTransactionFactory
</property>
<!-- property name="hibernate.hbm2ddl.auto">update</property -->
<mapping resource="gov/tresc/admsist/model/Usuario.hbm.xml"/>
<mapping resource="gov/tresc/admsist/model/Sistema.hbm.xml"/>
</session-factory>
</hibernate-configuration>
Code between sessionFactory.openSession() and session.close():
try {
ServiceLocator.currentSession().save(user);
} catch (Exception e) {
e.printStackTrace();
logger.error("Erro ao criar usuario", e);
throw new DAOException(e);
}
PS: the session is created by a servlet filter.
Full stack trace of any exception that occurs:
java.lang.ClassCastException: java.lang.String
at org.hibernate.type.LongType.set(LongType.java:40)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:62)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:44)
at org.hibernate.id.SelectGenerator.bindParameters(SelectGenerator.java:40)
at org.hibernate.id.AbstractPostInsertGenerator.getGenerated(AbstractPostInsertGenerator.java:41)
at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:1755)
at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:2149)
at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:34)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:239)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:238)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:158)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:104)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:184)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:173)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:69)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:429)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:424)
at gov.tresc.admsist.dao.DAOAdmSist.criaUsuario(DAOAdmSist.java:135)
at gov.tresc.admsist.AdmSistFacade.criaUsuario(AdmSistFacade.java:53)
at gov.tresc.admsist.struts.UsuariosCRUDAction.criarFinish(UsuariosCRUDAction.java:41)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:280)
at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:216)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at gov.tresc.hibplugin.ActionFilter.doFilter(ActionFilter.java:66)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:825)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:738)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:526)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:595)
11:45:08,028 ERROR DAOAdmSist:138 - Erro ao criar usuario
Name and version of the database you are using:
Oracle 9
The generated SQL (show_sql=true):
insert into ADMSIST.USUARIO (NOME_USUARIO, LOGIN, E_MAIL) values (?, ?, ?)
Debug level Hibernate log excerpt:
11:45:07,896 DEBUG SessionImpl:229 - opened session
11:45:07,898 DEBUG DefaultSaveOrUpdateEventListener:159 - saving transient instance
11:45:07,899 DEBUG AbstractSaveEventListener:89 - generated identifier: , using strategy: org.hibernate.id.SelectGenerator
11:45:07,900 DEBUG AbstractSaveEventListener:132 - saving [gov.tresc.admsist.model.Usuario#<null>]
11:45:07,901 DEBUG AbstractSaveEventListener:193 - executing insertions
11:45:07,917 DEBUG BasicEntityPersister:1705 - Inserting entity: gov.tresc.admsist.model.Usuario (native id)
11:45:07,926 DEBUG AbstractBatcher:258 - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
11:45:07,927 DEBUG AbstractBatcher:379 - opening JDBC connection
11:45:07,928 DEBUG DriverManagerConnectionProvider:93 - total checked-out connections: 0
11:45:07,929 DEBUG DriverManagerConnectionProvider:99 - using pooled JDBC connection, pool size: 0
11:45:07,930 DEBUG SQL:292 - insert into ADMSIST.USUARIO (NOME_USUARIO, LOGIN, E_MAIL) values (?, ?, ?)
Hibernate: insert into ADMSIST.USUARIO (NOME_USUARIO, LOGIN, E_MAIL) values (?, ?, ?)
11:45:07,930 DEBUG AbstractBatcher:343 - preparing statement
11:45:07,932 DEBUG BasicEntityPersister:1587 - Dehydrating entity: [gov.tresc.admsist.model.Usuario#<null>]
11:45:07,988 DEBUG AbstractBatcher:266 - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
11:45:07,988 DEBUG AbstractBatcher:363 - closing statement
11:45:07,990 DEBUG AbstractBatcher:258 - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
11:45:07,990 DEBUG SQL:292 - select IDO_USUARIO from ADMSIST.USUARIO where LOGIN =?
Hibernate: select IDO_USUARIO from ADMSIST.USUARIO where LOGIN =?
11:45:07,991 DEBUG AbstractBatcher:343 - preparing statement
11:45:08,009 DEBUG AbstractBatcher:266 - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
11:45:08,010 DEBUG AbstractBatcher:363 - closing statement
|