Lucas_Lacerda_Gertel 19 de jun. de 2008
Coloque no id:
@GeneratedValue ( strategy = GenerationType . IDENTITY )
Qq coisa posta teu código.
Abraços
diogoprosoft 19 de jun. de 2008
Obrigado por ter me ajudado, agora deu esse erro
HTTP Status 500 -
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request .
exception
javax . servlet . ServletException : org . hibernate . StaleStateException : Batch update returned unexpected row count from update [ 0 ]; actual row count : 0 ; expected : 1
org . apache . struts . action . RequestProcessor . processException ( RequestProcessor . java : 535 )
org . apache . struts . action . RequestProcessor . processActionPerform ( RequestProcessor . java : 433 )
org . apache . struts . action . RequestProcessor . process ( RequestProcessor . java : 236 )
org . apache . struts . action . ActionServlet . process ( ActionServlet . java : 1196 )
org . apache . struts . action . ActionServlet . doPost ( ActionServlet . java : 432 )
javax . servlet . http . HttpServlet . service ( HttpServlet . java : 710 )
javax . servlet . http . HttpServlet . service ( HttpServlet . java : 803 )
org . netbeans . modules . web . monitor . server . MonitorFilter . doFilter ( MonitorFilter . java : 390 )
root cause
org . hibernate . StaleStateException : Batch update returned unexpected row count from update [ 0 ]; actual row count : 0 ; expected : 1
org . hibernate . jdbc . Expectations $ BasicExpectation . checkBatched ( Expectations . java : 61 )
org . hibernate . jdbc . Expectations $ BasicExpectation . verifyOutcome ( Expectations . java : 46 )
org . hibernate . jdbc . BatchingBatcher . checkRowCounts ( BatchingBatcher . java : 68 )
org . hibernate . jdbc . BatchingBatcher . doExecuteBatch ( BatchingBatcher . java : 48 )
org . hibernate . jdbc . AbstractBatcher . executeBatch ( AbstractBatcher . java : 246 )
org . hibernate . engine . ActionQueue . executeActions ( ActionQueue . java : 266 )
org . hibernate . engine . ActionQueue . executeActions ( ActionQueue . java : 168 )
org . hibernate . event . def . AbstractFlushingEventListener . performExecutions ( AbstractFlushingEventListener . java : 298 )
org . hibernate . event . def . DefaultFlushEventListener . onFlush ( DefaultFlushEventListener . java : 27 )
org . hibernate . impl . SessionImpl . flush ( SessionImpl . java : 1000 )
hibernate . PersistenciaDAO . salvar ( PersistenciaDAO . java : 25 )
usuario . action . UsuarioAction . salvar ( UsuarioAction . java : 53 )
sun . reflect . NativeMethodAccessorImpl . invoke0 ( Native Method )
sun . reflect . NativeMethodAccessorImpl . invoke ( NativeMethodAccessorImpl . java : 39 )
sun . reflect . DelegatingMethodAccessorImpl . invoke ( DelegatingMethodAccessorImpl . java : 25 )
java . lang . reflect . Method . invoke ( Method . java : 597 )
org . apache . struts . actions . DispatchAction . dispatchMethod ( DispatchAction . java : 270 )
org . apache . struts . actions . DispatchAction . execute ( DispatchAction . java : 187 )
org . apache . struts . actions . LookupDispatchAction . execute ( LookupDispatchAction . java : 150 )
org . apache . struts . action . RequestProcessor . processActionPerform ( RequestProcessor . java : 431 )
org . apache . struts . action . RequestProcessor . process ( RequestProcessor . java : 236 )
org . apache . struts . action . ActionServlet . process ( ActionServlet . java : 1196 )
org . apache . struts . action . ActionServlet . doPost ( ActionServlet . java : 432 )
javax . servlet . http . HttpServlet . service ( HttpServlet . java : 710 )
javax . servlet . http . HttpServlet . service ( HttpServlet . java : 803 )
org . netbeans . modules . web . monitor . server . MonitorFilter . doFilter ( MonitorFilter . java : 390 )
note The full stack trace of the root cause is available in the Apache Tomcat / 6.0.16 logs .
Apache Tomcat / 6.0.16
Meu bean
@Entity
@Table ( name = "usuario" )
public class Usuario implements Serializable {
private static final long serialVersionUID = 1L ;
@Id
@GeneratedValue ( strategy = GenerationType . IDENTITY )
@Column ( name = "idusuario" , nullable = false )
private Integer idusuario ;
@Column ( name = "nome" , nullable = false )
private String nome ;
@Column ( name = "senha" , nullable = false )
private String senha ;
gets ... sets
O que pode ser agora
Lucas_Lacerda_Gertel 19 de jun. de 2008
Limpa os registros e me fala.
Se for uma tabela antiga deve estar com algum conflito de IDs;
diogoprosoft 19 de jun. de 2008
limpei o banco deu o mesmo erro
O que será que esta acontecendo, porque se eu tirar o @GeneratedValue (strategy=GenerationType.IDENTITY) ele grava com valor igual ‘0’ e me retorna ‘0’ mais não da erro, mais se eu gravar outro ele ao inves de gravar com numero 1 que seria a sequencia de ‘0’ ele so altera o form e continua no ‘0’
Realmente não sei o que esta acontecendo
Lucas_Lacerda_Gertel 19 de jun. de 2008
Tira o nullable de id, não precisa.
Posta o teu dao ai pra ver como vocÊ tá salvando isso.
scaiocesar 19 de jun. de 2008
cara tenta usar isso
@Id
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="xxxx_id")
@SequenceGenerator(name="xxxx_id", sequenceName="xxxx_id", allocationSize=1)
private Integer id;
esse cara vai criar uma sequence no postgre com o nome xxxx_id
diogoprosoft 19 de jun. de 2008
pois bem, esta ai meu DAO
public void salvar ( Object object ) throws Exception {
session . saveOrUpdate ( object );
session . flush ();
transaction . commit ();
session . close ();
}
Na minha action esta assim
persistencia . salvar ( usuario );