- This topic has 9 replies, 2 voices, and was last updated 18 years, 7 months ago by
Riyad Kalla.
-
AuthorPosts
-
ouafaaMemberhello,
i began to develop a small application with mysql, hibernate java and jsf.
i generated all maping files , i can excute the application (exemple insert some date from the database …)
i respect this syntax:
cfg = new Configuration().configure();
sessionFactory = cfg.buildSessionFactory();
session =sessionFactory.openSession();
session.close();but after 10 click (not sure) in the application i got the following error
org.apache.jasper.JasperException: javax.servlet.jsp.JspException: javax.faces.el.EvaluationException: Error getting property 'listdirections' from bean of type notation.BKNOTATION: org.hibernate.exception.GenericJDBCException: Cannot open connection org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264) javax.servlet.http.HttpServlet.service(HttpServlet.java:802) com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:322) com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:147) com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:87) com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200) com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:117) javax.faces.webapp.FacesServlet.service(FacesServlet.java:198)
thank you in advance for your help
Riyad KallaMemberWhat type of data source are you using? Session.close() is not closing the connection aparently and so you are leaking connections, default for MySQL is 10 I believe, so that makes sense. I would encourage you to use a container-managed datasource.
ouafaaMemberhello, thank you for you answer.
i’m using a jdbc connection driver to mysql.
why Session.close() is not closing opened session?
how can use container-managed datasource? does it replace hibernate?
thank you
Riyad KallaMemberActually the container managed datasource is just a way to allow your container (application server, like Tomcat, Sun App Server 9, Glassfish, WebLogic, etc.) to configure and provide connections to your database via JNDI. The good part about this is that the container will pool and manage the connections for you to improve performance.
So your old picture looks like this:
[DB] > [Java Driver Manager] > [Hibernate] > [Your Code]With container managed it will look like this:
[DB] > [Container Managed Datasource] > [Hibernate] > [Your Code]And Hibernate will use JNDI to read the datasource from your application server. Look at Table 3.2 here for properties for hibernate to use a JNDI datasource;
http://www.hibernate.org/hib_docs/v3/reference/en/html/session-configuration.html#configuration-hibernatejdbcand look here for information on how to configure it in Tomcat:
http://tomcat.apache.org/tomcat-5.5-doc/jndi-datasource-examples-howto.htmlTIP: Install the Tomcat Administration web application and use that to set up your datasource, it’s really easy.
ouafaaMemberhello,
i tried to configure the datasource.
in sever.xml i add<Resource
name=”jdbc/Mysql”
type=”javax.sql.DataSource”
password=”****”
driverClassName=”com.mysql.jdbc.Driver”
maxIdle=”100″
maxWait=”5000″
username=”root”
url=”jdbc:mysql://***.***.12.105:3306/notation?autoReconnect=true”
maxActive=”100″/>in web.xml off the application i add
<resource-ref> <description>DB Connection</description> <res-ref-name>jdbc/Mysql</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref>
and in hibernate.cfg.xml i add
<property name=”connection.driver_class”>com.mysql.jdbc.Driver</property>
<property name=”connection.url”>jdbc:mysql://192.168.12.105:3306/notation?autoReconnect=true</property><property name=”connection.username”>root</property>
<property name=”connection.password”>root</property>
<property name=”dialect”>org.hibernate.dialect.MySQLDialect</property>
<property name=”jndi.class”></property>
<property name=”connection.datasource”>jdbc/Mysql</property>
<property name=”jndi.url”></property>
<!– ### Apache DBCP Connection Pool ### –>
<!– connection pool –><property name=”dbcp.maxActive”>10</property>
<property name=”dbcp.whenExhaustedAction”>1</property>
<property name=”dbcp.maxWait”>20000</property>
<property name=”dbcp.maxIdle”>10</property>
<property name=”dbcp.initialSize”>2</property><!– prepared statement cache –>
<property name=”dbcp.ps.maxActive”>10</property>
<property name=”dbcp.ps.whenExhaustedAction”>1</property>
<property name=”dbcp.ps.maxWait”>20000</property>
<property name=”dbcp.ps.maxIdle”>10</property><!– optional query to validate pooled connections: –>
<property name=”dbcp.validationQuery”>select 1</property>
<property name=”dbcp.testOnBorrow”>true</property>
<property name=”dbcp.testOnReturn”>false</property>but it didn’t work ,i hane this error:
HibernateException: Could not find datasourceam i missing something?
thank you for your help.
Riyad KallaMemberIf I remember correctly you need the full JNDI connnection string:
<property name=”connection.datasource”>java:comp/env/jdbc/Mysql</property>
ouafaaMemberyes thank you very much, it’s working.
but i got this eror:
java.lang.OutOfMemoryError: Java heap space
when i added those 3 lines in server.xml:logAbandoned=”true”
removeAbandoned=”true”
removeAbandonedTimeout=”5″it’s work very well when i start tomcat from myeclipse.
but when i start it from the monitor tomcat program file i still have
java.lang.OutOfMemoryError: Java heap space error.
it’ seem that those properties are not used.
do you have any idea.
thank you in advance
Riyad KallaMemberYou likely need to give Tomcat more memory. You can do that by editing the startup arguments used to start Tomcat and include an argument like:
-Xmx256mYou can add that in MyEclipse under optional JDK arguments under the Tomcat connector if the problem is happening when it’s launched from MyEcliopse, or you can edit the batch file used to start Tomcat or you can edit the arguments for the Tomcat sevice if that’s what you are using to run it.
ouafaaMemberhello,
i tried to add -Xmx256m argument in startup argument like this start -Xmx256m but tomcat did not run.
in java argument, i add this:
initial memory pool: 32Mb
Maximum memory pool:256Mb
thread stack size:512Kbthe application work well now.
i’m not sure if those parameters meet your suggestion -Xmx256m .
any way, thank you very much for your help.
Riyad KallaMemberI’m glad to hear it’s working now, thank you for following up.
-
AuthorPosts