0

I have two Virtual machines on an external server. VM1 is the Tomcat server and VM2 is the MySQL server. I have a web application on the tomcat server which I can access by typing the ip in my browser at my home computer, so that works as it should.

For example if the IP to VM1 is 111.22.33.44, then I can type this from anywhere and be able to access the homepage: http://111.22.33.44:8080/WebApplication1

But after that, as I try to login in my web application, I get an exception:

javax.persistence.PersistenceException: [PersistenceUnit: WebApplication1PU] Unable to build EntityManagerFactory

I can only assume that this has something to do with my external database server.

persistence.xml (x.x.x.x being the ip of VM2):

    <?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
  <persistence-unit name="WebApplication1PU" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <class>bo.User</class>
    <class>bo.LogMessage</class>
    <class>bo.PrivateMessage</class>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties>
      <property name="hibernate.connection.username" value="root"/>
      <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
      <property name="hibernate.connection.password" value="root"/>
      <property name="hibernate.connection.url" value="jdbc:mysql://x.x.x.x:3306/community"/>
      <property name="hibernate.cache.provider_class" value="org.hibernate.cache.NoCacheProvider"/>
    </properties>
  </persistence-unit>
</persistence>

What I have tried to do to fix it:

  • Grant privileges on the mysql server for VM1 ip+username.
  • Hmm, that's all I can remember at the moment, I'll edit this.

I can edit in the stack trace as well, if that would help.

Also: The two VMs have completely different ip addresses. I read something about changing RESOURCE_LOCAL to JTA, could that fix anything?

EDIT 1 traceroute gave 2 rows (hops?) I commented the bind 127.0.0.1 row in the my.conf file. Still doesn't work. Exception when trying to login at the home page of the web application. (Stack Trace):

javax.faces.el.EvaluationException: javax.persistence.PersistenceException: [PersistenceUnit: WebApplication1PU] Unable to build EntityManagerFactory
    at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:102)
    at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
    at javax.faces.component.UICommand.broadcast(UICommand.java:315)
    at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)
    at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)
    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:409)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:185)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:151)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:269)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:679)
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: WebApplication1PU] Unable to build EntityManagerFactory
    at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:677)
    at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:126)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:51)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:33)
    at db.UserDB.getUserByUsername(UserDB.java:49)
    at bo.UserHandler.UserLogin(UserHandler.java:30)
    at ui.UserBean.login(UserBean.java:56)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:616)
    at org.apache.el.parser.AstValue.invoke(AstValue.java:262)
    at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:278)
    at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
    at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
    ... 24 more
Caused by: org.hibernate.HibernateException: Hibernate Dialect must be explicitly set
    at org.hibernate.dialect.DialectFactory.determineDialect(DialectFactory.java:57)
    at org.hibernate.dialect.DialectFactory.buildDialect(DialectFactory.java:39)
    at org.hibernate.cfg.SettingsFactory.determineDialect(SettingsFactory.java:426)
    at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:128)
    at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2009)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1292)
    at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:859)
    at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:669)
    ... 38 more

EDIT 2 netstat -anltp | grep "LISTEN" on VM2 (mysql server)

tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN      -               
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      -               
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      -               
tcp6       0      0 :::22                   :::*                    LISTEN      -               
tcp6       0      0 ::1:631                 :::*                    LISTEN      - 

EDIT 3 netstat -anltp | grep "LISTEN" on VM2 (mysql server) NOW LISTENING TO EXTERNAL CONNECTIONS TO MYSQL (to do this see step 4 of this guide: link

tcp        0      0 0.0.0.0:3306          0.0.0.0:*               LISTEN      -               
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      -               
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      -               
tcp6       0      0 :::22                   :::*                    LISTEN      -               
tcp6       0      0 ::1:631                 :::*                    LISTEN      - 
6
  • I apologize if that was difficult to understand, I'm just so tired of working with this stuff all day.
    – Erik L
    Commented Jan 12, 2012 at 20:18
  • Have you been able to get the application running with a different database? Hibernate not being able to build the EntityManagerFactory can mean a lot of things: bad class mappings, unable to connect, firewall blocking ports, etc...
    – clmarquart
    Commented Jan 12, 2012 at 20:47
  • If you're sure you granted mysql access for "VM1 ip+username", is mysql on VM2 listening on port 3306 and accepting non-localhost connections? Commented Jan 12, 2012 at 20:48
  • Yes, the stack trace would help. Can you login to VM1 to test connectivity from there to VM2? Perhaps you don't have a route to it. You do not want to switch to JTA; it's for managing distributed transactions: stackoverflow.com/questions/1962525/…
    – jbindel
    Commented Jan 13, 2012 at 4:49
  • @R.Valbuena I'm not sure if mysql is listening to external connections or if the port is open for external connections. Not usre how to fix that either, I have Ubuntu on both of the VM's. -Fly I will edit in the stack trace and try ping/traceroute between the VM's
    – Erik L
    Commented Jan 13, 2012 at 17:36

1 Answer 1

1

I have made it work now, I basically followed steps 4-5 in this tutorial: Link: allowing external connections to mysql server

So basically add a user with privileges of your choice using mysql commands CREATE USER and GRANT.

you can view the mysql user table to see what users exist (this shows only some columns though):

select host,user,password from mysql.user;

One host in that table should be the IP of the tomcat server. As you can see in the tutorial you also have to edit the mysql config file, if ubuntu complains about rights, the sudo command might come in handy. just type sudo followed by a regular command. Keep in mind that I'm really new to Ubuntu so there might be an easier way to do all this. gedit can be used to edit files.

Not the answer you're looking for? Browse other questions tagged or ask your own question.