-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Not able to configure Hibernate5 in project
PostPosted: Wed Dec 23, 2015 1:16 pm 
Newbie

Joined: Tue Dec 22, 2015 2:07 pm
Posts: 4
I am trying to develop small application using hibernate, but i am getting exception, previously i was getting exception "UnknownEntityTypeException: Unable to locate persister". After reading in some of the forums i added my domain classes and hbm file in hibernate util. but now i am getting exception java.lang.IllegalStateException: Could not locate SessionFactory in JNDI
---------------------------------------------------------------------------------------------------
public class HibernateUtil {

private static SessionFactory sessionFactory;

// private static SessionFactory buildSessionFactory() {
// try {
// // Create the SessionFactory from hibernate.cfg.xml
// Configuration configuration = new Configuration().configure("hibernate.cfg.xml");
// return new Configuration().configure().buildSessionFactory();
// } catch (Throwable ex) {
// System.err.println("Initial SessionFactory creation failed." + ex);
// throw new ExceptionInInitializerError(ex);
// }
// }

public static SessionFactory getSessionFactory() {
if (sessionFactory == null) {
final StandardServiceRegistry registry = new StandardServiceRegistryBuilder().configure().build();
Metadata metadata = (Metadata) new MetadataSources( registry )
.addAnnotatedClass(Department.class )
.addAnnotatedClassName("com.cms.domain.Department")
.addAnnotatedClass(Logindtl.class)
.addAnnotatedClassName("com.cms.domain.Logindtl")
.addAnnotatedClass(Userdtl.class)
.addAnnotatedClassName("com.cms.domain.Userdtl")
.addAnnotatedClass(Userrole.class)
.addAnnotatedClassName("com.cms.domain.Userrole")
.addResource("/hibernate-mapping/Department.hbm.xml")
.addResource("/hibernate-mapping/Logindtl.hbm.xml")
.addResource("/hibernate-mapping/Userdtl.hbm.xml")
.addResource("/hibernate-mapping/Userrole.hbm.xml");

sessionFactory = metadata.getSessionFactoryBuilder().build();
// Configuration configuration = new Configuration().configure();
// ServiceRegistry serviceRegistry
// = new StandardServiceRegistryBuilder()
// .applySettings(configuration.getProperties()).build();
//
// // builds a session factory from the service registry
// sessionFactory = configuration.buildSessionFactory(serviceRegistry);
}

return sessionFactory;
}

public static void shutdown() {
// Close caches and connection pools
getSessionFactory().close();
}
}
-------------------------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.password">root</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/cmsdb</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="show_sql">true</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<property name="hibernate.current_session_context_class">org.hibernate.context.internal.ThreadLocalSessionContext</property>

<mapping resource="/hibernate-mapping/Department.hbm.xml" class="com.cms.domain.Department"/>
<mapping resource="/hibernate-mapping/Logindtl.hbm.xml" class="com.cms.domain.Logindtl"/>
<mapping resource="/hibernate-mapping/Userdtl.hbm.xml" class="com.cms.domain.Userdtl"/>
<mapping resource="/hibernate-mapping/Userrole.hbm.xml" class="com.cms.domain.Userrole"/>

</session-factory>
</hibernate-configuration>

--------------------------------------------------------------------

Dec 23, 2015 10:31:15 PM org.apache.catalina.core.StandardContext loadOnStartup
SEVERE: Servlet [cms] in web application [/cms] threw load() exception
java.lang.IllegalStateException: Could not locate SessionFactory in JNDI
at com.cms.dao.daoimpl.LogindtlDaoImpl.getSessionFactory(LogindtlDaoImpl.java:37)
at com.cms.dao.daoimpl.LogindtlDaoImpl.<init>(LogindtlDaoImpl.java:30)
at com.cms.service.serviceimpl.LoginServiceImpl.<init>(LoginServiceImpl.java:18)
at com.cms.controller.LoginController.<init>(LoginController.java:25)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:147)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:89)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1098)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1050)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)
at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:668)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:634)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:682)
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:553)
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:494)
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
at javax.servlet.GenericServlet.init(GenericServlet.java:158)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1231)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1144)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1031)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4997)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5289)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
--------------------------------------------------------------------------------------------------------------------------------
Could you please help me into this.


Top
 Profile  
 
 Post subject: Re: Not able to configure Hibernate5 in project
PostPosted: Thu Dec 24, 2015 10:13 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
Since your using Spring already, it's easier to use the Spring support for bootstrapping Hibernate. You might want to switch to JPA annotations too.


Top
 Profile  
 
 Post subject: Re: Not able to configure Hibernate5 in project
PostPosted: Thu Dec 24, 2015 11:50 am 
Newbie

Joined: Tue Dec 22, 2015 2:07 pm
Posts: 4
Hi thanks for your valuable time. actually i don't want to use annotation. i want to develop this application without annotation.


Top
 Profile  
 
 Post subject: Re: Not able to configure Hibernate5 in project
PostPosted: Thu Dec 24, 2015 12:26 pm 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
Then you can use the xml configurations as well.


Top
 Profile  
 
 Post subject: Re: Not able to configure Hibernate5 in project
PostPosted: Fri Dec 25, 2015 12:11 am 
Newbie

Joined: Tue Dec 22, 2015 2:07 pm
Posts: 4
i am using xml configurations, but what i am missing. t..
----------------------------------------------------------------------------------------------
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Dec 11, 2015 12:15:06 AM by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<class name="com.cms.domain.Logindtl" table="logindtl" catalog="cmsdb">
<id name="userid" type="string">
<column name="USERID" length="7" />
<generator class="assigned" />
</id>
<property name="password" type="string">
<column name="PASSWORD" length="45" not-null="true" />
</property>
<set name="userdtls" table="userdtl" inverse="true" lazy="true" fetch="select">
<key>
<column name="USERID" length="7" not-null="true" />
</key>
<one-to-many class="com.cms.domain.Userdtl" />
</set>
</class>
</hibernate-mapping>
------------------------------------------------------------------------------
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Dec 11, 2015 12:15:06 AM by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<class name="com.cms.domain.Department" table="department" catalog="cmsdb">
<id name="id" type="int">
<column name="ID" />
<generator class="assigned" />
</id>
<property name="description" type="string">
<column name="DESCRIPTION" length="45" not-null="true" />
</property>
<set name="userdtls" table="userdtl" inverse="true" lazy="true" fetch="select">
<key>
<column name="DEPTID" not-null="true" />
</key>
<one-to-many class="com.cms.domain.Userdtl" />
</set>
</class>
</hibernate-mapping>
--------------------------------------------------------------------------------------------------------------
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Dec 11, 2015 12:15:06 AM by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<class name="com.cms.domain.Userdtl" table="userdtl" catalog="cmsdb">
<id name="id" type="int">
<column name="ID" />
<generator class="assigned" />
</id>
<many-to-one name="department" class="com.cms.domain.Department" fetch="select">
<column name="DEPTID" not-null="true" />
</many-to-one>
<many-to-one name="userrole" class="com.cms.domain.Userrole" fetch="select">
<column name="ROLID" not-null="true" />
</many-to-one>
<many-to-one name="logindtl" class="com.cms.domain.Logindtl" fetch="select">
<column name="USERID" length="7" not-null="true" />
</many-to-one>
<property name="userfirstname" type="string">
<column name="USERFIRSTNAME" length="45" not-null="true" />
</property>
<property name="usermiddlename" type="string">
<column name="USERMIDDLENAME" length="45" />
</property>
<property name="userlastname" type="string">
<column name="USERLASTNAME" length="45" not-null="true" />
</property>
<property name="recidentaddress" type="int">
<column name="RECIDENTADDRESS" not-null="true" />
</property>
<property name="permentaddress" type="int">
<column name="PERMENTADDRESS" not-null="true" />
</property>
</class>
</hibernate-mapping>
-----------------------------------------------------------------------------------------
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Dec 11, 2015 12:15:06 AM by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<class name="com.cms.domain.Userrole" table="userrole" catalog="cmsdb">
<id name="id" type="int">
<column name="id" />
<generator class="assigned" />
</id>
<property name="description" type="string">
<column name="description" length="45" not-null="true" />
</property>
<set name="userdtls" table="userdtl" inverse="true" lazy="true" fetch="select">
<key>
<column name="ROLID" not-null="true" />
</key>
<one-to-many class="com.cms.domain.Userdtl" />
</set>
</class>
</hibernate-mapping>
----------------------------------------------------------

So could you please help me what i am missing.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.