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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:25:07+00:00 2026-05-28T19:25:07+00:00

I have the following model classes: @Entity @Table(name = title) public final class Title

  • 0

I have the following model classes:

@Entity
@Table(name = "title")
public final class Title extends ModelData<Title>
{
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer titleID;

    @Column(name = "title")
    private String title;

    @Column(name = "description")
    private String description;

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "title")
    private Set<Book> books;
}

@Entity
@Table(name = "book")
public final class Book extends ModelData<Book>
{
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "bookID")
    private int bookID;

    @ManyToOne(cascade = CascadeType.PERSIST, fetch = FetchType.EAGER)
    @JoinColumn(name = "titleID")
    private Title title;

    @Column(name = "edition")
    private Integer edition;

    @Column(name = "isbn")
    private String ISBN;
}

I want to write a Criteria query that is equivalent to the following SQL;

Select 
        t.title, b.edition 
    from 
        books b, title t
    where 
        b.titleID = t.titleID
    and 
        (b.edition=4 OR t.title LIKE '%Java%);

I tried the following:

Criteria c = session.createCriteria(Book.class);

Criteria titleCriteria = c.createCriteria("title");
titleCriteria.add(Restrictions.like("title", "%Java%");

Criterion edition = Restrictions.eq("edition", 4);

LogicalExpression orExp = Restrictions.or(edition, titleCriteria); //cannot do this

How do I achieve the above?

Thanks.

  • 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-28T19:25:08+00:00Added an answer on May 28, 2026 at 7:25 pm
    public class MyDTO {
      private String dtoTitle;
      private String dtoEdition;
      // + setters/getters
    }
    
    
    Criteria c = session.createCriteria(Book.class,"b");
    c.createAlias("title", "t");
    c.add(
        Restrictions.disjunction()
        .add( Restrictions.like("t.title", "%Java%") )
        .add( Restrictions.eq("b.edition", 4) )
    );
    c.setProjection( 
        Projections.projectionList()
        .add( Projections.property("t.title"), "dtoTitle" )
        .add( Projections.property("b.edition"), "dtoEdition" )
    );
    c.setResultTransformer(Transformers.aliasToBean(MyDTO.class));
    List<MyDTO> result = (List<MyDTO>)c.list();
    

    Something like this should work fine.

    On dao using many criterias you should consider using static imports.

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

Sidebar

Related Questions

I have the following classes in my Model: public abstract class Entity : IEntity
I have the following classes: Ingredients, Recipe and RecipeContent... class Ingredient(models.Model): name = models.CharField(max_length=30,
I have the following zendframework model classes class Application_Model_DbTable_Mobile extends Zend_Db_Table_Abstract { protected $_name
I have the following classes in my models file class HardwareNode(models.Model): ip_address = models.CharField(max_length=15)
I have the following types and classes: namespace MVC.Models public class Page { public
I have the following Model pattern: public abstract class PARENTCLASS {...} public class CHILD_A_CLASS
I have the following model structure: class Container(models.Model): pass class Generic(models.Model): name = models.CharacterField(unique=True)
I have the following model and instance: class Bashable(models.Model): name = models.CharField(max_length=100) >>> foo
I have the following model: class User: name = models.CharField( max_length = 200 )
We have a simple Table per Type Entity Framework 4.0 model :- ALl classes

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.