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 8116245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T03:45:38+00:00 2026-06-06T03:45:38+00:00

Good night, in my application I access my database through Hibernate. I want to

  • 0

Good night,

in my application I access my database through Hibernate. I want to send a JSON data from a User

The code involved hibernate table (User) is as follows:

<hibernate-mapping>
<class name="modelos.Usuario" table="usuario" catalog="mydb">
    <id name="login" type="string">
        <column name="login" length="20" />
        <generator class="assigned" />
    </id>
    <many-to-one name="rol" class="modelos.Rol" fetch="join">
        <column name="Rol_idRol" not-null="true" />
    </many-to-one>
    <property name="password" type="string">
        <column name="password" length="32" />
    </property>
    <property name="nombre" type="string">
        <column name="nombre" length="45" />
    </property>
    <property name="apellidos" type="string">
        <column name="apellidos" length="45" />
    </property>
    <property name="dni" type="string">
        <column name="dni" length="10" />
    </property>
    <property name="direccion" type="string">
        <column name="direccion" length="60" />
    </property>
    <property name="numero" type="string">
        <column name="numero" length="5" />
    </property>
    <property name="poblacion" type="string">
        <column name="poblacion" length="45" />
    </property>
    <property name="cp" type="string">
        <column name="cp" length="5" />
    </property>
    <property name="provincia" type="string">
        <column name="provincia" length="30" />
    </property>
    <property name="email" type="string">
        <column name="email" length="60" />
    </property>
    <property name="telefono" type="string">
        <column name="telefono" length="15" />
    </property>
    <set name="reunions" table="reunion" inverse="true" lazy="false" fetch="join">
        <key>
            <column name="Perfil_login" length="20" not-null="true" />
        </key>
        <one-to-many class="modelos.Reunion" />
    </set>
    <set name="cuentas" table="cuenta" inverse="true" lazy="false" fetch="join">
        <key>
            <column name="usuario_login" length="20" not-null="true" />
        </key>
        <one-to-many class="modelos.Cuenta" />
    </set>
    <set name="sesions" table="sesion" inverse="true" lazy="false" fetch="join">
        <key>
            <column name="usuario_login" length="20" not-null="true" />
        </key>
        <one-to-many class="modelos.Sesion" />
    </set>
</class>

And generates the following Java code:

package modelos;

// Generated 19-abr-2012 18:48:54 by Hibernate Tools 3.4.0.CR1

import java.util.HashSet;
import java.util.Set;

/**
* Usuario generated by hbm2java
*/
public class Usuario implements java.io.Serializable {

 private String login;
 private Rol rol;
 private String password;
 private String nombre;
 private String apellidos;
 private String dni;
 private String direccion;
 private String numero;
 private String poblacion;
 private String cp;
 private String provincia;
 private String email;
 private String telefono;
 private Set<Reunion> reunions = new HashSet<Reunion>(0);
 private Set<Cuenta> cuentas = new HashSet<Cuenta>(0);
 private Set<Sesion> sesions = new HashSet<Sesion>(0);

public Usuario() {
}


public Usuario(String login, Rol rol) {
    this.login = login;
    this.rol = rol;
}
public Usuario(String login, Rol rol, String password, String nombre, String apellidos, String dni, String direccion, String numero, String poblacion, String cp, String provincia, String email, String telefono, Set<Reunion> reunions, Set<Cuenta> cuentas, Set<Sesion> sesions) {
   this.login = login;
   this.rol = rol;
   this.password = password;
   this.nombre = nombre;
   this.apellidos = apellidos;
   this.dni = dni;
   this.direccion = direccion;
   this.numero = numero;
   this.poblacion = poblacion;
   this.cp = cp;
   this.provincia = provincia;
   this.email = email;
   this.telefono = telefono;
   this.reunions = reunions;
   this.cuentas = cuentas;
   this.sesions = sesions;
}

public String getLogin() {
    return this.login;
}

public void setLogin(String login) {
    this.login = login;
}
public Rol getRol() {
    return this.rol;
}

public void setRol(Rol rol) {
    this.rol = rol;
}
public String getPassword() {
    return this.password;
}

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

public void setNombre(String nombre) {
    this.nombre = nombre;
}
public String getApellidos() {
    return this.apellidos;
}

public void setApellidos(String apellidos) {
    this.apellidos = apellidos;
}
public String getDni() {
    return this.dni;
}

public void setDni(String dni) {
    this.dni = dni;
}
public String getDireccion() {
    return this.direccion;
}

public void setDireccion(String direccion) {
    this.direccion = direccion;
}
public String getNumero() {
    return this.numero;
}

public void setNumero(String numero) {
    this.numero = numero;
}
public String getPoblacion() {
    return this.poblacion;
}

public void setPoblacion(String poblacion) {
    this.poblacion = poblacion;
}
public String getCp() {
    return this.cp;
}

public void setCp(String cp) {
    this.cp = cp;
}
public String getProvincia() {
    return this.provincia;
}

public void setProvincia(String provincia) {
    this.provincia = provincia;
}
public String getEmail() {
    return this.email;
}

public void setEmail(String email) {
    this.email = email;
}
public String getTelefono() {
    return this.telefono;
}

public void setTelefono(String telefono) {
    this.telefono = telefono;
}
public Set<Reunion> getReunions() {
    return this.reunions;
}

public void setReunions(Set<Reunion> reunions) {
    this.reunions = reunions;
}
public Set<Cuenta> getCuentas() {
    return this.cuentas;
}

public void setCuentas(Set<Cuenta> cuentas) {
    this.cuentas = cuentas;
}
public Set<Sesion> getSesions() {
    return this.sesions;
}

public void setSesions(Set<Sesion> sesions) {
    this.sesions = sesions;
}

}

The servlet that performs the update of user has the following code:

        if (opcion.equals("4")){

        response.setContentType("text/html");

        Rol rol = new Rol();

        String usuario = request.getParameter("login");
        Usuario user = facade.getUsuarioByLogin(usuario);

        String nombre= user.getNombre();
        String apellidos = user.getApellidos();
        String dni = user.getDni();
        String telefono = user.getTelefono();
        String email = user.getEmail();
        String direccion = user.getDireccion();
        String numero = user.getNumero();
        String poblacion = user.getPoblacion();
        String cp = user.getCp();
        String provincia = user.getProvincia();
        String login = user.getLogin();
        String contraseña = user.getPassword();
        rol = user.getRol();


        System.out.println("El valor de Nombre es"+nombre);

        //System.out.println("Opcion 4 El valor de rol es"+rol);

        JSONObject jsonObject1 = new JSONObject();
        jsonObject1.put("name", nombre);
        jsonObject1.put("apellidos", apellidos);
        jsonObject1.put("dni", dni);
        jsonObject1.put("telefono", telefono);
        jsonObject1.put("email", email);
        jsonObject1.put("direccion", direccion);
        jsonObject1.put("numero",numero);
        jsonObject1.put("poblacion", poblacion);
        jsonObject1.put("cp", cp);
        jsonObject1.put("provincia", provincia);
        jsonObject1.put("login", login);
        jsonObject1.put("pass", contraseña);

        jsonObject1.put("rol", rol);

When you run the application the following error:

net.sf.json.JSONException: There is a cycle in the hierarchy!
at net.sf.json.util.CycleDetectionStrategy$StrictCycleDetectionStrategy.handleRepeatedReferenceAsObject(CycleDetectionStrategy.java:97)
at net.sf.json.JSONObject._fromBean(JSONObject.java:857)
at net.sf.json.JSONObject.fromObject(JSONObject.java:192)
at net.sf.json.JSONObject._processValue(JSONObject.java:2774)
at net.sf.json.JSONObject._setInternal(JSONObject.java:2798)
at net.sf.json.JSONObject.setValue(JSONObject.java:1507)
at net.sf.json.JSONObject._fromBean(JSONObject.java:940)
at net.sf.json.JSONObject.fromObject(JSONObject.java:192)
at net.sf.json.JSONArray._processValue(JSONArray.java:2557)
at net.sf.json.JSONArray.processValue(JSONArray.java:2588)
at net.sf.json.JSONArray.addValue(JSONArray.java:2575)
at net.sf.json.JSONArray._fromCollection(JSONArray.java:1082)
at net.sf.json.JSONArray.fromObject(JSONArray.java:145)
at net.sf.json.JSONObject._processValue(JSONObject.java:2749)
at net.sf.json.JSONObject._setInternal(JSONObject.java:2798)
at net.sf.json.JSONObject.setValue(JSONObject.java:1507)
at net.sf.json.JSONObject._fromBean(JSONObject.java:940)
at net.sf.json.JSONObject.fromObject(JSONObject.java:192)
at net.sf.json.JSONObject._processValue(JSONObject.java:2774)
at net.sf.json.JSONObject.processValue(JSONObject.java:2833)
at net.sf.json.JSONObject.element(JSONObject.java:1871)
at net.sf.json.JSONObject.element(JSONObject.java:1849)
at net.sf.json.JSONObject.put(JSONObject.java:2466)
at servlet.UsuarioServlet.doPost(UsuarioServlet.java:195)

The error line in bold is the last line that appears in the servlet code pasted above. “jsonObject1.put (‘rol’, rol);”

What am I doing wrong?

Thanks!

Edit:

The code of Rol Class is the following:

package modelos;

// Generated 19-abr-2012 18:48:54 by Hibernate Tools 3.4.0.CR1

import java.util.HashSet;
import java.util.Set;

/**
* Rol generated by hbm2java
*/
public class Rol implements java.io.Serializable {

 private int idRol;
 private String nombre;
 private Boolean isAdmin;
 private Set<Usuario> usuarios = new HashSet<Usuario>(0);

public Rol() {
}


public Rol(int idRol) {
    this.idRol = idRol;
}
public Rol(int idRol, String nombre, Boolean isAdmin, Set<Usuario> usuarios) {
   this.idRol = idRol;
   this.nombre = nombre;
   this.isAdmin = isAdmin;
   this.usuarios = usuarios;
}

public int getIdRol() {
    return this.idRol;
}

public void setIdRol(int idRol) {
    this.idRol = idRol;
}
public String getNombre() {
    return this.nombre;
}

public void setNombre(String nombre) {
    this.nombre = nombre;
}
public Boolean getIsAdmin() {
    return this.isAdmin;
}

public void setIsAdmin(Boolean isAdmin) {
    this.isAdmin = isAdmin;
}
public Set<Usuario> getUsuarios() {
    return this.usuarios;
}

public void setUsuarios(Set<Usuario> usuarios) {
    this.usuarios = usuarios;
}

}

The code is generated by Hibenate as Usuario code.

The xml is the following:

<hibernate-mapping>
<class name="modelos.Rol" table="rol" catalog="mydb">
    <id name="idRol" type="int">
        <column name="idRol" />
        <generator class="assigned" />
    </id>
    <property name="nombre" type="string">
        <column name="Nombre" length="45" />
    </property>
    <property name="isAdmin" type="java.lang.Boolean">
        <column name="isAdmin" />
    </property>
    <set name="usuarios" table="usuario" inverse="true" lazy="false" fetch="select">
        <key>
            <column name="Rol_idRol" not-null="true" />
        </key>
        <one-to-many class="modelos.Usuario" />
    </set>
</class>

  • 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-06T03:45:40+00:00Added an answer on June 6, 2026 at 3:45 am

    In your pasted code, there is no “Rol” class or table definition ?

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

Sidebar

Related Questions

Good night, I'm trying to send from a servlet written in Java data name
good night: I want to mouse over .slide show the #panel , then click
Good morning, I am currently developing a java web application that exposes a web
Well, Maven is too good, when talking about speed. But I want something that
I am working on a website which the good user inputs a website domain
Is the materialized views of oracle(11g) are good practice for aggregated tables in Data
I maintain big MySQL database. I need to backup it every night, but the
Good night fellas, I'm trying to setup a app with django on Heroku using
Good night, I am currently working on a very simple lexical analiser for human
Good morning, I've been up all night trying to figure this out on my

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.