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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:13:19+00:00 2026-05-18T20:13:19+00:00

I really want to understand what is going on with my code. I have

  • 0

I really want to understand what is going on with my code.

I have a standalone application which uses spring and Hibernate as JPA and I am trying to run the test using a single main Class

My main class

package edu.acct.tsegay.common;

import edu.acct.tsegay.model.User;
import edu.acct.tsegay.business.IUserBusinessObject;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class App {
    public static void main(String[] args) {
        try {
            ApplicationContext context = new ClassPathXmlApplicationContext(
                    "Spring3AndHibernate-servlet.xml");
            IUserBusinessObject userBusinessObject = (IUserBusinessObject) context
                    .getBean("userBusiness");

            User user = (User) context.getBean("user1");
            user.setPassword("pass");
            user.setUsername("tsegay");
            System.out.println(user.getPassword());

            userBusinessObject.delete(user);

            User user2 = new User();
            user2.setUsername("habest");
            user2.setPassword("pass1");
            System.out.println(user2.getPassword());
            /*
             * userBusinessObject.save(user2);
             * 
             * User user3 = userBusinessObject.searchUserbyId("tsegay");
             * System.out.println("Search Result: " + user3.getUsername());
             */
            System.out.println("Success");
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

}

my application context is:

<beans xmlns="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-2.5.xsd">

    <!-- data source -->
    <bean id="dataSource"
        class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver" />
        <property name="url" value="jdbc:mysql://localhost:3306/test" />
        <property name="username" value="test" />
        <property name="password" value="password" />
    </bean>

    <!-- session factory -->
    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">

        <property name="dataSource">
            <ref bean="dataSource" />

        </property>

        <property name="hibernateProperties">

            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
                <prop key="hibernate.show_sql">true</prop>
            </props>
        </property>



    </bean>

    <!-- exposed person business object -->
    <bean id="userBusiness" class="edu.acct.tsegay.business.UserBusinessObject">
        <property name="userDao" ref="userDao" />

    </bean>
    <bean id="user1" class="edu.acct.tsegay.model.User">
        <property name="username" value="tse" />
        <property name="password" value="pass" />
    </bean>


    <!-- Data Access Object -->
    <bean id="userDao" class="edu.acct.tsegay.dao.UserDao">
        <property name="sessionFactory" ref="sessionFactory" />
    </bean>


</beans>

My User Model is:

package edu.acct.tsegay.model;

import java.io.Serializable;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Version;

import org.hibernate.annotations.NaturalId;

@Entity
public class User implements Serializable {
    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    private String username;
    private String password;
    private Integer VERSION;

    @Version
    public Integer getVERSION() {
        return VERSION;
    }

    public void setVERSION(Integer vERSION) {
        VERSION = vERSION;
    }
    @NaturalId
    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;
    }

}

My DAO is:

package edu.acct.tsegay.dao;

import edu.acct.tsegay.model.User;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;

import org.springframework.stereotype.Repository;

@Repository
public class UserDao implements IUserDao {
    private SessionFactory sessionFactory;

    private HibernateTemplate hibernateTemplate;

    public SessionFactory getSessionFactory() {
        return sessionFactory;
    }
    @Autowired
    public void setSessionFactory(SessionFactory sessionFactory) {
        this.sessionFactory = sessionFactory;
        this.hibernateTemplate = new HibernateTemplate(sessionFactory);
    }

    public void save(User user) {
        // TODO Auto-generated method stub
        // getHibernateTemplate().save(user);
        this.hibernateTemplate.save(user);
    }

    public void delete(User user) {
        // TODO Auto-generated method stub
        this.hibernateTemplate.delete(user);
    }

    public User searchUserbyId(String username) {
        // TODO Auto-generated method stub
        return this.hibernateTemplate.get(User.class, username);
    }

}

And this my stacktrace error when i run the program:

pass
org.springframework.orm.hibernate3.HibernateSystemException: Unknown entity: edu.acct.tsegay.model.User; nested exception is org.hibernate.MappingException: Unknown entity: edu.acct.tsegay.model.User
    at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:679)
    at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412)
    at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:411)
    at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
    at org.springframework.orm.hibernate3.HibernateTemplate.delete(HibernateTemplate.java:837)
    at org.springframework.orm.hibernate3.HibernateTemplate.delete(HibernateTemplate.java:833)
    at edu.acct.tsegay.dao.UserDao.delete(UserDao.java:34)
    at edu.acct.tsegay.business.UserBusinessObject.delete(UserBusinessObject.java:30)
    at edu.acct.tsegay.common.App.main(App.java:23)
Caused by: org.hibernate.MappingException: Unknown entity: edu.acct.tsegay.model.User
    at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:580)
    at org.hibernate.impl.SessionImpl.getEntityPersister(SessionImpl.java:1365)
    at org.hibernate.event.def.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:100)
    at org.hibernate.event.def.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:74)
    at org.hibernate.impl.SessionImpl.fireDelete(SessionImpl.java:793)
    at org.hibernate.impl.SessionImpl.delete(SessionImpl.java:771)
    at org.springframework.orm.hibernate3.HibernateTemplate$25.doInHibernate(HibernateTemplate.java:843)
    at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:406)
    ... 6 more
  • 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-18T20:13:20+00:00Added an answer on May 18, 2026 at 8:13 pm

    You have to list your classes in your session factory configuration. You can have your entities auto-discovered if you are using EntityManager.

    In order to use annotations with hibernate and spring, you have to use AnnotationSessionFactoryBean:

     <bean id="sessionFactory"
        class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        <property name="annotatedClasses">
            <list>
                <value>edu.acct.tsegay.model.User</value>
            </list>
        </property>
        ....
     </bean>
    

    Also, it is rather strange that your User entity is a spring bean. You don’t need that. Hibernate entities are supposed to be created with the new operator.

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

Sidebar

Related Questions

I really want to write .NET apps that run on any platform (PC, Linux
I really want to be able to have a way to take an app
I need to read the user's fingerprint from my application. What I really want
I really want to get the google Calendar Api up an running. I found
I really want to put in some sort of section handler into App.config that
I really want to know if I'm missing anything obvious in the software I'm
I've got an NSColor, and I really want the 32-bit RGBA value that it
I want to make a really simple iphone app: one screen with a single
I want to create a really easy to use 2D Grid. Each cell in
I want to start working with TDD but I don't know really where to

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.