Results 1 to 6 of 6
  1. #1
    Monique7 is offline Member
    Join Date
    May 2014
    Posts
    7
    Rep Power
    0

    Default Spring/Hibernate + java.lang.StackOverflowError?

    I have an app with a many-to-many relationship between entities (Product, Order) , the intermediary table is ProductOrder

    Java Code:
        for(Item item : items)
        {
            ProductOrder po = new ProductOrder();
            po.setOrder(order);
            po.setProduct(item.getProduct());
            po.setQuantity(item.getQuantity());
            item.getProduct().getProductOrders().add(po); // FetchType is set to EAGER
            productService.save(item.getProduct());
    
        }
    the first 2-3 times I lauched the app it worked fine, but now I get

    java.lang.StackOverflowError

    The DB was updated on the first runs (table for ProductOrder was populated with the correct data).

    Here is the code for Product, Order, ProductOrder (id and other fields excluded) :

    Product code:

    Java Code:
    @Entity
    @Table(name = "product")
    public class Product implements Serializable{
    
    @OneToMany(fetch = FetchType.EAGER, mappedBy = "pk.product", cascade = CascadeType.ALL)
    private Set<ProductOrder> productOrders = new HashSet<ProductOrder>();
    ...
    }
    Order code:
    Java Code:
    @Entity
    @Table(name = "orders")
    public class Order implements Serializable{
    
    @OneToMany(fetch = FetchType.EAGER, mappedBy = "pk.order")
    private Set<ProductOrder> productOrders = new HashSet<ProductOrder>();
    
    }
    ProductOrder code:
    Java Code:
    @Entity
    @Table(name = "product_order")
    @AssociationOverrides({
        @AssociationOverride(name = "pk.product", joinColumns = @JoinColumn(name = "id_product")),
        @AssociationOverride(name = "pk.order", joinColumns = @JoinColumn(name = "id_order")) })
    public class ProductOrder implements Serializable{
    
    private ProductOrderId pk = new ProductOrderId();
    ...
    @EmbeddedId
    public ProductOrderId getPk() {
        return pk;
    }
    }
    ProductOrderId code:

    Java Code:
    @Embeddable
    public class ProductOrderId implements Serializable{
    
    @ManyToOne
    public Produs getProdus() {
        return produs;
    }
    
    @ManyToOne
    public Order getOrder() {
        return order;
    }
    }
    The stack trace changes a bit with every launch , but the main error is still java.lang.StackOverflowError , full stack trace is availale at StackOverflowError - f9f52aee

  2. #2
    Join Date
    Apr 2014
    Posts
    51
    Rep Power
    0

    Default Re: Spring/Hibernate + java.lang.StackOverflowError?

    can you check by fetch = FetchType.LAZY

  3. #3
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,273
    Rep Power
    6

    Default Re: Spring/Hibernate + java.lang.StackOverflowError?

    Post the stacktrace here please.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  4. #4
    Monique7 is offline Member
    Join Date
    May 2014
    Posts
    7
    Rep Power
    0

    Default Re: Spring/Hibernate + java.lang.StackOverflowError?

    Quote Originally Posted by itswebin@gmail.com View Post
    can you check by fetch = FetchType.LAZY
    I tried that and was getting LazyInitializationException . I tried several solutions from the internet, but couldn't get it to work )
    I found that maybe the java.lang.StackOverflowError was due to a hibernate bug (I'm using Hibernate version 3.2.0.Final ) so I tried to update to 4.2.8.Final but I still get the error.

  5. #5
    Monique7 is offline Member
    Join Date
    May 2014
    Posts
    7
    Rep Power
    0

    Default Re: Spring/Hibernate + java.lang.StackOverflowError?

    Stack trace: (Full stack trace is too long but it's mainly repeating so I guess it's like this)

    Java Code:
    java.lang.StackOverflowError
    	sun.nio.cs.SingleByte.withResult(SingleByte.java:44)
    	sun.nio.cs.SingleByte.access$000(SingleByte.java:38)
    	sun.nio.cs.SingleByte$Encoder.encodeArrayLoop(SingleByte.java:187)
    	sun.nio.cs.SingleByte$Encoder.encodeLoop(SingleByte.java:219)
    	java.nio.charset.CharsetEncoder.encode(CharsetEncoder.java:561)
    	sun.nio.cs.StreamEncoder.implWrite(StreamEncoder.java:271)
    	sun.nio.cs.StreamEncoder.write(StreamEncoder.java:125)
    	java.io.OutputStreamWriter.write(OutputStreamWriter.java:207)
    	java.io.BufferedWriter.flushBuffer(BufferedWriter.java:129)
    	java.io.PrintStream.write(PrintStream.java:526)
    	java.io.PrintStream.print(PrintStream.java:669)
    	java.io.PrintStream.println(PrintStream.java:806)
    	org.apache.tomcat.util.log.SystemLogHandler.println(SystemLogHandler.java:264)
    	org.hibernate.jdbc.util.SQLStatementLogger.logStatement(SQLStatementLogger.java:113)
    	org.hibernate.jdbc.AbstractBatcher.log(AbstractBatcher.java:444)
    	org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:511)
    	org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:452)
    	org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:161)
    	org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1700)
    	org.hibernate.loader.Loader.doQuery(Loader.java:801)
    	org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274)
    	org.hibernate.loader.Loader.loadEntity(Loader.java:2037)
    	org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:86)
    	org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:76)
    	org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3293)
    	org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:496)
    	org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:477)
    	org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:227)
    	org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:285)
    	org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:152)
    	org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:1090)
    	org.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:1038)
    	org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:630)

  6. #6
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,273
    Rep Power
    6

    Default Re: Spring/Hibernate + java.lang.StackOverflowError?

    Ouch, it looks like Hibernate is running into an endless recursion loop. That indeed looks like a bug in Hibernate.

    It looks like the problem originates in the SQL logging. What happens when you turn off Hibernate sql logging, does the problem disappear / you get another problem?

    BTW: LazyInitializationException is well-documented and has very clear reasons; you try to access an uninitialized collection when the Hibernate session has already been closed. You'd do well to not run away from learning how to deal with it.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. java.lang.StackOverflowError???
    By remus19 in forum New To Java
    Replies: 6
    Last Post: 05-06-2011, 03:55 AM
  2. java.lang.StackOverflowError
    By malstryx in forum New To Java
    Replies: 9
    Last Post: 10-01-2008, 05:14 AM
  3. java.lang.StackoverflowError
    By ravisankarvivek in forum New To Java
    Replies: 6
    Last Post: 06-23-2008, 10:05 AM
  4. java.lang.StackOverFlowError exception
    By jayaj in forum NetBeans
    Replies: 1
    Last Post: 06-08-2008, 12:17 PM
  5. java.lang.StackOverflowError
    By eva in forum New To Java
    Replies: 3
    Last Post: 12-24-2007, 10:54 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •