Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7765533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:11:24+00:00 2026-06-01T15:11:24+00:00

I am having some problems getting a larger application with many table relationships working

  • 0

I am having some problems getting a larger application with many table relationships working with Struts2 and Hibernate, so I decided to create a much smaller-scale example to figure it out and I cannot get that working either. My main problem is that I cannot get the two to work together at all when there are any lazy instantiation sets involved. I am trying to figure out how to make it work with and without loading the lazy data, but in this case I have loaded the lazy data and I am getting a “java.lang.StackOverflowError.” I have two tables, “Departments,” with two entries and “Employees,” with three; I am using the Struts2 “xslt” result type. Here are the two persistence classes:

Departments:

package com.test.model;
// Generated Apr 7, 2012 7:10:28 PM by Hibernate Tools 3.4.0.CR1

import java.util.HashSet;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 * Departments generated by hbm2java
 */
@Entity
@Table(name="Departments"
    ,catalog="test"
)
public class Departments  implements java.io.Serializable {


     private Integer id;
     private String name;
     private Set<Employees> employeeses = new HashSet(0);

    public Departments() {
    }


    public Departments(String name) {
        this.name = name;
    }
    public Departments(String name, Set employeeses) {
       this.name = name;
       this.employeeses = employeeses;
    }

     @Id @GeneratedValue(strategy=IDENTITY)


    @Column(name="Id", unique=true, nullable=false)
    public Integer getId() {
        return this.id;
    }

    public void setId(Integer id) {
        this.id = id;
    }


    @Column(name="Name", nullable=false)
    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @OneToMany(fetch=FetchType.LAZY, mappedBy="departments")
    public Set<Employees> getEmployeeses() {
        return this.employeeses;
    }

    public void setEmployeeses(Set employeeses) {
        this.employeeses = employeeses;
    }
}

Employees:

package com.test.model;
// Generated Apr 7, 2012 7:10:28 PM by Hibernate Tools 3.4.0.CR1


import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

/**
 * Employees generated by hbm2java
 */
@Entity
@Table(name="Employees"
    ,catalog="test"
)
public class Employees  implements java.io.Serializable {


     private Integer id;
     private Departments departments;
     private String firstName;
     private String lastName;

    public Employees() {
    }

    public Employees(Departments departments, String firstName, String lastName) {
       this.departments = departments;
       this.firstName = firstName;
       this.lastName = lastName;
    }

     @Id @GeneratedValue(strategy=IDENTITY)


    @Column(name="Id", unique=true, nullable=false)
    public Integer getId() {
        return this.id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    @ManyToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="DepartmentsId", nullable=false)
    public Departments getDepartments() {
        return this.departments;
    }

    public void setDepartments(Departments departments) {
        this.departments = departments;
    }


    @Column(name="FirstName", nullable=false)
    public String getFirstName() {
        return this.firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }


    @Column(name="LastName", nullable=false)
    public String getLastName() {
        return this.lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }
}

The HQL query I am using in the DepartmentsManager class is: “from Departments d left join fetch d.employeeses”.

Here is the stacktrace of the error:

Exception in thread “http-bio-8080-exec-4” java.lang.StackOverflowError
at java.security.AccessController.doPrivileged(Native Method)
at org.apache.commons.logging.LogFactory.getContextClassLoaderInternal(LogFactory.java:859)
at org.apache.commons.logging.LogFactory.getFactory(LogFactory.java:423)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:685)
at com.opensymphony.xwork2.util.logging.commons.CommonsLoggerFactory.getLoggerImpl(CommonsLoggerFactory.java:29)
at com.opensymphony.xwork2.util.logging.LoggerFactory.getLogger(LoggerFactory.java:42)
at org.apache.struts2.views.xslt.AbstractAdapterNode.(AbstractAdapterNode.java:85)
at org.apache.struts2.views.xslt.AbstractAdapterElement.(AbstractAdapterElement.java:41)
at org.apache.struts2.views.xslt.BeanAdapter.(BeanAdapter.java:73)
at sun.reflect.GeneratedConstructorAccessor14.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
at java.lang.Class.newInstance0(Class.java:372)
at java.lang.Class.newInstance(Class.java:325)
at org.apache.struts2.views.xslt.AdapterFactory.constructAdapterInstance(AdapterFactory.java:209)
at org.apache.struts2.views.xslt.AdapterFactory.adaptNode(AdapterFactory.java:159)
at org.apache.struts2.views.xslt.BeanAdapter.buildChildAdapters(BeanAdapter.java:135)
at org.apache.struts2.views.xslt.AbstractAdapterNode.getChildAdapters(AbstractAdapterNode.java:128)
at org.apache.struts2.views.xslt.AbstractAdapterNode.getChildNodes(AbstractAdapterNode.java:186)
at org.apache.struts2.views.xslt.BeanAdapter.getChildNodes(BeanAdapter.java:88)
at org.apache.struts2.views.xslt.AbstractAdapterNode.getFirstChild(AbstractAdapterNode.java:194)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2SAX.parse(DOM2SAX.java:300)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2SAX.parse(DOM2SAX.java:302)…[this line repeats ad nauseam]

Would someone please point me in the right direction?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T15:11:25+00:00Added an answer on June 1, 2026 at 3:11 pm

    Yes, here’s a thought:

    You have a Departments class (bad naming – use the singular Department). It has a Set of Employee instances. It’s a one to many relationship: a Department can have one or more Employees. So far, so good.

    Your Employees class (more bad naming – use the singular Employee) has a reference to its parent Department.

    You see the problem? Every time you call the Employee constructor, you can the Department constructor, which creates a Set of Employees. The instance of the original Employee is in that Set, which again calls the Department constructor, ad nauseum.

    You need to break the cycle: it’s a bidirectional one-to-many:

    http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/example-parentchild.html#example-parentchild-bidir

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having some problems getting a flash application (in AS3) to search for a
I am having some problems getting only a date to show in my table..
Im having some problems getting the Sticky Footer to work on my site. If
I'm having some problems getting ncurses' getch() to block. Default operation seems to be
I am having some problems getting my JS/JQ to fire in HTML5 page. Basically
I'm having some problems with getting the .getruntime.exec() to work properly. Here is the
Currently i am having some problems with getting some data out of a DataTable
I am having some problems getting this animation to execute. I have a feeling
I am having some problems getting some French text to convert to UTF8 so
I am having some problems getting a small piece of text to be centered

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.