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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:01:29+00:00 2026-05-15T15:01:29+00:00

In my Hibernated system, I have a class Picture that has some simple data,

  • 0

In my Hibernated system, I have a class Picture that has some simple data, a list of Installations and some (huge) binary data. The list of Installations is implemented with a join table, as it’s a ManyToMany relation, and it’s defined on the Installation side:

@Entity
public class Picture {
  @Id
  private long pictureId;
  private String mimeType;
  @Lob
  @Basic(fetch=FetchType.LAZY) // Don't load all data unless required
  private byte[] picture;

  @ManyToMany(mappedBy= "images")
  private List<Installation> installations;

  /** This should be used only to load partial objects through PictureDao */
  public Picture(long pictureId, String mimeType, List<Installation> insts) {
    this.pictureId = pictureId;
    this.mimeType = mimeType;
    this.installations = insts;
  }
...
}

The constructor is there solely to allow partial selects.

@Entity
public class Installation {
  @Id
  private long id;
  @ManyToMany(cascade=CascadeType.PERSIST)
  @JoinTable(name="InstPicture",
     joinColumns={@JoinColumn(name="installationId")},
     inverseJoinColumns = {@JoinColumn(name="pictureId")})
  @OrderBy("pictureDate ASC")
  private List<Picture> images;
  ...
}

I’d like to be able to make a partial select that inlucdes the list of Installations, but not the picture data. I have tried the obvious solution:

Query q = em.createQuery("SELECT new Picture" +
  "(p.pictureId, p.mimeType, p.installations) " +
  " FROM Picture p WHERE p.pictureId = :id");

but it claims it cannot find the constructor. If I don’t include the installations in the select, the field becomes null rather than a lazy loader for the list. I have also tried joining p.installations in, and it still can’t find the constructor. Without the list of Installations, it works beautifully.

Is there a way to get a Collection into my partial select?

Thanks,
-Lars

  • 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-15T15:01:29+00:00Added an answer on May 15, 2026 at 3:01 pm

    You can’t use a collection-valued path-expression in a constructor expression. Quoting the JPA 1.0 specification:

    4.8 SELECT Clause

    The SELECT clause denotes the query
    result. More than one value may be
    returned from the SELECT clause of a
    query.

    The SELECT clause may contain one or
    more of the following elements: a
    single range variable or
    identification variable that ranges
    over an entity abstract schema type, a
    single-valued path expression, an
    aggregate select expression, a
    constructor expression.

    The SELECT clause has the following
    syntax:

    select_clause ::= SELECT [DISTINCT] select_expression {, select_expression}*
    select_expression ::=
             single_valued_path_expression |
             aggregate_expression |
             identification_variable |
             OBJECT(identification_variable) |
             constructor_expression
    constructor_expression ::=
             NEW constructor_name ( constructor_item {, constructor_item}* )
    constructor_item ::= single_valued_path_expression | aggregate_expression
    aggregate_expression ::=
             { AVG | MAX | MIN | SUM } ([DISTINCT] state_field_path_expression) |
             COUNT ([DISTINCT] identification_variable | state_field_path_expression |
                       single_valued_association_path_expression)
    

    JPA 2.0 gives you a bit more of power for the constructor_item (see this answer) but, still, you won’t be able to pass a collection-valued path-expression.

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

Sidebar

Related Questions

In my business model I have Entity class (IPoint interface ) that has a
Suppose you have class B with lazily loaded property c . And that this
I have a class called ReportRequest as: public class ReportRequest { Int32 templateId; List<Int32>
I have a one-directional many-to-many association: the ListDefinition class has the Columns property of
I have an inheritance hierarchy with overlap. The system knows about People that can
Hibernate has a handful of methods that, one way or another, takes your object
I have an odd problem. I have a number of C# apps that utilize
I have a problem getting my change(s) to data object retrieved using NHibernate to
We are just starting to migrate/reimplement an ERP system to Java with Hibernate, targeting
My understanding of Hibernate is that as objects are loaded from the DB they

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.