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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:00:07+00:00 2026-06-10T08:00:07+00:00

My scenario is a users table and a pictures table. Each user can upload

  • 0

My scenario is a users table and a pictures table. Each user can upload multiple pictures. Each user can set one of their own pictures to be their favourite picture, but this does not affect that picture being within that user’s collection of pictures.

Mapping this to hibernate has proven to be difficult. My application has a screen which displays a list of all of a user’s pictures, and also says which one is their favourite. However, when the application loads the pictures, the single picture which is the favourite one does not load. Debugging in eclipse shows various fun things for that specific object in the list, perhaps it is a proxy object. Here is the entity code showing the mappings:

@Entity
class Account {
    @Id
    public String username;

    /* Originally a Set<Picture>, but wanted ordering */
    @OneToMany(cascade=CascadeType.ALL, mappedBy="account")
    @OrderBy("uploadtime DESC")
    public List<Picture> pictures;

    @ManyToOne(fetch = FetchType.LAZY, optional=true)
    @LazyToOne(LazyToOneOption.PROXY)
    @JoinColumn(name="favourite_picture_id")
    public Picture favourite_picture;

    /* Sometimes it is useful to get just the id, if possible without loading the entire entity */
    @OneToOne(fetch = FetchType.LAZY, optional=true)
    @Column(insertable=false, updatable=false)
    public String favourite_picture_id;
}

@Entity
public class Picture {
    @Id
    @GeneratedValue(generator="uuid")
    @GenericGenerator(name="uuid", strategy="uuid2")
    public String id;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name="username")
    public Account account;

    /* This is never used, but I thought this might be required for the mapping? */
    @OneToOne(mappedBy="favourite_picture")
    public Account account_favourite_picture;


    public String mimetype;

    public Date uploadtime = new Date();

    @Column(length=1024 * 1024 * 4)
    public byte[] data;
}

I do not know why the favourite picture fails to load in the list of pictures. Any suggestions will be highly appreciated 😀

  • 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-10T08:00:08+00:00Added an answer on June 10, 2026 at 8:00 am

    Since a Picture has a specific Account which owns it I would be tempted just to include a boolean property on the Picture class called isFavourite. This would simplify the mappings considerably.

    You could provide a getFavourite method on the Account class which returns the favourite picture by looking through the list of pictures and finding the one marked as favourite.

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

Sidebar

Related Questions

I'm adding some functionality to my site so that users can upload their own
Here's my simple scenario: I've a Users table and a Locations table. ONE User
Scenario: We have 5 users. (users table) Each user has up to 10 imgs.
I have this scenario... 1.- I'm providing a Dynamic Table for wich users can
I'm not familiar on how forms work. Example Scenario Lets say users can create
Scenario: User X1 logged in. He can not be logged again. up to previous
I am having the scenario with multiple linq include methods with table object associations.
Scenario: I have users that want to be able to change their username (unfortunately
Scenario : I have a users table in my application. I also have two
I have 2 tables - an Account table and a Users table. Each account

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.