-->
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.  [ 2 posts ] 
Author Message
 Post subject: StackOverflow Error on saveorupdate
PostPosted: Mon Mar 11, 2013 9:55 pm 
Newbie

Joined: Mon Mar 11, 2013 9:24 pm
Posts: 1
I have a project which is separated as core and webapp.
When I run ProductSiteImplTest using JUnit it works fine and was able to update the record on the DB.
But if I transfer this onto the webapp controller the stackoverflow error occurs.

I have no problem with creating a record just on update when I specify the idProductSite....
Tried to make the fetch type to eager and still the same.
Changed the cascade to detach and even removed the cascade type and still the same....

I've been hitting the blogs/forums for the past 3 days and found no clue.
Our company's tech advisor is too lazy to resolve the issue as well. T-T

Any help to identify the issue is greatly appreciated.

Thanks


Code:
public class ProductSiteImplTest {

   @Autowired ProductSiteService pss;
   @Autowired QuoteRepository qr;
   @Test
   public void testSaveOrUpdate() {
      ProductSite ps = new ProductSite();
      Quote quote = new Quote();
      Site site = new Site();
      
      ps = pss.findById(5);
      
      System.out.println(ps.getQuote().getCrmQuoteId());
      
      ps.setUpdatedBy("Jasper ");
      ps.setUpdatedDate(new Date());
      pss.saveOrUpdate(ps);
   }

}


Code:
@Entity
public class ProductSite implements Serializable {
   private static final long serialVersionUID = 1L;

   @Id
   @GeneratedValue(strategy=GenerationType.AUTO)
   private int idProductSite;

   @Column(columnDefinition = "TINYINT(1) DEFAULT 0")
   private int isAEnd;

   @Column(columnDefinition = "TINYINT(1) DEFAULT 0")
   private int isBEnd;

   @Column(columnDefinition = "TINYINT(1) DEFAULT 0")
   private int isCEnd;

   @Column(columnDefinition = "VARCHAR(45) DEFAULT NULL")
   private String createdBy;

   @Temporal(TemporalType.TIMESTAMP)
   @Column(columnDefinition = "DATETIME DEFAULT NULL")
   private Date createdDate;

   @Column(columnDefinition = "VARCHAR(45) DEFAULT NULL")
   private String updatedBy;

   @Temporal(TemporalType.TIMESTAMP)
   @Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP")
   private Date updatedDate;

   //bi-directional many-to-one association to ProductDetail
   @OneToMany(mappedBy="productSite", fetch=FetchType.LAZY, cascade=CascadeType.ALL)
   private List<ProductDetail> productDetails;

   //bi-directional many-to-one association to Site
   @ManyToOne
   @JoinColumn(name="site")
   @ForeignKey(name = "FK_PRODUCTSITE_SITE")
   private Site site;

   //bi-directional many-to-one association to Quote
   @ManyToOne
   @JoinColumn(name="quote")
   @ForeignKey(name = "FK_PRODUCTSITE_QUOTE")
   private Quote quote;

   @Column(columnDefinition = "TINYINT(1) DEFAULT 0")
   private int active;

        ... getters and setters here



Code:
@Entity
public class Quote implements Serializable {
   private static final long serialVersionUID = 1L;

   @Id
   @GeneratedValue(strategy=GenerationType.AUTO)
   private int idQuote;

   @Column(columnDefinition = "TEXT DEFAULT NULL")
   private String note;
   
   //bi-directional many-to-one association to Quote
   @OneToMany(mappedBy="quote", fetch=FetchType.LAZY, cascade=CascadeType.ALL)
   private List<ProductSite> productSites;

   @Column(columnDefinition = "VARCHAR(45) DEFAULT NULL")
   private String createdBy;

   @Temporal(TemporalType.TIMESTAMP)
   @Column(columnDefinition = "DATETIME DEFAULT NULL")
   private Date createdDate;

   @Column(columnDefinition = "VARCHAR(45) DEFAULT NULL")
   private String updatedBy;

   @Temporal(TemporalType.TIMESTAMP)
   @Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP")
   private Date updatedDate;

   //bi-directional many-to-one association to Customer
   @ManyToOne(cascade=CascadeType.ALL)
   @JoinColumn(name="customer")
   @ForeignKey(name = "FK_QUOTE_CUSTOMER")
   private Customer customer;

    @Column(columnDefinition = "VARCHAR(20) DEFAULT NULL")
    private String crmQuoteId;

    ... getters and setters here.


Code:
@Controller
public class TelehousingController {
   @Autowired ProductDetailPricingService pdps;
   @Autowired SiteService siteService;
   @Autowired ProductSiteService pss;
   @Autowired QuoteRepository qr;
   @Autowired ContractService cs;

    @ResponseBody
    @RequestMapping(value = "/rest/productscreens/telehousing/manageTransaction", method = RequestMethod.POST)
    public String saveData(@RequestBody String data,HttpServletRequest request, HttpServletResponse response) throws Exception {
      String msg = "";
      JsonObject json = (JsonObject)new JsonParser().parse(data);
      System.out.println("Validate Start...");
      msg = this.validate(json);
      System.out.println("Validate Finish : "+msg);
      if(msg.isEmpty()){
         System.out.println("Storing product site details");
         ProductSite ps = new ProductSite();
         
         int psID = pdps.getProductSiteId(json.get("crmQuoteId").getAsString(), json.get("siteId").getAsInt());
         if(psID > 0){
            System.out.println("START FIND PRODUCT SITE ID");
            ps = pss.findById(psID);
            System.out.println("GOT THE PRODUCT SITE DETAIL: " + ps.getQuote().getCrmQuoteId());
            
            //ps.setUpdatedBy(json.get("currentUser").getAsString());
            ps.setUpdatedBy("YOMAMAN!!");
            ps.setUpdatedDate(new Date());
         }else{
            Quote quote = new Quote();
            quote = qr.findOneByCrmQuoteIdLikeOrderByIdQuoteDesc(json.get("crmQuoteId").getAsString());
            Site site = new Site();
            site.setIdSite(json.get("siteId").getAsInt());
            ps.setQuote(quote);
            ps.setSite(site);
            ps.setActive(1);
            ps.setCreatedBy(json.get("currentUser").getAsString());
            ps.setCreatedDate(new Date());
         }
         try{
            ps = pss.saveOrUpdate(ps);
         }catch(Exception e){
            e.printStackTrace();
         }
      }
      return msg;
   }
.
.
.
}



Code:
SEVERE: Servlet.service() for servlet [appServlet] in context with path [/nos_webapp-1.0.0-SNAPSHOT] threw exception [Handler processing failed; nested exception is java.lang.StackOverflowError] with root cause
java.lang.StackOverflowError
   at com.mysql.jdbc.ConnectionPropertiesImpl.getProcessEscapeCodesForPrepStmts(ConnectionPropertiesImpl.java:3717)
   at com.mysql.jdbc.ConnectionImpl.prepareStatement(ConnectionImpl.java:4196)
   at com.mysql.jdbc.ConnectionImpl.prepareStatement(ConnectionImpl.java:4152)
   at org.apache.commons.dbcp.DelegatingConnection.prepareStatement(DelegatingConnection.java:281)
   at org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.prepareStatement(PoolingDataSource.java:313)
   at sun.reflect.GeneratedMethodAccessor61.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
   at org.hibernate.engine.jdbc.internal.proxy.ConnectionProxyHandler.continueInvocation(ConnectionProxyHandler.java:138)
   at org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:81)
   at $Proxy97.prepareStatement(Unknown Source)
   at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$5.doPrepare(StatementPreparerImpl.java:147)
   at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:166)
   at org.hibernate.engine.jdbc.internal.StatementPreparerImpl.prepareQueryStatement(StatementPreparerImpl.java:145)
   at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1719)
   at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1696)
   at org.hibernate.loader.Loader.doQuery(Loader.java:831)
   at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:292)
   at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:262)
   at org.hibernate.loader.Loader.loadEntity(Loader.java:1976)
   at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:82)
   at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:72)
   at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3720)
   at org.hibernate.event.internal.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:458)
   at org.hibernate.event.internal.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:427)
   at org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:204)
   at org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:260)
   at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:148)
   at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1079)
   at org.hibernate.internal.SessionImpl.internalLoad(SessionImpl.java:1006)
   at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:613)
   at org.hibernate.type.EntityType.resolve(EntityType.java:441)
   at org.hibernate.type.ComponentType.resolve(ComponentType.java:658)
   at org.hibernate.loader.Loader.extractKeysFromResultSet(Loader.java:759)
   [b][color=#BF4040]at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:638)
   at org.hibernate.loader.Loader.doQuery(Loader.java:853)
   at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:292)
   at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:262)
   at org.hibernate.loader.Loader.loadEntity(Loader.java:1976)
   at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:82)
   at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:72)
   at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3720)
   at org.hibernate.event.internal.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:458)
   at org.hibernate.event.internal.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:427)
   at org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:204)
   at org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:260)
   at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:148)
   at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1079)
   at org.hibernate.internal.SessionImpl.internalLoad(SessionImpl.java:1006)
   at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:613)
   at org.hibernate.type.EntityType.resolve(EntityType.java:441)
   at org.hibernate.type.ComponentType.resolve(ComponentType.java:658)
   at org.hibernate.loader.Loader.extractKeysFromResultSet(Loader.java:759)[/color][/b]
.
.
.the highlighted error repeats around 10-15 times


Top
 Profile  
 
 Post subject: Re: StackOverflow Error on saveorupdate
PostPosted: Tue Mar 12, 2013 3:18 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
Since from the stacktrace you report, it does not seem to be a endless recursion,
it may be work by increasing the java-stack-size.
See following article about increasing the java stack size.

http://stackoverflow.com/questions/3700459/how-to-increase-to-java-stack-size


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