Hi,
I'm trying to make the parameters of the user and the path of BD configurable from another XML file other than hibernate.cfg.xml.
To do this I'm using this code :
Code:
Configuration configuration = new Configuration();
configuration.configure();
/* Initialiser le fichier hibernate.cfg.xml */
Preferences dataBasePrefs = prefs.node("database");
Properties propreties1 = new Properties();
String str1 = dataBasePrefs.get("connection.username", "");
propreties1.put("connection.username", str1);
Properties propreties2 = new Properties();
String str2 = dataBasePrefs.get("connection.password", "");
propreties2.put("connection.password", str2);
Properties propreties3 = new Properties();
String str3 = dataBasePrefs.get("connection.url", "");
propreties3.put("connection.url", str3);
configuration.addProperties(propreties1);
configuration.addProperties(propreties2);
configuration.addProperties(propreties3);
SessionFactory sessionFactory = configuration.buildSessionFactory();
HibernateUtil.setSessionFactory(sessionFactory);
/* Fin initialisation */
But I hace this exception
Code:
java.lang.UnsupportedOperationException: The user must supply a JDBC connection
at org.hibernate.connection.UserSuppliedConnectionProvider.getConnection(UserSuppliedConnectionProvider.java:30)
at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:423)
at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:144)
at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:119)
at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:57)
at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1326)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:301)
at $Proxy0.beginTransaction(Unknown Source)
at com.ullink.extranet.module.orderBookMonitoring.dao.OrderBook.DaoOrderBookImpl.getAllTblconfeventsync(DaoOrderBookImpl.java:746)
at com.ullink.extranet.module.orderBookMonitoring.service.OrderBook.ServiceOrderBookImpl.getAllTblconfeventsync(ServiceOrderBookImpl.java:446)
at com.ullink.extranet.module.orderBookMonitoring.web.Connection.MemberAreaFacesServlet$1.run(MemberAreaFacesServlet.java:46)
at java.lang.Thread.run(Unknown Source)
The exception is launched when I try to start a transaction (the 2nd line)
Code:
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
This is my hibernate.cfg.xml file :
Code:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="connection.driver_class">org.postgresql.Driver</property>
<!--<property name="connection.username">postgres</property>
<property name="connection.password">postgres</property>
<property name="connection.url">jdbc:postgresql://localhost/db_memberarea</property>-->
<!-- Echo all executed SQL to stdout
<property name="show_sql">true</property>-->
<property name="hibernate.transaction.factory_class">
org.hibernate.transaction.JDBCTransactionFactory
</property>
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- <property name="hibernate.jdbc.batch_size">0</property> -->
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<mapping resource="com/ullink/extranet/module/orderBookMonitoring/mapping/Tblorder.hbm.xml" />
<mapping resource="com/ullink/extranet/module/orderBookMonitoring/mapping/Tbltrade.hbm.xml" />
<mapping resource="com/ullink/extranet/module/orderBookMonitoring/mapping/Tblconfeventsync.hbm.xml" />
</session-factory>
</hibernate-configuration>
Do you have any idea about this exception ?
thanks