-->
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.  [ 4 posts ] 
Author Message
 Post subject: Problem hell with Hibernate, please help.
PostPosted: Tue Jun 17, 2008 9:07 am 
Newbie

Joined: Tue Jun 17, 2008 8:55 am
Posts: 2
Location: Brasil
Personnel someone could tell me what I'm doing wrong, or what remains to be done to the code following work:

my class product:

Code:

   1. package com.Lgweb.Tcc.Model; 
   2.   
   3. import java.io.Serializable; 
   4. import java.math.BigInteger; 
   5. import java.util.Collection; 
   6. import java.util.Date; 
   7. import javax.persistence.CascadeType; 
   8. import javax.persistence.Column; 
   9. import javax.persistence.Entity; 
  10. import javax.persistence.GeneratedValue; 
  11. import javax.persistence.GenerationType; 
  12. import javax.persistence.Id; 
  13. import javax.persistence.OneToMany; 
  14. import javax.persistence.SequenceGenerator; 
  15. import javax.persistence.Table; 
  16. import javax.persistence.Temporal; 
  17. import javax.persistence.TemporalType; 
  18.   
  19. import org.hibernate.annotations.FetchMode; 
  20.   
  21. @Entity 
  22. @Table(name = "produto") 
  23.     @SequenceGenerator(name = "geraCodProduto", sequenceName = "geraCodProduto") 
  24. public class Produto implements Serializable { 
  25.     private static final long serialVersionUID = 1L; 
  26.     @Id @GeneratedValue(strategy = GenerationType.AUTO, generator = "geraCodProduto")   
  27.     @Column(name = "produtoid", nullable = false) 
  28.     private Integer produtoid; 
  29.     @Column(name = "modelo") 
  30.     private String modelo;   
  31.   
  32.     @Column(name = "qtdtotal", nullable = false) 
  33.     private BigInteger qtdtotal; 
  34.   
  35.     @Column(name = "valorcusto") 
  36.     private Double valorcusto; 
  37.   
  38.     @Column(name = "valorvenda") 
  39.     private Double valorvenda; 
  40.   
  41.     @Column(name = "situacao") 
  42.     private String situacao; 
  43.   
  44.     @Column(name = "datacadastro") 
  45.     @Temporal(TemporalType.DATE) 
  46.     private Date datacadastro= new Date(); 
  47.   
  48.     @Column(name = "linha") 
  49.     private String linha;     
  50.   
  51.     @OneToMany(cascade = CascadeType.PERSIST, mappedBy = "produto") 
  52.     private Collection<Itensvenda> itensvendaCollection; 
  53.   
  54.     @OneToMany(cascade = CascadeType.PERSIST, mappedBy = "produto") 
  55.     private Collection<Itenscompra> itenscompraCollection; 
  56.       
  57.     @OneToMany(cascade = CascadeType.PERSIST, mappedBy = "produto")   
  58.     @org.hibernate.annotations.Fetch(FetchMode.SUBSELECT) 
  59.     private Collection<ProdutoNumeracao> produtoNumeracaoCollection; 
  60.   


The method save in the controller
Code:

   1. public String  create() {         
   2.         IDaoProduto ldao = new DaoProduto();             
   3.         produtoNumeracao.setProduto(produto);             
   4.         ldao.salvar(produto);         
   5.         setProdutoNumeracaoEditando(false); 
   6.         getTodos(); 
   7.         return "sucesso_incProduto"; 
   8.         } 




The method save in he Dao:
Code:
   1. public void salvar(Produto produto) { 
   2.         session = HibernateUtil.getInstance(); 
   3.         Transaction tx = null; 
   4.         try { 
   5.             tx = session.beginTransaction(); 
   6.                System.out.println("Modelo do Produto NO DAO...:"+produto.getModelo());               
   7.             session.saveOrUpdate(produto);           
   8.             tx.commit(); 
   9.         } catch (HibernateException e) { 
  10.             tx.rollback(); 
  11.         } finally { 
  12.             session.close(); 
  13.           
  14.         } 
  15.           
  16.     } 


in the server log shows that he run the generator of code, where a sequence of postgresql, but not saved or to pump in the bank, someone could help me please?

Code:

# 09:12:40,187 INFO  [STDOUT] o produto em create u 
# 09:12:40,203 INFO  [STDOUT] Modelo do Produto NO DAO...:TESTE DE HJ 
# 09:12:40,203 INFO  [STDOUT] Hibernate: select nextval ('geraCodProduto') 
# 09:12:40,296 INFO  [STDOUT] Hibernate: select produto0_.produtoid as produtoid16_, produto0_.modelo as modelo16_, produto0_.qtdtotal as qtdtotal16_, produto0_.valorcusto as valorcusto16_, produto0_.valorvenda as valorvenda16_, produto0_.situacao as situacao16_, produto0_.datacadastro as datacada7_16_, produto0_.linha as linha16_ from produto produto0_ order by produto0_.modelo 


I am using JSF 1.2, hibernate 3 with annotations, database PostgreSql 8.1, you, any hint aid and is of great value to me.
Thank you, hugging.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 17, 2008 10:55 am 
Expert
Expert

Joined: Fri Jul 13, 2007 8:18 am
Posts: 370
Location: london
Code:
9.         } catch (HibernateException e) {
  10.             tx.rollback();
  11.         } finally { 


Perhaps you're getting an exception on save - there's no logging in the catch block.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 17, 2008 11:49 am 
Newbie

Joined: Tue Jun 17, 2008 8:55 am
Posts: 2
Location: Brasil
That same friend thank you for your tip, the problem was that I had mapped the attribute (Total amount) to not receive zero values, and as I was not using e.printStackTrace (), not via the following error in the log of location:
Code:

12:38:06,609 ERROR [STDERR] org.hibernate.PropertyValueException: not-null property references a null or transient value: com.Lgweb.Tcc.Model.Produto.qtdtotal
   at org.hibernate.engine.Nullability.checkNullability(Nullability.java:72)
   at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:290)
   at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:181)
   at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:121)
   at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:187)
   at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:172)
   at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:94)
   at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
   at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:507)
   at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:499)
   at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:495)
   at com.Lgweb.Tcc.Dao.DaoProduto.salvar(DaoProduto.java:190)
   at com.Lgweb.Tcc.Controller.ControlProduto.create(ControlProduto.java:124)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at org.apache.el.parser.AstValue.invoke(AstValue.java:131)
   at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
   at org.apache.jasper.el.JspMethodExpression.invoke(JspMethodExpression.java:68)
   at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:77)
   at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:91)
   at javax.faces.component.UICommand.broadcast(UICommand.java:383)
   at org.ajax4jsf.component.AjaxActionComponent.broadcast(AjaxActionComponent.java:55)
   at org.ajax4jsf.component.AjaxViewRoot.processEvents(AjaxViewRoot.java:317)
   at org.ajax4jsf.component.AjaxViewRoot.broadcastEvents(AjaxViewRoot.java:292)
   at org.ajax4jsf.component.AjaxViewRoot.processPhase(AjaxViewRoot.java:249)
   at org.ajax4jsf.component.AjaxViewRoot.processApplication(AjaxViewRoot.java:462)
   at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:97)
   at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
   at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117)
   at javax.faces.webapp.FacesServlet.service(FacesServlet.java:244)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
   at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:154)
   at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:260)
   at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:366)
   at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:493)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
   at com.Lgweb.Tcc.Util.SecuritFilter.doFilter(SecuritFilter.java:38)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
   at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
   at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
   at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
   at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:241)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
   at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:580)
   at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
   at java.lang.Thread.run(Unknown Source)


Thank you for help, hugs. :)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 17, 2008 3:20 pm 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
It does feel nice when you get it to work, doesn't it. :) Thanks for posting back with a solution.

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


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