-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 
Author Message
 Post subject: Error inserting object using select GENERATOR( db trigger)
PostPosted: Wed Mar 09, 2005 12:41 pm 
Beginner
Beginner

Joined: Sat Oct 18, 2003 8:00 pm
Posts: 22
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


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 09, 2005 12:43 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
You are selecting a string from the db, your property is a long.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 09, 2005 1:01 pm 
Beginner
Beginner

Joined: Sat Oct 18, 2003 8:00 pm
Posts: 22
michael wrote:
You are selecting a string from the db, your property is a long.


No, as you can see, login property is string, that was what I put in the key param of select. What is of type long is the id, which is generated by the trigger.


<?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>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 09, 2005 1:22 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Please read again and think how the select generator actually works.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 09, 2005 1:47 pm 
Newbie

Joined: Thu Jul 08, 2004 1:10 pm
Posts: 11
I didn´t understand what´s wrong either.

Hibernate inserts the attributes NAME, LOGIN and EMAIL
Database generates the attribute ID_USER
Hibernate selects the ID_USER and should set the ID property (Long) in the class, wich is a Long.

Maybe the error is in the database?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 09, 2005 2:34 pm 
Beginner
Beginner

Joined: Sat Oct 18, 2003 8:00 pm
Posts: 22
michael wrote:
Please read again and think how the select generator actually works.


Michael

I read and I think i undertood. The example int he doc has two long fields. The id and the unique key has to be of the same type? Please clarify me.

Thanks
Emerson


Top
 Profile  
 
 Post subject: Select Generator
PostPosted: Fri Mar 18, 2005 6:16 am 
Newbie

Joined: Fri Mar 18, 2005 6:09 am
Posts: 3
I was also having a problem with the id and unique key having to be of the same type. I looked into this and found that this is a bug. I have subsequently fixed this bug and have submitted a patch that has been accepted into CVS. The changed file is org.hibernate.id.SelectGenerator. You can now have an id with a different type to the unique key.

Hope this helps.

Malcolm


Top
 Profile  
 
 Post subject: Re: Error inserting object using select GENERATOR( db trigger)
PostPosted: Fri Oct 02, 2009 10:22 am 
Newbie

Joined: Fri Oct 02, 2009 9:52 am
Posts: 2
Hello greenmj,

Can you please let me knwo how to retrieve your changed code fiel for SelectGenerator? Also is this fix available in any of the new versions of Hibernate?

Thanks


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.