Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to write Utility class so that i can perform lazy loading with DTO design pattern?
    primarykey
    data
    text
    <p>As i know DTO is used to transfer the objects from one layer to other layers. In my project i am using DTO to transfer the objects from persistance layer to service layer.</p> <p>Here is my Utility class file which helps me to tranfrom persistance object to DTO.</p> <p>PropertyUtil</p> <pre><code> package com.cac.util; import java.util.HashSet; import java.util.Iterator; import java.util.Set; import com.cac.hibernate.Answers; import com.cac.hibernate.Members; import com.cac.hibernate.Questions; import com.cac.hibernate.Sections; import com.cac.to.AnswersTO; import com.cac.to.MembersTO; import com.cac.to.QuestionsTO; import com.cac.to.SectionsTO; public class PropertyUtil { public static Sections getSectionsFromSectionsTO(SectionsTO sectionsto) { Sections sections=new Sections(); sections.setSection_id(sectionsto.getSection_id()); sections.setSection_name(sectionsto.getSection_name()); sections.setSection_desc(sectionsto.getSection_desc()); sections.setThreads(sectionsto.getThreads()); sections.setPosts(sectionsto.getPosts()); sections.setLast_post(sectionsto.getLast_post()); sections.setLast_post_by(PropertyUtil.getMembersFromMembersTO(sectionsto.getLast_post_by())); sections.setQuestion_id(sectionsto.getQuestion_id()); return sections; } public static SectionsTO getSectionsTOFromSections(Sections sections) { SectionsTO sectionsto=new SectionsTO(); sectionsto.setSection_id(sections.getSection_id()); sectionsto.setSection_name(sections.getSection_name()); sectionsto.setSection_desc(sections.getSection_desc()); sectionsto.setThreads(sections.getThreads()); sectionsto.setPosts(sections.getPosts()); sectionsto.setLast_post(sections.getLast_post()); sectionsto.setLast_post_by(PropertyUtil.getMembersTOFromMembers(sections.getLast_post_by())); sectionsto.setQuestion_id(sections.getQuestion_id()); Set&lt;Questions&gt; questions_set=sections.getQuestions_set(); Set&lt;QuestionsTO&gt; questions_set_to=new HashSet&lt;QuestionsTO&gt;(); Iterator&lt;Questions&gt; it=questions_set.iterator(); while(it.hasNext()) { QuestionsTO questionsto=PropertyUtil.getQuestionsTOFromQuestions(it.next()); questions_set_to.add(questionsto); } return sectionsto; } public static Members getMembersFromMembersTO(MembersTO membersto) { Members members=new Members(); members.setMember_id(membersto.getMember_id()); members.setUsername(membersto.getUsername()); members.setPassword(membersto.getPassword()); members.setEmail(membersto.getEmail()); members.setGender(membersto.getGender()); members.setBdate(membersto.getBdate()); members.setImage_path(membersto.getImage_path()); members.setAddress(membersto.getAddress()); members.setBest_at(membersto.getBest_at()); members.setPosition(membersto.getPosition()); members.setJoin_date(membersto.getJoin_date()); //Set&lt;Members&gt; memset=new HashSet&lt;Members&gt;(); //members.setQuestions_set(membersto.getQuestionsto_set()); //mem return members; } public static MembersTO getMembersTOFromMembers(Members members) { MembersTO membersto=new MembersTO(); membersto.setMember_id(members.getMember_id()); membersto.setUsername(members.getUsername()); membersto.setPassword(members.getPassword()); membersto.setEmail(members.getEmail()); membersto.setGender(members.getGender()); membersto.setBdate(members.getBdate()); membersto.setImage_path(members.getImage_path()); membersto.setAddress(members.getAddress()); membersto.setBest_at(members.getBest_at()); membersto.setPosition(members.getPosition()); membersto.setJoin_date(members.getJoin_date()); Set&lt;Questions&gt; questions_set=members.getQuestions_set(); Set&lt;QuestionsTO&gt; questions_set_to=new HashSet&lt;QuestionsTO&gt;(); Iterator&lt;Questions&gt; it=questions_set.iterator(); while(it.hasNext()) { QuestionsTO questionsto=PropertyUtil.getQuestionsTOFromQuestions(it.next()); questions_set_to.add(questionsto); } Set&lt;Answers&gt; answers_set=members.getAnswers_set(); Set&lt;AnswersTO&gt; answers_set_to=new HashSet&lt;AnswersTO&gt;(); Iterator&lt;Answers&gt; answers_it=answers_set.iterator(); while(answers_it.hasNext()) { AnswersTO answersto=PropertyUtil.getAnswersTOFromAnswers(answers_it.next()); answers_set_to.add(answersto); } //members.setQuestions_set(membersto.getQuestionsto_set()); //mem return membersto; } public static QuestionsTO getQuestionsTOFromQuestions(Questions questions) { QuestionsTO questionsto=new QuestionsTO(); questionsto.setQuestion_id(questions.getQuestion_id()); questionsto.setQuestion_title(questions.getQuestion_title()); questionsto.setQuestion_desc(questions.getQuestion_desc()); questionsto.setQ_post_date(questions.getQ_post_date()); questionsto.setReplies(questions.getReplies()); questionsto.setViews(questions.getViews()); questionsto.setLast_post_by(questions.getLast_post_by()); questionsto.setLast_post_date(questions.getLast_post_date()); Set&lt;Answers&gt; answers_set=questions.getAnswers_set(); Set&lt;AnswersTO&gt; answers_set_to=new HashSet&lt;AnswersTO&gt;(); Iterator&lt;Answers&gt; answers_it=answers_set.iterator(); while(answers_it.hasNext()) { AnswersTO answersto=PropertyUtil.getAnswersTOFromAnswers(answers_it.next()); answers_set_to.add(answersto); } return questionsto; } public static Questions getQuestionsFromQuestionsTO(QuestionsTO questionsto) { Questions questions=new Questions(); questions.setQuestion_id(questionsto.getQuestion_id()); questions.setQuestion_title(questionsto.getQuestion_title()); questions.setQuestion_desc(questionsto.getQuestion_desc()); questions.setQ_post_date(questionsto.getQ_post_date()); questions.setReplies(questionsto.getReplies()); questions.setViews(questionsto.getViews()); questions.setLast_post_by(questionsto.getLast_post_by()); questions.setLast_post_date(questionsto.getLast_post_date()); return questions; } public static AnswersTO getAnswersTOFromAnswers(Answers answers) { AnswersTO answersto=new AnswersTO(); answersto.setAnswer_id(answers.getAnswer_id()); answersto.setAnswer_desc(answers.getAnswer_desc()); answersto.setA_post_date(answers.getA_post_date()); return answersto; } public static Answers getAnswersFromAnswersTO(AnswersTO answersto) { Answers answers=new Answers(); answers.setAnswer_id(answersto.getAnswer_id()); answers.setAnswer_desc(answersto.getAnswer_desc()); answers.setA_post_date(answersto.getA_post_date()); return answers; } } </code></pre> <p>The thing is that whenever i have to perform lazy loading but when i use getSectionsTOFromSection() it will load all the persistence class. . So how to write this PropertyUtil class so that i can use lazy loading and DTO design pattern both ?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload