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

  • Home
  • SEARCH
  • 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 909011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:48:26+00:00 2026-05-15T16:48:26+00:00

I am trying to build a login page using hibernate and struts2. My design

  • 0

I am trying to build a login page using hibernate and struts2. My design is as follows. Each login user has a role. Many users can have the same role.
So my class are:
User.java

@Entity
@Table(name = "user", catalog = "ciner")
public class User implements java.io.Serializable {

    private Integer userId;
    private Role role;
    private String loginId;
    private String password;
    private String firstName;
    private String lastName;

    public User() {
    }

    public User(Role role, String loginId, String password, String firstName, String lastName) {
        this.role = role;
        this.loginId = loginId;
        this.password = password;
        this.firstName = firstName;
        this.lastName = lastName;
    }

    @Id
    @GeneratedValue(strategy = IDENTITY)
    @Column(name = "user_id")
    public Integer getUserId() {
        return this.userId;
    }

    public void setUserId(Integer userId) {
        this.userId = userId;
    }

    @Column(name = "password", nullable = false)
    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "role_id")
    public Role getRole() {
        return this.role;
    }

    public void setRole(Role role) {
        this.role = role;
    }

    @Column(name = "login_id", nullable = false, length = 7)
    public String getLoginId() {
        return this.loginId;
    }

    public void setLoginId(String loginId) {
        this.loginId = loginId;
    }

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

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

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

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

    @Override
    public String toString() {
        return "User{" + "userId=" + userId + "role=" + role + "loginId="
                + loginId + "firstName=" + firstName + "lastName=" + lastName
                + '}';
    }

}

Role.java

@Entity
@Table(name = "role", catalog = "ciner")
public class Role implements java.io.Serializable {

    private Integer roleId;
    private String roleDescription;
    private List users;

    public Role() {
    }

    public Role(String roleDescription) {
        this.roleDescription = roleDescription;
    }

    public Role(String roleDescription, List users) {
        this.roleDescription = roleDescription;
        this.users = users;
    }

    @Id
    @GeneratedValue(strategy = IDENTITY)
    @Column(name = "role_id", unique = true, nullable = false)
    public Integer getRoleId() {
        return this.roleId;
    }

    public void setRoleId(Integer roleId) {
        this.roleId = roleId;
    }

    @Column(name = "role_description", nullable = false, length = 100)
    public String getRoleDescription() {
        return this.roleDescription;
    }

    public void setRoleDescription(String roleDescription) {
        this.roleDescription = roleDescription;
    }

    // @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy =
    // "role")
    @OneToMany(fetch = FetchType.LAZY, mappedBy = "role", targetEntity = User.class)
    public List getUsers() {
        return this.users;
    }

    public void setUsers(List users) {
        this.users = users;
    }

    @Override
    public String toString() {
        return "Role{" + "roleId=" + roleId + "roleDescription="
                + roleDescription + "users=" + users + '}';
    }
}

It returns 1 user just fine if it is valid. But since the method return that user back, i use return users.get(0);

Stack

java.lang.StackOverflowError
    java.lang.Integer.toString(Unknown Source)
    java.lang.Integer.toString(Unknown Source)
    java.lang.String.valueOf(Unknown Source)
    java.lang.Integer.toString(Unknown Source)
    java.lang.String.valueOf(Unknown Source)
    java.lang.StringBuilder.append(Unknown Source)
    com.inhis.model.Role.toString(Role.java:70)
    sun.reflect.GeneratedMethodAccessor293.invoke(Unknown Source)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    java.lang.reflect.Method.invoke(Unknown Source)
    org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(JavassistLazyInitializer.java:197)
    com.inhis.model.Role_$$_javassist_6.toString(Role_$$_javassist_6.java)
    java.lang.String.valueOf(Unknown Source)
    java.lang.StringBuilder.append(Unknown Source)
    com.inhis.model.User.toString(User.java:97)
    java.lang.String.valueOf(Unknown Source)
    java.lang.StringBuilder.append(Unknown Source)
    java.util.AbstractCollection.toString(Unknown Source)
    org.hibernate.collection.PersistentBag.toString(PersistentBag.java:507)

Say, roles are
1, Unauthorized
2, Manager
3, User
What am I doing wrong? Also, I want assign them a default role of 1. I couldn’t figure that out. So, I am storing it as null now. How can I achieve that?

  • 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-05-15T16:48:27+00:00Added an answer on May 15, 2026 at 4:48 pm

    You created an infinite loop.
    If you call the toString-method of a role it calls the toString-method for each user and this calls the toString of the role again.
    A possible solution is to remove this from the role-class:

    "users=" + users +
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying build a page, where a user can login using his google
I am trying to login to this page using Python. I tried using the
I am trying to build a small page using django which uses a facebook
I'm trying to build a control logic that depends on the current gsp page
I am trying to build openid login system for my website. To do this
I'm trying to build a site that runs without refreshes, using Jquery and PHP
I'm trying to build an edit page for a database record that can be
im trying out to build a web application. it must have contain a login
Trying to get a login script working, I kept getting the same login page
i'm trying to get the html of a page using this screen scraping in

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.