Scale up as you grow — whether you're running one virtual machine or ten thousand.

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.

Hello! Good afternoon! First of all, sorry for my english! So, My name is Josemar and I’m trying to make a project using Hibernate 4.3.5 / JPA 2.0 plus JNDI DataSource! Well I have already configured persistence.xml and server.xml / context.xml, but I don’t know how I can get EntityManagerFactory from jndi. When I try this: “Persistence.createEntityManagerFactory(“my_UP”)” it doesn’t work. Do you have some example about it? Thank you!
- Josemar Flausino
Hi Pankaj, I did not understand why have you specified driver class name in hibernate.cfg.xml file? because you already specified driver class name in in Context.xml file for tomcat.
- Farhan
Hi, thank you very much for this great tutorial! I’ve a couple of questions: 1) Is this setup a valid solution for enterprise web app with big number of users? 2) Is this using connection pooling? 3) You’re declaring the jdbc/MyLocalDB resource at server level. Can this be done at web app level (dynamic web project)? thanks!
- Luca
Thank you very much for your tutorials - they are very clearly written. This is the first one I’ve had trouble with: - I couldn’t get the java classes to compile - Eclipse could not import javax.servlet classes until I configured the build path and added the apache tomcat 7 library. This made the javac errors go away. - Then I exported the .war file … but you don’t tell us where to put it. By googling around, I read that it should to into the apache-tomcat-7.0/webapps directory, and that by stopping/restarting tomcat, it would uncompress this into a folder. - However, when I stopped/restarted tomcat *within* Eclipse, nothing happened. - So I stopped tomcat in Eclipse and then started it from the command line: bin/startup.sh - and this opened the folder into the webapps/ directory. - Then I loaded a browser but I got a connection error - incorrect database user+password. I had set these in the tomcat conf/server.xml file as you suggested: <Resource name=“jdbc/MyLocalDB” global=“jdbc/MyLocalDB” username = “…” - The fix was to edit the hibernate.cfg.xml file inside of webapps/HibernateDataSource/WEB-INF/classes and add in: root passwd And now it works(!) But … I don’t know if I am using Hibernate inside of Tomcat the way you designed (e.g., I’m not sure where exactly it is getting the jdbc mysql driver from). Can you suggest what is right/wrong here ? Thanks! -Mike
- Mike
Hi Pankaj, https://www.journaldev.com/3531/spring-mvc-hibernate-mysql-integration-crud-example-tutorial now i want to use jndi datasource for the above refered link. the below is the hibernate config file data. i am confusing how do i change the below configuration if i want to use jndi datasource. com.journaldev.spring.model.Person org.hibernate.dialect.MySQLDialect true each dao bean id is refering to session factory. could you please suggest me how do i change this config file.
- srini
You forgot to do configuration.addAnnotatedClass(Employee.class); at the contextInitialized method. Without it we have got exception: Exception in thread “main” org.hibernate.UnknownEntityTypeException: Unable to locate persister: servlet.hibernate.Employee
- Oleg
Hi Pankaj, I’ve been following your tutorials from long time. Well, here in this tutorial I’m getting NPE at line Session session = sessionFactory.getCurrentSession(); in GetCustomerByID class. I’m not able to figure out what’s the root cause. Here is the logs: Log: ------ Feb 07, 2017 11:20:29 AM org.apache.catalina.core.AprLifecycleListener init INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib Feb 07, 2017 11:20:29 AM org.apache.tomcat.util.digester.SetPropertiesRule begin WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property ‘source’ to ‘org.eclipse.jst.j2ee.server:HibernateConnectionsusingDataSourceAndJNDITest’ did not find a matching property. Feb 07, 2017 11:20:29 AM org.apache.coyote.AbstractProtocol init INFO: Initializing ProtocolHandler [“http-bio-8080”] Feb 07, 2017 11:20:29 AM org.apache.coyote.AbstractProtocol init INFO: Initializing ProtocolHandler [“ajp-bio-8009”] Feb 07, 2017 11:20:29 AM org.apache.catalina.startup.Catalina load INFO: Initialization processed in 986 ms Feb 07, 2017 11:20:29 AM org.apache.catalina.core.StandardService startInternal INFO: Starting service Catalina Feb 07, 2017 11:20:29 AM org.apache.catalina.core.StandardEngine startInternal INFO: Starting Servlet Engine: Apache Tomcat/7.0.54 Feb 07, 2017 11:20:30 AM org.apache.catalina.loader.WebappClassLoader validateJarFile INFO: validateJarFile(/home/dhiraj/MyWorkSpace/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/HibernateConnectionsusingDataSourceAndJNDITest/WEB-INF/lib/javax.servlet-api-3.0.1.jar) - jar not loaded. See Servlet Spec 3.0, section 10.7.2. Offending class: javax/servlet/Servlet.class Feb 07, 2017 11:20:30 AM org.apache.coyote.AbstractProtocol start INFO: Starting ProtocolHandler [“http-bio-8080”] Feb 07, 2017 11:20:30 AM org.apache.coyote.AbstractProtocol start INFO: Starting ProtocolHandler [“ajp-bio-8009”] Feb 07, 2017 11:20:30 AM org.apache.catalina.startup.Catalina start INFO: Server startup in 1348 ms Feb 07, 2017 11:20:36 AM com.journaldev.servlet.hibernate.GetEmployeeByID doGet INFO: Request Param empId=3 Feb 07, 2017 11:20:36 AM com.journaldev.servlet.hibernate.GetEmployeeByID doGet INFO: Here is the session factory object: null Feb 07, 2017 11:20:36 AM org.apache.catalina.core.StandardWrapperValve invoke SEVERE: Servlet.service() for servlet [com.journaldev.servlet.hibernate.GetEmployeeByID] in context with path [/HibernateConnectionsusingDataSourceAndJNDITest] threw exception java.lang.NullPointerException at com.journaldev.servlet.hibernate.GetEmployeeByID.doGet(GetEmployeeByID.java:35) at javax.servlet.http.HttpServlet.service(HttpServlet.java:620) at javax.servlet.http.HttpServlet.service(HttpServlet.java:727) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:745)
- Dhiraj Singh
Hi For all who have met with error - org.hibernate.UnknownEntityTypeException: Unable to locate persister. I encountered this error because I used hibernate 5.+. One line in contextInitialized solved the problem : configuration.addAnnotatedClass(Employee.class);
- Maciek