-->
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.  [ 5 posts ] 
Author Message
 Post subject: Strange error while using a different kind of association
PostPosted: Fri Dec 09, 2005 11:46 am 
Newbie

Joined: Sun Nov 20, 2005 8:08 pm
Posts: 10
I have a entity called Usuario as described below:

Code:
<?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="br.gov.go.tj.integra.entidades.Usuario"
            table="josso_usuario">
    <id name="codigo" column="codigo">
        <generator class="sequence">
           <param name="sequence">
               josso_usuario_codigo_seq
           </param>
       <generator/>
    </id>
      <property  name="usuario"  column="usuario"  />
      <property name="senha"   column="senha" />
      <property name="descricao" column="descricao" />
      <property name="nome"  column="nome" />
      <set  name="detalhes" lazy="true"  cascade="all">
            <key  column="codigo_usuario" / >
            <one-to-many  class="br.gov.go.tj.integra.entidades.Detalhe" />
      </set>
  </class>   

   <query  name="pesquisarUsuarioPorNome">
            <![CDATA[from Usuario where nome like concat(?, '%') order by nome]]>
    </query>

    <query name="pesquisarUsuarioPorCodigo">
            <![CDATA[from Usuario where codigo = ?]]>
    </query>

</hibernate-mapping>


and Detalhe entity as described below:

Code:
<?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="br.gov.go.tj.integra.entidades.Detalhe"         table="josso_usuario_detalhe">

    <composite-id unsaved-value="undefined">
            <key-many-to-one name="usuario"
                    class="br.gov.go.tj.integra.entidades.Usuario"
                    column="codigo_usuario"/>
            <key-many-to-one name="sistema"
                    class="br.gov.go.tj.integra.entidades.Sistema"
                    column="codigo_sistema" />
            <key-many-to-one name="perfil"
                    class="br.gov.go.tj.integra.entidades.Perfil"
                    column="codigo_perfil" />
    </composite-id>

        <many-to-one name="usuario" column="codigo_usuario" not-null="true"
                outer-join="true" fetch="join" insert="false" update="false"/>
        <many-to-one name="sistema" column="codigo_sistema" not-null="true"
                outer-join="true" fetch="join" insert="false" update="false" />
        <many-to-one name="perfil" column="codigo_perfil" not-null="true"
                outer-join="true" fetch="join" insert="false" update="false" />
    </class>   

</hibernate-mapping>


but when i try to do this:

Usuario usuario = new Usuario();
usuario.setCodigo(1);
usuario.setDetalhes(detalhesSet);
tx.commit();

i get this error:

Hibernate: select nextval ('
josso_usuario_codigo_seq
')
Hibernate: select detalhe_.codigo_usuario, detalhe_.codigo_sistema, detalhe_.codigo_perfil from josso_usuario_detalhe detalhe_ where detalhe_.codigo_usuario=? and detalhe_.codigo_sistema=? and detalhe_.codigo_perfil=?
Hibernate: insert into josso_usuario (usuario, senha, descricao, nome, codigo) values (?, ?, ?, ?, ?)
Hibernate: insert into josso_usuario_detalhe (codigo_usuario, codigo_sistema, codigo_perfil) values (?, ?, ?)
09/12/2005 13:38:14 org.hibernate.util.JDBCExceptionReporter logExceptions
WARNING: SQL Error: 0, SQLState: null
09/12/2005 13:38:14 org.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: Entrada em lote 0 insert into josso_usuario_detalhe (codigo_usuario, codigo_sistema, codigo_perfil) values (NULL, 1, 2) foi abortada. Chame getNextException para ver a causa.
09/12/2005 13:38:14 org.hibernate.util.JDBCExceptionReporter logExceptions
WARNING: SQL Error: 0, SQLState: 23502
09/12/2005 13:38:14 org.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: ERROR: null value in column "codigo_usuario" violates not-null constraint
09/12/2005 13:38:14 org.hibernate.event.def.AbstractFlushingEventListener performExecutions
SEVERE: Could not synchronize database state with session
org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:69)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:200)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:230)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:296)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:905)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:345)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at br.gov.go.tj.integra.pagebeans.FormUsuario.gravarUsuario(FormUsuario.java:182)
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.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:129)
at org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:63)
at javax.faces.component.UICommand.broadcast(UICommand.java:106)
at javax.faces.component.UIViewRoot._broadcastForPhase(UIViewRoot.java:90)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:164)
at org.apache.myfaces.lifecycle.LifecycleImpl.invokeApplication(LifecycleImpl.java:316)
at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:86)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:106)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.myfaces.component.html.util.ExtensionsFilter.doFilter(ExtensionsFilter.java:122)
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:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:514)
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:868)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:663)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
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)
Caused by: java.sql.BatchUpdateException: Entrada em lote 0 insert into josso_usuario_detalhe (codigo_usuario, codigo_sistema, codigo_perfil) values (NULL, 1, 2) foi abortada. Chame getNextException para ver a causa.
at org.postgresql.jdbc2.AbstractJdbc2Statement$BatchResultHandler.handleError(AbstractJdbc2Statement.java:2423)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1268)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:345)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeBatch(AbstractJdbc2Statement.java:2485)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:58)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:193)
... 38 more

so to avoid this error i tried this:

Usuario usuario = new Usuario();
usuario.setCodigo(this.codigo);
if(detalhes != null)
{
HashSet tempDetalhes = new HashSet();
for(Iterator it = detalhes.iterator(); it.hasNext();)
{
Detalhe detalhe = (Detalhe) it.next();
detalhe.setUsuario(usuario);
tempDetalhes.add(detalhe);
}
usuario.setDetalhes(tempDetalhes);
}
tx.commit();

and this works very nice when i call session.save(usuario), but when i call session.delete(usuario) or session.update(usuario) i'm always getting this error:

Hibernate: select detalhe_.codigo_usuario, detalhe_.codigo_sistema, detalhe_.codigo_perfil from josso_usuario_detalhe detalhe_ where detalhe_.codigo_usuario=? and detalhe_.codigo_sistema=? and detalhe_.codigo_perfil=?
Hibernate: select detalhe_.codigo_usuario, detalhe_.codigo_sistema, detalhe_.codigo_perfil from josso_usuario_detalhe detalhe_ where detalhe_.codigo_usuario=? and detalhe_.codigo_sistema=? and detalhe_.codigo_perfil=?
Hibernate: insert into josso_usuario_detalhe (codigo_usuario, codigo_sistema, codigo_perfil) values (?, ?, ?)
Hibernate: update josso_usuario set usuario=?, senha=?, descricao=?, nome=? where codigo=?
Hibernate: update josso_usuario_detalhe set codigo_usuario=null where codigo_usuario=?
09/12/2005 13:45:27 org.hibernate.util.JDBCExceptionReporter logExceptions
WARNING: SQL Error: 0, SQLState: null
09/12/2005 13:45:27 org.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: Entrada em lote 0 update josso_usuario_detalhe set codigo_usuario=null where codigo_usuario=9 foi abortada. Chame getNextException para ver a causa.
09/12/2005 13:45:27 org.hibernate.util.JDBCExceptionReporter logExceptions
WARNING: SQL Error: 0, SQLState: 23502
09/12/2005 13:45:27 org.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: ERROR: null value in column "codigo_usuario" violates not-null constraint
09/12/2005 13:45:27 org.hibernate.event.def.AbstractFlushingEventListener performExecutions
SEVERE: Could not synchronize database state with session
org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:69)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:200)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:230)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:142)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:296)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:905)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:345)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at br.gov.go.tj.integra.pagebeans.FormUsuario.gravarUsuario(FormUsuario.java:181)
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.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:129)
at org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:63)
at javax.faces.component.UICommand.broadcast(UICommand.java:106)
at javax.faces.component.UIViewRoot._broadcastForPhase(UIViewRoot.java:90)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:164)
at org.apache.myfaces.lifecycle.LifecycleImpl.invokeApplication(LifecycleImpl.java:316)
at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:86)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:106)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.myfaces.component.html.util.ExtensionsFilter.doFilter(ExtensionsFilter.java:122)
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:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:514)
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:868)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:663)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
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)
Caused by: java.sql.BatchUpdateException: Entrada em lote 0 update josso_usuario_detalhe set codigo_usuario=null where codigo_usuario=9 foi abortada. Chame getNextException para ver a causa.
at org.postgresql.jdbc2.AbstractJdbc2Statement$BatchResultHandler.handleError(AbstractJdbc2Statement.java:2423)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1268)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:345)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeBatch(AbstractJdbc2Statement.java:2485)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:58)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:193)
... 38 more

why codigo_usuario is null in set clause and has a value in where clause?
Please i need a light to solve this, this is the only way that i found to make the things works here. I'm using Hibernate 3.0.5 .
Sorry about large post.




[/b]


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 09, 2005 7:18 pm 
Newbie

Joined: Sun Nov 20, 2005 8:08 pm
Posts: 10
I'm still trying to solve my problem, but no sucess...


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 10, 2005 6:46 pm 
Newbie

Joined: Sun Nov 20, 2005 8:08 pm
Posts: 10
Please somebody help this poor soul.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 10, 2005 6:51 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
If your posting (or a question you are referring to) was not answered by anybody, the possible reasons are:

- http://www.hibernate.org/ForumMailingli ... AskForHelp
- You did not submit enough information
- Nobody knows the answer or has the free time to answer

What you can do now:

- Do the things listed in After Posting
- Add missing and/or more information
- Consider commercial support for guaranteed expert response times

This is a high-traffic forum run by volunteers with hundreds of postings made every day. The community works because people try to help others in their free time. Nobody is paid for this service or has to pay.

You should not expect a timely response and you should not rely on a public community forum for critical cases.

All community members should respect the rules of this forum and treat others like they would prefer to be treated.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 10, 2005 7:07 pm 
Newbie

Joined: Sun Nov 20, 2005 8:08 pm
Posts: 10
Thanks for your help, but i'll use only SQL to solve this problem, i checked the docs, asked some guys in IRC, searched in google, tried to use surrogate keys, but not sucess...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.