-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Datasource dynamique en fonction d'une variable session
PostPosted: Tue Nov 17, 2009 5:38 am 
Newbie

Joined: Tue Nov 17, 2009 4:53 am
Posts: 7
Salut à tous,

J'aimerais dans mon appli pouvoir dynamiquement en fonction du login de l'utilisateur modifier le datasource du fichier hibernate.cfg.xml

J'ai une variable de session que je récupère quand l'utilisateur se logue :
#{sessionScope.utilisateur.datasource}

j'aimerais donc remplacer le XXX de la ligne :
<property name="connection.datasource">java:comp/env/XXX</property>
par cette variable.


Mon fichier hibernate.cfg.xml fonctionnel sans datasource dynamique
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>



J'ai essayé de modifier la configuration hibernate via ce code dans le 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()


Cependant j'ai toujours cette erreur :
Code:
Caused by: java.lang.UnsupportedOperationException: The user must supply a JDBC connection
   at org.hibernate.connection.UserSuppliedConnectionProvider.getConnection(UserSuppliedConnectionProvider.java:30)


Quelqu'un aurait il une idée ?

Par avance merci !


Top
 Profile  
 
 Post subject: Re: Datasource dynamique en fonction d'une variable session
PostPosted: Tue Nov 17, 2009 9:17 am 
Newbie

Joined: Tue Nov 17, 2009 4:53 am
Posts: 7
Bon finalement j'ai trouvé :

configuration.setProperty("hibernate.connection.datasource", "xxxx");

dans le hibernatesessionfactory


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.