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

The Archive Base Latest Questions

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

I am using spring 3 + spring security 3 + hibernate. I have some

  • 0

I am using spring 3 + spring security 3 + hibernate.
I have some problems with mapping classes. I don’t know why, but some classes are mapped they can be used by Hibernate but at the same time some (which are used for Spring Security) are not!
forum-security.xml:

<beans:beans xmlns="http://www.springframework.org/schema/security" 
xmlns:beans="http://www.springframework.org/schema/beans" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
    http://www.springframework.org/schema/security 
    http://www.springframework.org/schema/security/spring-security-3.0.xsd">
<http auto-config='true'>
    <intercept-url pattern="/**" access="ROLE_USER" />
</http>
<authentication-manager>
    <authentication-provider user-service-ref="userDetailsService"/>
</authentication-manager>
</beans:beans>

UserServiceImpl:

package forum.service;
import java.util.List;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.User;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import forum.domain.ForumUser;

@Service
public class UserServiceImpl implements UserService{
    @Autowired private SessionFactory sessionFactory;
@Autowired private Assembler assembler;
public List<ForumUser> listAllUsers(){
    return null;
}
public List<ForumUser> listUsersBySellingPont(){
    return null;
}
@Transactional
public ForumUser getUserByUsername(String username){
    Session session = sessionFactory.getCurrentSession();
    List<ForumUser> users = session.createQuery("from ForumUser").list();
    ForumUser result = null;
    for(ForumUser user : users){
        if(user.getUsername().equals(username))
            result = user;
    }
    return result;
}
public void addUser(ForumUser user){

}
public void updateUser(ForumUser user){

}
public void deleteUser(Integer id){

}
}

Assembler:

package forum.service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import forum.domain.ForumUser;
import forum.domain.UserDetailsImpl;

@Service("assembler")
public class Assembler {
@Transactional(readOnly = true)
  UserDetailsImpl buildUserFromUserEntity(ForumUser userEntity) {
    Integer id = userEntity.getId();
    String username = userEntity.getUsername();
    String password = userEntity.getPassword();
    String email = userEntity.getEmail();
    Date enabled = userEntity.getEnabled();
    Date lastEntered = userEntity.getLastEntered();
    Date registered = userEntity.getRegistered();

    List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
    for (GrantedAuthority role : userEntity.getAuthorities()) {
      authorities.add(role);
    }
    UserDetailsImpl user = new UserDetailsImpl();
    user.setId(id);
    user.setUsername(username);
    user.setPassword(password);
    user.setEmail(email);
    user.setEnabled(enabled);
    user.setAuthorities(authorities);
    user.setLastEntered(lastEntered);
    user.setRegistered(registered);
    return user;
  }
}

And now classes that are not mapped by hibernate (other classes are mapped):

package forum.domain;

import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.FetchType;
import javax.persistence.CascadeType;

import org.springframework.security.core.GrantedAuthority;

@Entity
@Table(name="users")
public class ForumUser {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="id")
private Integer id;
@Column(name="username")
private String username;
@Column(name="password")
private String password;
@Column(name="email")
private String email;
@Column(name="registered")
private Date registered;
@Column(name="lastEntered")
private Date lastEntered;
@Column(name="enabled")
private Date enabled;
@OneToMany(cascade=CascadeType.REFRESH,fetch=FetchType.LAZY,mappedBy="forumUser")
private List<GrantedAuthority> authorities;
public Date getEnabled(){
    return enabled;
}
public void setEnabled(Date enabled){
    this.enabled = enabled;
}
public Integer getId(){
    return id;
}
public void setId(Integer id){
    this.id = id;
}
public String getUsername(){
    return username;
}
public void setUsername(String username){
    this.username = username;
}
public String getPassword(){
    return password;
}
public void setPassword(String password){
    this.password = password;
}
public String getEmail(){
    return email;
}
public void setEmail(String email){
    this.email = email;
}
public Date getRegistered(){
    return registered;
}
public void setRegistered(Date registered){
    this.registered = registered;
}
public Date getLastEntered(){
    return lastEntered;
}
public void setLastEntered(Date lastEntered){
    this.lastEntered = lastEntered;
}
public List<GrantedAuthority> getAuthorities() {
    return authorities;
}
public void setAuthorities(List<GrantedAuthority> authorities){
    this.authorities = authorities;
}
}

And the second class:

package forum.domain;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ManyToOne;
import javax.persistence.CascadeType;
import javax.persistence.JoinColumn;
import javax.persistence.Table;

import org.springframework.security.core.GrantedAuthority;

@Entity
@Table(name="authorities")
public class Authority implements GrantedAuthority{
@ManyToOne(cascade=CascadeType.REFRESH,fetch=FetchType.LAZY)
@JoinColumn(name="userId")
private ForumUser forumUser;
@Column(name="authority")
private String authority;
public String getAuthority() {
    return authority;
}
public void setAuthority(String authority) {
    this.authority = authority;
}
}

So when I am trying to retrieve an user by username from DB (UserServiceImpl.getUserByUsername() from ForumUser), it throws
org.hibernate.hql.ast.QuerySyntaxException: ForumUser is not mapped [from ForumUser]

And if I change thir HQL to another, for example “from Forum” (it is another class, that is working) it will throw another exception, doesn’t really matter what exactly, but the fact is that it mappes another class and can retrieve it.
How can I solve this problem?

  • 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-27T17:15:42+00:00Added an answer on May 27, 2026 at 5:15 pm

    Oh, I have found a solution! It all was because of my own inattention. I have forgotten to add new classes to a list of annotated persistent classes in my conf.

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

Sidebar

Related Questions

I'm using Spring, Spring Security, BlazeDS, Flex and spring-flex. I know that I can
I'm using Spring Security 3.0.2 form based authentication. But I can't figure out how
I am using Spring/Hibernate and Spring-Security for my web-based application. Now I have a
I'm using Spring Security 3.0.2 and I can't find a way to load roles
We're securing Mule services using the Spring Security Framework, and some of the services
I'm using Spring.net with NHiberante (HibernateTemplate) to implement my DAO's. I also have some
I have a simple POJO mapped to a table using Hibernate. Which works just
I am using spring, spring security, hibernate. Got a jsp page where i am
I'm using spring security 3 in my jsf2 web app. How can I show
I'm using Spring + Hibernate + JPA and I have a situation where I

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.