1

Hi am developing an struts+hibernate website. I have an issue with the hibernate connection problem. When i am using it in my localhost it is working properly. The issue is i am using the same configuration file with the server database connection username and password the connection not open. I have write the error message to a file in server and it shows the error message as "Cannot open connection".

Here is my hibernate configuration file

<?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">
<?xmsl version="1.0" encoding="UTF-8"?>
<hibernate-configuration>
  <session-factory name="session1">
    <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
    <property name="hibernate.connection.driver_class">org.gjt.mm.mysql.Driver</property>
    <property name="hibernate.connection.url">jdbc:mysql://localhost/dev_mydatabase?autoReconnect=false</property>
    <property name="hibernate.connection.username">myusername(not original)</property>
    <property name="hibernate.connection.password">mypassword(no original)</property>
    <property name="show_sql">true</property>
    <property name="hibernate.cglib.use_reflection_optimizer">false</property>
    <property name="current_session_context_class">managed</property>
    <property name="hibernate.c3p0.max_statements">50</property>

    <!-- For seeing hibernate log on the console -->
    <property name="show_sql">true</property>
   <!-- End-->

    <property name="hibernate.hbm2ddl.auto">update</property>
    <property name="log4j.logger.org.hibernate.SQL">trace</property>
    <!--    <property name="hbm2ddl.auto">update</property>-->

<!-- All my mapping files are here.-->
  </session-factory>
</hibernate-configuration>

and in my dao file i write query as

SessionFactory sessionFactory =
                    (SessionFactory) ServletActionContext.getServletContext().getAttribute(HibernateListener.KEY_NAME);
            Session Hibernatesession = sessionFactory.openSession();
            Hibernatesession.beginTransaction();
            doctorList = Hibernatesession.createCriteria("Hibernate query will be here").

I don't understand what is the issue occured here. Any one please help me.

Thanks.

0

1 Answer 1

1

The problem is the localhost in your hibernate config as shown below. Change it to point to the actual db address and port.

 <property name="hibernate.connection.url">jdbc:mysql://localhost/dev_mydatabase?autoReconnect=false</property>
Sign up to request clarification or add additional context in comments.

4 Comments

No the connection details i provide here is dummy data. The actual data in my hibernate config file is different. I have tested the connection with a simple jsp page. it worked perfectly.
@anoopkattodi post the stacktrace then
actually i don't know how to take stracktrace from server. I have uses log4j for getting the log from the server. It only says could no open connection..
Guys it is worked. The problem was not really in the configuration file. I have used different different database name in my server so i need to change it in my hbm files. Once it change and restart tomcat it worked. Anyway thank you Panega

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.