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

The Archive Base Latest Questions

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

I have two tables as below. User Acc is user’s profile details and user’s

  • 0

I have two tables as below.enter image description here

“User Acc” is user’s profile details and user’s login details(username password) are in a seperate table called login.When I generated the entities in Netbeans IDE, there were 2 tables for login(database) table. One generated entity is “Login”, another one is “LoginId”.Login entity has a reference to LoginId and UserAcc entity. LoginId entity has username and password which were in login database table.UserAcc has primary key which is INT for each user.That key is the foreign key of login table.

Now I want to check the user @ loging. How I do is, I create a LoginId instance and set the user name and password and then check any object which has same LoginId. Here is the code.
uName and pw are strings and taken from user input.

  LoginId id=new LoginId(uName, pw);

 Session ses = NewHibernateUtil.getSessionFactory().openSession();            
 Criteria crit = ses.createCriteria(Login.class);
 crit.add(Restrictions.eq("id", id));
 Entities.Login log = (Entities.Login)crit.uniqueResult();

But eventhough there are existing usernames and passwords matching with given username and password, the log is always null.

Any one tell me where I should check and what the problem is. Thank you.
And my other problem is why a separate entity(“LoginId”) is created for two columns(primary keys) in one database table and another entity for that its database table .

for login;

<hibernate-mapping>
<class name="Entities.Login" table="login" catalog="pcw">
    <composite-id name="id" class="Entities.LoginId">
        <key-property name="uname" type="string">
            <column name="uname" length="10" />
        </key-property>
        <key-property name="pw" type="string">
            <column name="pw" length="10" />
        </key-property>
    </composite-id>
    <many-to-one name="useracc" class="Entities.Useracc" fetch="select">
        <column name="UserAcc_uid" not-null="true" />
    </many-to-one>
</class>

for UserAcc:

<hibernate-mapping>
<class name="Entities.Useracc" table="useracc" catalog="pcw">
    <id name="uid" type="java.lang.Integer">
        <column name="uid" />
        <generator class="identity" />
    </id>
    <property name="fname" type="string">
        <column name="fname" length="45" />
    </property>
    <property name="sname" type="string">
        <column name="sname" length="45" />
    </property>
    <property name="RDate" type="date">
        <column name="r_date" length="10" />
    </property>
    <property name="street" type="string">
        <column name="street" length="45" />
    </property>
    <property name="city" type="string">
        <column name="city" length="45" />
    </property>
    <property name="email" type="string">
        <column name="email" length="45" />
    </property>
    <property name="tel" type="string">
        <column name="tel" length="45" />
    </property>
    <set name="comments" inverse="true" cascade="all">
        <key>
            <column name="UserAcc_uid" not-null="true" />
        </key>
        <one-to-many class="Entities.Comment" />
    </set>
    <set name="logins" inverse="true" cascade="all">
        <key>
            <column name="UserAcc_uid" not-null="true" />
        </key>
        <one-to-many class="Entities.Login" />
    </set>
</class>

  • 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-25T21:29:08+00:00Added an answer on May 25, 2026 at 9:29 pm

    Anyway you can use HQL to solve it it will look more and less like this:

    public boolean authenticate(Sting username,String pass){
    Session ses = NewHibernateUtil.getSessionFactory().openSession();            
    String sql = "from Login login where login.username:= username and login.pass = :=pass";
    Query query = session.createQuery(sql);
    query.setString("username",username);
    query.setString("pass",pass);
    List<Login> result = query.list();
     //close session, transaction,etc....
    if (result ==null)
      return false;
    else
      return true;
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the two tables below. The table jobs will have a user id
Hi ok I have two tables one called Login and one called User there
so I have two tables. They are pictured below. I have a master table
Say I have two tables, user and comment . They have table definitions that
I have two tables User & User Log . User log table basically logs
I have two tables. Table user contains user_id, user_name. Table Transactions contains user_id, transactions
I have two tables like the ones below. I need to find what exchangeRate
I have 10 tables in my database(MySQL). two of them is given below tbl_state
I have two tables A and B as defined bellow. create table A (
I have two tables in my database, called ratings and movies . Ratings: |

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.