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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:58:33+00:00 2026-06-02T01:58:33+00:00

I’m new to hibernate. I have the following classes: @Entity @Table( name = Users

  • 0

I’m new to hibernate.

I have the following classes:

@Entity
@Table( name = "Users" )
public class User implements Serializable{

private static final long serialVersionUID = -3550174731709532722L;

private String userName;
private String pasportID;
private Company company; 
private String name;
private String email;
private String phone1;
private String phone2;
private String password; //may be null/empty , will be kept hashed
private boolean isAdmin;
private Date lastLogin;


User() {} //not public on purpose!


public User(String userName, String pasportID, Company company,
        String name, String email, String phone1, String phone2,
        String password, boolean isAdmin) {
    this.userName = userName;
    this.pasportID = pasportID;
    this.company = company;
    this.name = name;
    this.email = email;
    this.phone1 = phone1;
    this.phone2 = phone2;
    this.password = password;
    this.isAdmin = isAdmin;
}


@Id
public String getUserName() {
    return userName;
}

public void setUserName(String userName) {
    this.userName = userName;
}

@OneToOne(cascade = CascadeType.ALL)
public Company getCompany() {
    return company;
}

public void setCompany(Company company) {
    this.company = company;
}
public String getName() {
    return name;
}
public void setName(String name) {
    this.name = name;
}

public String getEmail() {
    return email;
}
public void setEmail(String email) {
    this.email = email;
}

public String getPhone1() {
    return phone1;
}
public void setPhone1(String phone1) {
    this.phone1 = phone1;
}

public String getPhone2() {
    return phone2;
}
public void setPhone2(String phone2) {
    this.phone2 = phone2;
}

public String getPassword() {
    return password;
}
public void setPassword(String password) {
    this.password = password;
}

public boolean isAdmin() {
    return isAdmin;
}

public void setAdmin(boolean isAdmin) {
    this.isAdmin = isAdmin;
}

@Temporal(TemporalType.TIMESTAMP) 
public Date getLastLogin() {
    return lastLogin;
}

public void setLastLogin(Date lastLogin) {
    this.lastLogin = lastLogin;
}


public String getPasportID() {
    return pasportID;
}


public void setPasportID(String pasportID) {
    this.pasportID = pasportID;
    }
}

And:

@Entity
@Table( name = "COMPANIES" )
/**
 * This class is an entity class that represent the company object in the database.
 * This class holds no logic, only getters, setter and constructors.
 */
public class Company implements Serializable {


    private static final long serialVersionUID = -4809404779999217296L;

    private long companyID;
    private CompanyType companyType;
    private String name;

    Company() {} //not public on purpose!

    public Company(String name, CompanyType companyType) {
        this.companyType = companyType;
        this.name = name;
    }


    @Id
    @GeneratedValue(generator="increment")
    @GenericGenerator(name="increment", strategy = "increment")
    public long getCompanyID() {
        return companyID;
    }
    public void setCompanyID(long companyID) {
        this.companyID = companyID;
    }

    @Enumerated(EnumType.STRING)
    public CompanyType getCompanyType() {
        return companyType;
    }
    public void setCompanyType(CompanyType companyType) {
        this.companyType = companyType;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }

}

And the enum:

public enum CompanyType { A,B,C //TODO }

I want to get a list of all the users that work in company “companyName”.
please nitice that User contains a refference to Company.

I’m quite sure a join query is required, but I can’t seem to nail the syntax.

I would very much appriciate your help with that.

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-06-02T01:58:35+00:00Added an answer on June 2, 2026 at 1:58 am

    First of all change the mapping from user to company to from ..as many users can belong to one comapny.

    <many-to-one name="company>
    </many-to-one>
    

    Then you can use the following query.
    “from user u left outer join u.company where u.company.companyName=’XYZ'”

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I want use html5's new tag to play a wav file (currently only supported
I am doing a simple coin flipping experiment for class that involves flipping a
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into

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.