Technologies: JSF, Hibernate 3, eclipse. Glassfish server
My website works 100% locally but when I deployed it, it just closes the connection after a while.
I thought of using a connection pool to avoid this issue
I downloaded the jar file c3p0-0.9.2.1.jar and added it in java class path an added the following configs in hibernate.cfg.xml and hibernate-c3p0-4.3.10.Final.jar
<property name="hibernate.c3p0.min_size">5</property>
<property name="hibernate.c3p0.max_size">20</property>
<property name="hibernate.c3p0.timeout">300</property>
<property name="hibernate.c3p0.max_statements">50</property>
<property name="hibernate.c3p0.idle_test_period">3000</property>
and it gives an error that a class named LogM is not found. might the jar file I used be a wrong one? or did I miss a step?
Caused by: java.lang.ClassNotFoundException: com.mchange.v2.log.MLog
Related
I am following this link to generate hibernate file
https://www.mkyong.com/hibernate/how-to-generate-code-with-hibernate-tools/
the files are generated but without annotation.
I checked the "generate EJB3 annotation " but still it is not working
the DB is Postgres.
I use to do it the same way and it was working fine..
few weeks ago I upgrade to eclipse to oxygen and change my workplace
since then it is not working..
does any body know if there is a log file for the activity ? maybe I can find some thing there ?
this is my hibernate.cfg.xml file
<property name="hibernate.bytecode.use_reflection_optimizer">false</property>
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.password">password</property>
<property name="hibernate.connection.url">jdbc:postgresql://xxxxx/yyy</property>
<property name="hibernate.connection.username">user</property>
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<!-- <property name="hibernate.enable_lazy_load_no_trans">false</property> -->
<property name="hibernate.search.autoregister_listeners">true</property>
<property name="hibernate.validator.apply_to_ddl">false</property>
<property name="hibernate.temp.use_jdbc_metadata_defaults">false</property>
<property name="hibernate.enable_lazy_load_no_trans">true</property>
</session-factory>
After spending two days on it , I found the problem..
my hibernate version is 5.3 and still after changing the hibernate version to 5.2 (in the hibernate configuration window ) - it worked !!
After changing different possibilities in the configuration and connection, I changed the hibernate version from 5.3 to 5.2 and it works now ! (Tested on Photon and Oxygen versions of Eclipse)
In my case I have to check the checkboxe "Generate EJB3 annotations" with hibernate version 5.2 to make it work fine !
I am having a difficult time trying to set a connection with hibernate to a SQL Server. I should create a connection to the following data source DataSource=server,port. It seem strange that the port must be specify with a comma instead of :
When I connect to it through Visual Studio 2012 this is how it looks:
Data Source=server,17001;Initial Catalog=database;User ID=username
In order to connect it I create the following hibernate configuration file:
<hibernate-configuration>
<session-factory name="">
<property name="hibernate.connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
<property name="hibernate.connection.url">jdbc:sqlserver://server.fqdn</property>
<property name="hibernate.connection.port">port</property>
<property name="hibernate.connection.username">username</property>
<property name="hibernate.connection.password">password</property>
<property name="hibernate.connection.databasename">database</property>
<property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property>
<property name="hibernate.enable_lazy_load_no_trans">true</property>
<property name="connection.pool_size">1000</property>
</session-factory>
</hibernate-configuration>
But I get the following Exception when the connection is attempted:
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user 'username'. ClientConnectionId:c619c1dc-2c6c-4c6e-bc81-7d3619ee9ff1
I know for sure that the user and password are correct as I am using them to connect to the database through Visual Studio 2012 and they works fine.
Any idea of how should I face it?
I forgot to mark this as resolved. The issue was that I was specifying the port as a separate property:
<property name="hibernate.connection.port">port</property>.
When I add it to the connection string parameter
<property name="hibernate.connection.url">jdbc:sqlserver://server.fqdn:port</property>
it works
My application was running properly when I was configuring Hibernate.cfg.xml without any DataSource.
I am deploying my application on Weblogic.
But now I have configured it using a Data Source, (both in .cfg as well as Weblogic).
Aster this suddenly I have started getting the exception when update on some table is happening. Without the DataSource its working fine.
This was the old config: (works fine)
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.connection.url">jdbc:oracle:thin:#localhost:1521:XE</property>
<property name="hibernate.connection.username">username</property>
<property name="hibernate.connection.password">password</property>
<property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>
<property name="org.hibernate.envers.track_entities_changed_in_revision">true</property>
Following is the new config: (throws exception)
<property name="connection.datasource">DataSourceTest</property>
<property name="jndi.class">weblogic.jndi.WLInitialContextFactory</property>
<property name="hibernate.dialect">org.hibernate.dialect.OracleDialect</property>
<property name="org.hibernate.envers.track_entities_changed_in_revision">true</property>
<property name="show_sql">true</property>
<!-- <property name="hibernate.connection.autocommit">true</property> -->
<property name="hibernate.hbm2ddl.auto">update</property>
I have made the similar cofiguration in Weblogic 12.1.3 also
But now its giving the following exception:
2016-07-20 14:45:02 INFO AbstractBatchImpl:208 - HHH000010: On release of batch it still contained JDBC statements
2016-07-20 14:45:02 WARN SqlExceptionHelper:144 - SQL Error: 17004, SQLState: 99999
2016-07-20 14:45:02 ERROR SqlExceptionHelper:146 - Invalid column type: 16
org.hibernate.exception.GenericJDBCException: could not update
All the Select and Insert queries are working just fine, but when the update happens, the above error is thrown.
My Lib folder contains the Hibernate Jar, JPA 2.1 jar.
Is it some issue with the configuration I am doing?
All my mappings and columns etc seems to be fine.
Any help would be appreciated.
Hello the problem is coming from the fact that support of boolean in Oracle is either CHAR(1) or alternatively NUMBER(1). Which basically means that you will either have '1'-'0' or 'Y' -'N' combinations respectively. The problem is a conversion problem the JDBC driver needs to know how to convert your boolean into the CHAR(1)/NUMBER(1)
You can try the following:
1. Set your dialect to org.hibernate.dialect.Oracle10gDialect
Alternatively you can try to convert the Number(1)/Char(1):
#org.hibernate.annotations.Type(type="true_false")
#NotNull
boolean value;
or
#org.hibernate.annotations.Type(type="yes_no")
#NotNull
boolean value;
when i am trying to connect to a test db which settings as per shown, i am faced all the errors as per mentioned.
most of the config is taken from working production environment but i am not able to connect to my test db.
i have tried various methods and it just fails to run properly.
Im able to connect test db via other methods such as PLSQL developer or SQLPLUS.
The errors i am getting in a bunch are :
org.hibernate.exception.GenericJDBCException: Cannot open connection
....
....
....
Caused by: java.sql.SQLException: Connections could not be acquired from the underlying database!
....
....
....
Caused by: com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could not acquire a resource from its primary factory or source.
at com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1422)
at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:606)
at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:526)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutAndMarkConnectionInUse(C3P0PooledConnectionPool.java:756) at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:683)
this is my config file for hibernate :
<session-factory>
<property name="hibernate.connection.url">jdbc:oracle:thin:#ipaddress:1521:dbname</property>
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.connection.username">user</property>
<property name="hibernate.connection.password">password</property>
<property name="connection.autoReconnect">true</property>
<property name="connection.autoReconnectForPools">true</property>
<property name="connection.is-connection-validation-required">true</property>
<property name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
<property name="hibernate.c3p0.max_size">1</property>
<property name="hibernate.c3p0.min_size">1</property>
<property name="hibernate.c3p0.timeout">50000</property>
<property name="hibernate.c3p0.max_statements">100</property>
<property name="hibernate.c3p0.idle_test_period">3000</property>
<property name="hibernate.c3p0.acquire_increment">1</property>
<property name="hibernate.c3p0.validate">false</property>
<property name="dialect">org.hibernate.dialect.Oracle10gDialect</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
<mapping resource etc>
</session-factory>
Can anyone help me on this issue?
It happen for many reason like
The database configuration details you have entered are incorrect or have changed, e.g. the database name or database username/password for your Confluence database.
1)The URL for the database is incorrect.
2)The database server is not running. If your database server is down, restart it and check the logs to see why it had failed or stopped.
3)The network is down (or there is a firewall in between confluence and the database server which is interfering) and the connection to the database cannot be established.
4)Your database password has expired.
5)Check your driver,if its present or not in your class-path.
Hello everyone,
I am using hibernate ORM and oracle database. My cfg file has following properties:
<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="connection.url">jdbc:oracle:thin:#url</property>
<property name="connection.username">username</property>
<property name="connection.password">pasword</property>
<property name="dialect">org.hibernate.dialect.Oracle9Dialect</property>
<property name="hibernate.c3p0.min_size">5</property>
<property name="hibernate.c3p0.max_size">20</property>
<property name="hibernate.c3p0.timeout">300</property>
<property name="hibernate.c3p0.max_statements">50</property>
<property name="hibernate.c3p0.idle_test_period">3000</property>
<property name="hibernate.c3p0.acquire_increment">3</property>
Everything works fine, but when I run the application and if I unplug network cable and plug it agian my db queries fail. It gives me the error
java.sql.SQLException: Io exception: Connection reset by peer: socket write error
Is there any way to re establish the connection?
You need to configure your database connection pool - not hibernate.Try setting idleConnectionTestPeriod and an appropriate preferredTestQuery, e.g., select 1 from dual.
See How To Configure The C3P0 ConnectionPool for more information. You'll get the most control if you create a c3p0.properties file in WEB-INF/classes but you need to make sure not to override those properties in your hibernate.cfg.xml.
Well I had written c3p0-config.xml like
<c3p0-config>
<default-config>
<!-- Configuring Connection Testing -->
<!-- property name="automaticTestTable">TEST_EMS_HIBERNATE_CONN</property -->
<property name="checkoutTimeout">0</property>
<property name="testConnectionOnCheckout">true</property>
<property name="testConnectionOnCheckin">false</property>
<property name="preferredTestQuery">SELECT 1 from dual</property>
<!-- Configuring Recovery From Database Outages -->
<property name="acquireRetryAttempts">0</property>
<property name="acquireRetryDelay">1000</property>
<property name="breakAfterAcquireFailure">false</property>
<!-- Configuring to Debug and Workaround Broken Client Apps -->
<property name="unreturnedConnectionTimeout">1800</property>
<property name="debugUnreturnedConnectionStackTraces">true</property>
</default-config>
and the system properties like:
C3P0_SYS_PROPS="-Dcom.mchange.v2.c3p0.cfg.xml=<FILE-PATH>/c3p0-config.xml -Dcom.mchange.v2.log.MLog=com.mchange.v2.log.FallbackMLog -Dcom.mchange.v2.log.FallbackMLog.DE
FAULT_CUTOFF_LEVEL=WARNING"
As I see, you have specified when test connection, but have not specified how to test them. Read it http://www.mchange.com/projects/c3p0/index.html#configuring_connection_testing . I guess you should just add preferredTestQuery, usually it's something like SELECT 1 FROM DUAL.
Also read here Something wrong with Hibernate DB connection pooler c3p0