I have to ask it, I almost tried everything.
Entity Class
@Entity
@Table(name="UserInfo")
public class User {
@Id@Column(name="user_name")
private String userName;
@Column(name="user_id")
private Integer userId;
}
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
<property name="hibernate.connection.url">jdbc:sqlserver://localhost:1433;databaseName=BankingApplication</property>
<property name="hibernate.connection.username">sa</property>
<property name="hibernate.connection.password">2OmniWay</property>
<!-- org.hibernate.HibernateException: No CurrentSessionContext configured! -->
<property name="hibernate.current_session_context_class">thread</property>
<property name="hibernate.default_schema">dbo</property>
<!-- Mapping with model class containing annotations -->
<mapping class="pojo.User"/>
</session-factory>
</hibernate-configuration>
SeesionFactory
// Create the SessionFactory from hibernate.cfg.xml
Configuration configuration = new Configuration();
configuration.configure("hibernate-annotation.cfg.xml");
System.out.println("Hibernate Annotation Configuration loaded");
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder(). applySettings(configuration.getProperties()).build();
System.out.println("Hibernate Annotation serviceRegistry created");
SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry);
return sessionFactory;
Getting Object saved in DB
SessionFactory sessionFactory = HibernateUtil.getSessionAnnotationFactory();
Session session = sessionFactory.openSession();
Account account = null;
try{
account = (Account) session.get(Account.class, id);
I am getting exception mentioned in subject. I just tripled checked everything but it is just not working.
Any suggestion would be helpful.
___________Stack Trace_________
Exception in thread "main" org.hibernate.UnknownEntityTypeException: Unable to locate persister: pojo.User
at org.hibernate.internal.SessionFactoryImpl.locateEntityPersister(SessionFactoryImpl.java:792)
at org.hibernate.internal.SessionImpl.locateEntityPersister(SessionImpl.java:2652)
at org.hibernate.internal.SessionImpl.access$2500(SessionImpl.java:164)
at org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.<init>(SessionImpl.java:2590)
at org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.<init>(SessionImpl.java:2577)
at org.hibernate.internal.SessionImpl.byId(SessionImpl.java:1044)
at org.hibernate.internal.SessionImpl.get(SessionImpl.java:955)
at business.ManageAccount.getAccountDetails(ManageAccount.java:18)
at Utils.TestConnecttion.main(TestConnecttion.java:16)