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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:14:04+00:00 2026-06-18T00:14:04+00:00

Background: I work in an education environment and last summer one of our developers

  • 0

Background: I work in an education environment and last summer one of our developers designed and built a Java web application using Spring MVC and Hibernate. It launched with the new term in September to much joy from the users as it replaced a dusty old Blackboard plugin. The primary functions of the applications are used for setting targets for a student, leaving them messages and creating reports for students.

Fast forward a few months, the original developer has moved on and the application is having some growing pains.

Use Case Scenario: A Teacher logs in and they are presented with their home screen which contains a list of courses which they teach on, with an overview of Targets, messages and Reports for the currently selected course as well as a list of student enrolments for the course. If a course contains a small number of targets etc then it’s quick to return the information. But as the amount of information grows, the time taken to load it seems to increase exponentially.

After investigating I think I’ve found out why. I took a sample course and took a look at Reports to see what was going on. and I found that the Database returned the relevant data in milliseconds, the browser rendered it in milliseconds but there was 12 seconds in between when the browser was waiting for data to be returned from it. The only thing that gets done to the objects between the database query finishing and the front end receiving the response is a convert to DTO.

Code: This is what the Report Object looks like in the DAO layer

@Entity
@Table(name = "REPORTS")
public class Report implements Serializable
{

    /**
     * 
     */
    private static final long   serialVersionUID    = -7659637777880535914L;

    @Id
    @GeneratedValue
    @Column(name = "REPORT_ID", insertable = true, updatable = false, nullable = false, unique=true)
    private Integer             reportID;

    @Column(name = "DATE_CREATED", insertable = true, updatable = false, nullable = false)
    private GregorianCalendar   dateCreated;

    @Column(name = "DATE_MODIFIED", insertable = true, updatable = true, nullable = true)
    private GregorianCalendar   dateModified;

    @Column(name = "TITLE", insertable = true, updatable = true, nullable = false, length=1000)
    private String              title;

    @Column(name = "CURRENT_PERFORMANCE_GRADE", insertable = true, updatable = true, nullable = false)
    private String              currentPerformanceGrade;

    @Column(name = "TARGET_GRADE", insertable = true, updatable = true, nullable = false)
    private String              targetGrade;

    //VARCHAR(MAX) as this is the main body of the tutor report comments. Here the tutor can write as much content as they like.
    @Column(name = "TUTOR_COMMENTS", insertable = true, updatable = true, nullable = false, columnDefinition="VARCHAR(MAX)")
    private String              tutorComments;
//getters and setters below
}

There are other fields in there too like the user the report is linked to, the course, the tutor who wrote it etc. but I left them out for simplicity’s sake here.

public class ReportDTO implements Serializable
{

/**
 * 
 */
private static final long   serialVersionUID    = 2795129355073929139L;

private Integer             reportID;

private String              dateCreated;

private String              dateModified;

private String              title;

private String              currentPerformanceGrade;

private String              targetGrade;

private String              tutorComments;
//getters and setters below
}

So the main differences are with the date objects have become date formatted strings as opposed to GregorianCalendar objects so that the front end display of the date is in a nice readable format. Here’s an example of what the converting to DTO involves. A Single method in the service layer which takes the DAO object, gets the relevant fields from it, sets them in the newly constructed DTO object, converts as needed (e.g. Gregorian Calendar to date formatted String) and returns the DTO:

public ReportDTO convertToDto(Report daoReport) throws Exception
{

    ReportDTO dtoReport = new ReportDTO();
    try
    {
                    if(daoReport.getReportID() != null)
        {
            dtoReport.setReportID(daoReport.getReportID());
        }
                    if(daoReport.getDateCreated() != null)
        {
            dtoReport.setDateCreated(ReportServiceImpl.ISO_DATE_TIME_FORMAT.format(daoReport.getDateCreated().getTime()));

        }

        if(daoReport.getDateModified() != null)
        {
             dtoReport.setDateModified(ReportServiceImpl.ISO_DATE_TIME_FORMAT.format(daoReport.getDateModified().getTime()));

        }

        if(daoReport.getTitle() != null)
        {
            dtoReport.setTitle(daoReport.getTitle());

        }
                     if(daoReport.getCurrentPerformanceGrade() != null)
        {
              dtoReport.setCurrentPerformanceGrade(daoReport.getCurrentPerformanceGrade());

        }

        if(daoReport.getTargetGrade() != null)
        {
            dtoReport.setTargetGrade(daoReport.getTargetGrade());

        }

        if(daoReport.getTutorComments() != null)
        {
            dtoReport.setTutorComments(daoReport.getTutorComments());

        }
                    return dtoReport;
    }
    catch(Exception e)
    {
        Exception myException = new Exception("Exception was thrown while converting a persistent Report object to it's data transport equivalent", e);
        throw myException;
    }

Question: So after all that, my question is, is this the correct way of converting from DAO to DTO? Since he left I had been following his code and anything new added was done in the same way. Returning the Objects to the front end without converting them I see the results in >300 milliseconds instead of 12 seconds.

I know he learned Spring MVC from here for the project so he wasn’t an experienced Spring Developer and neither am I and judging by the fact we’re seeing such large request times we must be doing something wrong.

  • 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-18T00:14:06+00:00Added an answer on June 18, 2026 at 12:14 am

    Okay as beny23 mentioned Hibernate was lazy-loading (loading a list of PKs initially then loading the rest when actioning something on the data)

    The solution I used was to create a non-hibernate connection for reading data using a normal JDBC connection, the query also converted the data so that it came back in the format I needed it in (Dates as Strings etc) so and I didn’t have to convert to dto. That way I unloaded some of the work to the database and saved my application the hassle of doing it.

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

Sidebar

Related Questions

We run our web application wehre we start some Threads for background work and
background: I work on an asp.net web application that is on a company intranet.
What's the proper way for a Java command line application to do background work
Background The main application where I work is based heavily on the MUMPS-esque Caché
i have the following simple code, but it doesn,t work <ul> <li id=one onmouseover=this.style.background-color='white';>
Background: I work for a small microsoft based web dev company who is slowly
I'm new to this android. i'm using a service to do some background work.
I need to write some application which will do some work in background. This
I have a two-thread application: GUI, and some background work. I'm trying to send
Say I have a third party Application that does background work, but prints out

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.