mInEiRo 16 de abr. de 2007
<?xml version="1.0" encoding="UTF-8"?>
<hibernate-mapping>
<class name= "com.br.sistema.bean.InMenus" table= "in_menus" >
<id column= "idIN_MENUS" name= "idinMenus" type= "integer" >
<generator class= "native" />
</id>
<property column= "DESCRICAO" length= "255" name= "descricao" not-null= "true" type= "string" />
<property column= "LINK" length= "255" name= "link" not-null= "true" type= "string" />
<property column= "ATIVO" length= "1" name= "ativo" not-null= "true" type= "string" />
</class>
mInEiRo 16 de abr. de 2007
é em mysql meu projeto
entao tive que colocar native, porque com outro dava erro, tentei o increment
mas em consigo dar o insert normal
mInEiRo 16 de abr. de 2007
estou usando int, não Integer :shock:
vou mudar pra testar
no arquivo do hibernate, deixo o integer mesmo né?
mInEiRo 16 de abr. de 2007
agora deu esse erro
org . hibernate . TransientObjectException : The given object has a null identifier : com . br . sistema . bean . InMenus
at org . hibernate . event . def . DefaultSaveOrUpdateEventListener . getUpdateId ( DefaultSaveOrUpdateEventListener . java : 249 )
at org . hibernate . event . def . DefaultUpdateEventListener . getUpdateId ( DefaultUpdateEventListener . java : 46 )
at org . hibernate . event . def . DefaultSaveOrUpdateEventListener . entityIsDetached ( DefaultSaveOrUpdateEventListener . java : 217 )
at org . hibernate . event . def . DefaultUpdateEventListener . performSaveOrUpdate ( DefaultUpdateEventListener . java : 33 )
at org . hibernate . event . def . DefaultSaveOrUpdateEventListener . onSaveOrUpdate ( DefaultSaveOrUpdateEventListener . java : 70 )
at org . hibernate . impl . SessionImpl . fireUpdate ( SessionImpl . java : 564 )
at org . hibernate . impl . SessionImpl . update ( SessionImpl . java : 552 )
at org . hibernate . impl . SessionImpl . update ( SessionImpl . java : 544 )
at com . br . sistema . dao . MenusDAO . setUpdate ( MenusDAO . java : 25 )
at com . br . sistema . business . MenuB . setAlterar ( MenuB . java : 14 )
at com . br . sistema . action . MenuAction . Alterar ( MenuAction . java : 140 )
at com . br . sistema . action . MenuAction . execute ( MenuAction . java : 184 )
at org . apache . struts . chain . commands . servlet . ExecuteAction . execute ( ExecuteAction . java : 58 )
at org . apache . struts . chain . commands . AbstractExecuteAction . execute ( AbstractExecuteAction . java : 67 )
at org . apache . struts . chain . commands . ActionCommandBase . execute ( ActionCommandBase . java : 51 )
at org . apache . commons . chain . impl . ChainBase . execute ( ChainBase . java : 190 )
at org . apache . commons . chain . generic . LookupCommand . execute ( LookupCommand . java : 304 )
at org . apache . commons . chain . impl . ChainBase . execute ( ChainBase . java : 190 )
at org . apache . struts . chain . ComposableRequestProcessor . process ( ComposableRequestProcessor . java : 283 )
at org . apache . struts . action . ActionServlet . process ( ActionServlet . java : 1913 )
at org . apache . struts . action . ActionServlet . doPost ( ActionServlet . java : 462 )
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 org . apache . catalina . core . StandardWrapperValve . invoke ( StandardWrapperValve . java : 213 )
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 : 869 )
at org . apache . coyote . http11 . Http11BaseProtocol $ Http11ConnectionHandler . processConnection ( Http11BaseProtocol . java : 664 )
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 ( Unknown Source )
mInEiRo 16 de abr. de 2007
tipo, no logs do eclipse aparece
2007-04-16 16:27:06,890 DEBUG jasper.servlet.JspServlet -> ativo = 1
2007-04-16 16:27:06,890 DEBUG jasper.servlet.JspServlet -> botao = Alterar
2007-04-16 16:27:06,890 DEBUG jasper.servlet.JspServlet -> descricao = Arquivo21321
2007-04-16 16:27:06,906 DEBUG jasper.servlet.JspServlet -> link = www.uol.com.br
2007-04-16 16:27:06,906 DEBUG jasper.servlet.JspServlet -> codigo = 1
o codigo = 1 é o id da tabela
mInEiRo 16 de abr. de 2007
funcionou cara
realemnte estava null o codigo
muito obrigado
brunoneves 18 de mai. de 2009
estou com o mesmo problema,já tentei algumas coisas,mas o problema persiste!
“org.hibernate.TransientObjectException: The given object has a null identifier:model.Usuario”
Alguém me ajuda?
Seguem os códigos da página jsp e do model.Usuario
Model.usuario
@Entity
@Table ( name = "usuario" )
@SuppressWarnings ( "serial" )
public class Usuario implements Serializable {
private Estado estado = new Estado ();
private String login ;
private String nomeReduzido ;
private String nomeCompleto ;
private String email ;
private String senha ;
private Date nascimento ;
@ManyToOne
public Estado getEstado () {
return estado ;
}
public void setEstado ( Estado estado ) {
this . estado = estado ;
}
public Usuario (){}
public Usuario ( Estado estado , String login , String nomeReduzido ,
String nomeCompleto , String email , String senha , Date nascimento ) {
super ();
this . estado = estado ;
this . login = login ;
this . nomeReduzido = nomeReduzido ;
this . nomeCompleto = nomeCompleto ;
this . email = email ;
this . senha = senha ;
this . nascimento = nascimento ;
}
@Id
@Column ( name = "login" )
public String getLogin () {
return login ;
}
public void setLogin ( String login ) {
this . login = login ;
}
@Column ( name = "nomeReduzido" )
public String getNomeReduzido () {
return nomeReduzido ;
}
public void setNomeReduzido ( String nomeReduzido ) {
this . nomeReduzido = nomeReduzido ;
}
@Column ( name = "nomeCompleto" )
public String getNomeCompleto () {
return nomeCompleto ;
}
public void setNomeCompleto ( String nomeCompleto ) {
this . nomeCompleto = nomeCompleto ;
}
@Column ( name = "email" )
public String getEmail () {
return email ;
}
public void setEmail ( String email ) {
this . email = email ;
}
@Column ( name = "senha" )
public String getSenha () {
return senha ;
}
public void setSenha ( String senha ) {
this . senha = senha ;
}
@Temporal ( TemporalType . DATE )
@Column ( name = "nascimento" )
public Date getNascimento () {
return nascimento ;
}
public void setNascimento ( Date nascimento ) {
this . nascimento = nascimento ;
}
}
página de atualização de dados!
<% @ page language = "java" contentType = "text/html; charset=UTF-8"
pageEncoding = "UTF-8" %>
<% @taglib uri = "http://java.sun.com/jsf/core" prefix = "f" %>
<% @taglib uri = "http://java.sun.com/jsf/html" prefix = "h" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
< html >
< head >
< meta http-equiv = "Content-Type" content = "text/html; charset=UTF-8" >
< title > Atualizar Usuario</ title >
</ head >
< body >
< f:view >
< h:form id = "cadastro" >
< h:panelGrid columns = "2" >
< f:facet name = "header" >
< h:outputText value = "Atualizar Usuarios" />
</ f:facet >
< h:outputText value = "Login" />
< h:inputText size = "10" id = "login"
value = "#{usuarioBean.usuario.login}" readonly = "true" />
< h:outputText value = "senha" />
< h:inputText size = "10" id = "senha"
value = "#{usuarioBean.usuario.senha}" />
< h:outputText value = "Nome" />
< h:inputText size = "15" id = "nome"
value = "#{usuarioBean.usuario.nomeReduzido}" />
< h:outputText value = "Data de Nascimento" />
< h:inputText size = "10" id = "nascimento"
value = "#{usuarioBean.usuario.nascimento}" >
< f:convertDateTime pattern = "dd/MM/yyyy" />
</ h:inputText >
< h:outputText value = "Unidade Federativa" />
< h:selectOneMenu value = "#{usuarioBean.usuario.estado.id}" >
< f:selectItems value = "#{usuarioBean.estados}" />
</ h:selectOneMenu >
</ h:panelGrid >
< h:commandButton value = "Atualizar" action = "#{usuarioBean.atualizar}" />
< h:commandButton value = "Redefinir" type = "reset" />
< h:commandButton value = "Cancelar" action = "mostrar" />
</ h:form >
</ f:view >
</ body >
</ html >