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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:16:22+00:00 2026-05-26T02:16:22+00:00

I have the next structure of DTO objects: public class MainDTO implements Serializable {

  • 0

I have the next structure of DTO objects:

public class MainDTO implements Serializable {
    private Long mainId;
    private String name;
    ... //some other fields
    private boolean disabled;

    @ManyToOne()
    @JoinColumn(name = "root_id")
    private RootDTO root;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "child_id", updatable = false, referencedColumnName = "child_id")
    @Cascade(value = { CascadeType.ALL, CascadeType.DELETE_ORPHAN })
    private ChildDTO child;

    ...
}

public class RootDTO implements Serializable {
    ... //some other fields
    private boolean disabled;

    ...
}


public class ChildDTO implements Serializable {
    private Long childId;
    ... //some other fields
    private boolean disabled;

    @ManyToOne()
    @JoinColumn(name = "info_id")
    private InfoDTO info;

    ...
}

public class InfoDTO implements Serializable {
    private Long infoId;
    ... //some other fields
    private boolean disabled;

    ...
}

I need to fill Map<String, Map<Long, Long>> (<name from MainDTO, <mainId from MainDTO, infoId from InfoDTO >>) with next restrictions:

MainDTO.disabled = false,

MainDTO.root != null,

MainDTO.root.disabled = false,

MainDTO.child.disabled = false,

MainDTO.child.info != null,

MainDTO.child.info.disabled = false

Here is the code I’ve written, but got stuck in select infoId from InfoDTO:

Criteria rootCriteria = getSession().createCriteria(
        MainDTO.class);

// check that root is enabled
rootCriteria.createCriteria("root", "root").add(
    Restrictions.eq("disabled", false));

// check that child is enabled
Criteria childCriteria = rootCriteria
    .createCriteria("child", "child")
    .add(Restrictions.eq("disabled", false))
    .add(Restrictions.isNotNull("info"));

// check that info is enabled
childCriteria
    .createCriteria("info", "info")
    .add(Restrictions.eq("disabled", false));

ProjectionList rootProjection = Projections.projectionList()
    .add(Projections.property("mainId"))
    .add(Projections.property("name"))
    .add(Projections.property("child.info")); //HOW TO SELECT ONLY ID??
rootCriteria.setProjection(rootProjection);
rootCriteria.add(Restrictions.eq("disabled", false))
    .add(Restrictions.isNotNull("root"))
    .add(Restrictions.isNotNull("child"));

Thanks a lot!

  • 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-26T02:16:23+00:00Added an answer on May 26, 2026 at 2:16 am

    First of all, calling entities DTO is really confusing.

    Now regarding your question, you should use the aliases you defined in your projections

    ProjectionList rootProjection = 
        Projections.projectionList()
                   .add(Projections.property("mainId"))
                   .add(Projections.property("name"))
                   .add(Projections.property("info.infoId"));
    

    Also, given that you’re doing an inner join to root and child, the last two restrictions are not necessary: the inner joins already make sure those are not null.

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

Sidebar

Related Questions

There is next problem, i have similar class structure: class A { public String
I have next structure: @Component public abstract class HuginJob extends QuartzJobBean {...} @Component(CisxJob) public
I have next package structure webService.ear -- dependency.jar -- some.class Can I remove some.class
I have the next menu structure. <li class=menu-422><a href=item-1 title=>Item 1</a></li> <li class=menu-444><a href=item-2
Let us say we have the next JSON structure: { { name:FirstComponent, items:[ {
I have next tables Order , Transaction , Payment . Class Order has some
I have next code require 'rack/rpc' class Server < Rack::RPC::Server def hello_world Hello, world!
I have next problem: i have a View: <UserControl x:Class=WpfApplication1.UserControl1 xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml xmlns:mc=http://schemas.openxmlformats.org/markup-compatibility/2006 xmlns:d=http://schemas.microsoft.com/expression/blend/2008
I have next html: <label for="user_name"> <abbr title="required">*</abbr> Name </label> And I want to
I have next SVN repositories structure running Apache 2.2 under Windows Server 2008: http://example.com/svn/

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.