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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:11:02+00:00 2026-06-12T21:11:02+00:00

Say we have a User class with UserType property defined: private UserType userType; Is

  • 0

Say we have a User class with UserType property defined:

private UserType userType;

Is it possible to set this property using only ID of needed UserType? Something like

public void setUserTypeById(Long id){
   this.userType.setId(id); 
}

But this one will only change the id property of assigned UserType instance, while I need to change it to another one.

  • 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-12T21:11:04+00:00Added an answer on June 12, 2026 at 9:11 pm

    In theory, it would be possible, if you had access to a session or to a DAO in your User class. Then you could just retrieve then UserType corresponding to the given ID and set it.

    But I do not recommend this. I think it is better to clearly separate the domain classes (User, UserType) from the persistence classes (DAOs or session). Better create a service class (UserService for instance) that has a method setUserType(User user, int typeId) which takes care of this.

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

Sidebar

Related Questions

I have a user defined class, say import java.util.Calendar; public class Employee{ private String
Let's say I have following POJO's using Hibernate. public class User { private String
Lets say I have a class like this: Class User { var $id var
Say I have a class, User: public class User { private String name; private
Say I have a User model in JavaScript that looks something like this: var
Let's say I have one class User, and it has a property of type
Say I have a three models that look (basically) like this: class User <
Let's say I have this object: [JsonObject] public class User { [JsonProperty(PropertyName = id)]
Let's say I have a user class setup with validation like this: [MetadataType(typeof(ssUserMetaData))] public
Say I have a model like this public class User { [Required] [StringLength(14, ErrorMessage

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.