-
1. Re: Dynamic data sources with EntityManager
fnordinuk Aug 3, 2007 3:45 AM (in response to wiberto)I have the same database setup that I'm trying to get EJB3 to work with. Any help on this one would be much appreciated.
-
2. Re: Dynamic data sources with EntityManager
pmuir Aug 3, 2007 5:50 AM (in response to wiberto)You can't put runtime parameters into annotations so you'll have to access the PC programmatic ally. The neatest way I can see to do this is to use a Seam manager component to look up and inject the correct PC based upon who is logged in.
-
3. Re: Dynamic data sources with EntityManager
wiberto Aug 3, 2007 12:31 PM (in response to wiberto)Any samples out there on how to create a Seam manager component?
-
4. Re: Dynamic data sources with EntityManager
wiberto Aug 3, 2007 12:32 PM (in response to wiberto)That's what I thought, that it would have to be programatically since annotations are static in the source code. I'm fine with that.
-
5. Re: Dynamic data sources with EntityManager
pmuir Aug 3, 2007 12:41 PM (in response to wiberto)Most of Seam is implemented using manager components. e.g. MailSession.
-
6. Re: Dynamic data sources with EntityManager
wiberto Aug 6, 2007 12:32 PM (in response to wiberto)How do I then go about having Seam use my component? Do I have to do anything special in the components.xml file?
-
7. Re: Dynamic data sources with EntityManager
pmuir Aug 6, 2007 12:58 PM (in response to wiberto)No.
-
8. Re: Dynamic data sources with EntityManager
wiberto Aug 6, 2007 1:17 PM (in response to wiberto)I was looking over at the documentation for the components and came across this:
<component name="customerDatabase" class="org.jboss.seam.persistence.ManagedPersistenceContext"> <property name="persistenceUnitJndiName">java:/customerEntityManagerFactory</property> </component>
Can I then create my own persistenceContext that gets some information about the user that is logged in probably through the Identity object?
Then in the class that needs it, how would I tell it use use this persistence manager? Can I pass a name attribute to the @PersistenceContext annotation? -
9. Re: Dynamic data sources with EntityManager
wiberto Aug 6, 2007 6:37 PM (in response to wiberto)I think I got this figured out now!!!
I was able to create my own persistence context as I stated in the previous post, and I'm then creating my own entitymanager factory. there I point to the the persistence unit I want to use.
Now the issue I have is that I want to pass overrides to the entitymanager factory. My persistence.xml looks like this:<persistence-unit name="userbased" transaction-type="RESOURCE_LOCAL"> <provider>org.hibernate.ejb.HibernatePersistence</provider> <class>com.numbersinsight.data.customer.User</class> <properties> <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" /> <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" /> <property name="hibernate.connection.username" value="numins" /> <property name="hibernate.connection.password" value="num6482bersi" /> <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/numins" /> <property name="hibernate.hbm2ddl.auto" value="none" /> <property name="hibernate.show_sql" value="true" /> <property name="hibernate.use_sql_comments" value="true" /> </properties> <non-jta-data-source>java:jdbc/numins</non-jta-data-source> </persistence-unit>
The connection is always made using the data source deifnintion. If I take that out the application will not deploy complaining about not having a data source defined. Do you know of a way to not have that data source defined and have it use the properties?
This way it will make it easy to load the properties and configure the connection properties at runtime based on the user. -
10. Re: Dynamic data sources with EntityManager
olvin Aug 29, 2007 8:08 PM (in response to wiberto)Anybody has experimented a solution for that ? And a concrete example ?
Thanks,
Olivier -
11. Re: Dynamic data sources with EntityManager
wiberto Aug 30, 2007 10:36 AM (in response to wiberto)I will post what I did to solve this problem in my blog soon. I'll post again when I have it out there.
Thanks,
Jose -
12. Re: Dynamic data sources with EntityManager
olvin Sep 14, 2007 4:52 AM (in response to wiberto)Hello wiberto,
Could you post your solution ? Or only the idea ?
Thanks,
Olivier