Hi all,
I want my application to dynamically based on user login to change the datasource hibernate.cfg.xml
I have a session variable that I get when the user logs in:
#{sessionScope.utilisateur.datasource}
I then replace the XXX line:
<property name="connection.datasource">java:comp/env/XXX</property>
by this variable.
My hibernate.cfg.xml functional without datasource dynamic :
Code:
<?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">
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="connection.datasource">java:comp/env/XXX</property>
<property name="show_sql">true</property>
<
</session-factory>
</hibernate-configuration>
I tried to change the configuration hibernate through this code in the HibernateSessionFactory.java:
Code:
Configuration configuration = new Configuration()
.setProperty("hibernate.dialect", "org.hibernate.dialect.PostgreSQLDialect")
.setProperty("hibernate.connection.driver_class", "org.postgresql.Driver")
.setProperty("connection.datasource", "java:comp/env/"+"XXX")
.setProperty("show_sql", "true")
SessionFactory factory = configuration.buildSessionFactory()
However I have always this error:
Code:
Caused by: java.lang.UnsupportedOperationException: The user must supply a JDBC connection
at org.hibernate.connection.UserSuppliedConnectionProvider.getConnection(UserSuppliedConnectionProvider.java:30)
Someone would have an idea?
In advance thank you!
P.S: Sorry for my bad English...