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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:27:15+00:00 2026-05-13T17:27:15+00:00

I have the following two table (which are tied in with Spring security –

  • 0

I have the following two table (which are tied in with Spring security – but the issue I believe is with Hibernate):

Table user
Table authority

The user table is tied (through Hibernate) to a domain object in my application: class User, which has the following attributes (and corresponding getters and setters), which correspond to columns in the user table (except for the Collection which is explained later):

long uId
String username
String password
...
Collection<GrantedAuthority> authorities

The authority table has 2 columns: UserId (foreign key into user table), and Authority (e.g. “ROLE_USER”). This table is NOT represented as a domain object, but is simply a collection in the User class.

To create the mapping, in my .hbm file I use the following:

<class name="com.business.project.domain.User" table="user">
    <id name="uId" column="UserId"></id>
    <property name="username" column="Name" type="java.lang.String" />
    <property name="password" column="Password" type="java.lang.String" />
    ...
    <set name="authorities" table="authority">
        <key column="UserId" />
        <element column="Authority" type="java.lang.String" />
    </set>
</class>

In my hibernate DAO implementation, I create a query object, execute the query, and cast the result to a User object:

...
Query query = session.createQuery("from User where name = :username");
...
User user = (User) query.uniqueResult();

At this point, I would expect this object to be populated with the data that it pulled from the DB (I made sure that the tables are populated properly with test data and the mapping names are correct in the mapping file).

However, calling the getter methods for various attributes on the user object all return NULL for some reason. Can somebody see something immediately wrong with my setup? Perhaps I mapped the collection (to foreign key relationship) wrong? THANKS!

Update: here is the sql query that hibernate generated (taken from its DEBUG output):

Hibernate: select user0_.UserId as UserId1_, user0_.Name as Name1_, 
  user0_.Password as Password1_ from user user0_ where user0_.Name=?

For some reason, it doesn’t show anything related to the authority table…does this mean that my mapping is incorrect?

Edit: Per bozho’s suggestion, I took a look at the messages on the consol on startup (tomcat), but didn’t see anything out of the ordinary:

Feb 16, 2010 10:35:12 AM org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: com.me.project.domain.User -> user
Feb 16, 2010 10:35:12 AM org.hibernate.cfg.HbmBinder bindCollection
INFO: Mapping collection: com.me.project.domain.User.authorities -> authority
  • 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-13T17:27:16+00:00Added an answer on May 13, 2026 at 5:27 pm
    Query query = session.craeteQuery("FROM User WHERE username = :username");
    query.setString("username", "SomeUserName");
    

    That should pretty much do it.

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

Sidebar

Related Questions

I have the following two queries (*) , which only differ in the field
HI, I have the following table which save agent ranking on daily basis on
So I have a database, within which there is a table with two columns:
I have the following table, from which i have to fetch non unique rows
I have two MySQL tables, here's how they are structured: table foo( foo_id varchar(32),
I have the following trigger on a table that redirects data and includes data
I have two tables, a current table and an archive table. When searching for
How to suppress field depending upon next data field change? I have datas (two
Hey guys, I am really messing up with this. I tried this but it
Technology: Java 1.5 or 1.6 Hibernate 3.4 To avoid update of column name on

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.