-
1. Re: JDBC
marx3 Mar 4, 2008 10:56 AM (in response to marx3)Sorry for double post, forum has problems... :(
-
2. Re: JDBC
nickarls Mar 4, 2008 11:24 AM (in response to marx3)cast the entityManager.getDelegate() (Session in Hibernate case) and get the connection from there.
or look it up in JNDI
-
3. Re: JDBC
tom_goring Mar 4, 2008 11:33 AM (in response to marx3)Or standard EJB3 injection
E.g.
@Stateless @Name("bankBalanceManager") public class BankBalanceManagerBean implements BankBalanceManager { ... @Resource (mappedName=BLJndi.DataSourceName) private DataSource jnetDS; ... }
-
4. Re: JDBC
marx3 Mar 4, 2008 1:00 PM (in response to marx3)In example above I had to know datasource name, I don't know it (it's changing)
Is it what Niklas suggest?
HibernateEntityManager emh = (HibernateEntityManager) em; Connection conn = emh.getSession().connection();
Anyway it works, despite deprecated connection() method
-
5. Re: JDBC
nickarls Mar 4, 2008 10:55 PM (in response to marx3)Something like that, if it works, it ain't broken ;-) At least not yet
-
6. Re: JDBC
luxspes Mar 5, 2008 7:41 AM (in response to marx3)Hi!
I am curious... Why would you need to change the datasource name often?
AFAIK if you are creating your project with eclipse, your datasource configuration should be stored in a file like
nameofyourproject-ds.xml
, its contents look like this:<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE datasources PUBLIC "-//JBoss//DTD JBOSS JCA Config 1.5//EN" "http://www.jboss.org/j2ee/dtd/jboss-ds_1_5.dtd"> <datasources> <local-tx-datasource> <jndi-name>nameofyourprojectDatasource</jndi-name> <connection-url>jdbc:hsqldb:hsql://localhost/xdb</connection-url> <driver-class>org.hsqldb.jdbcDriver</driver-class> <user-name>sa</user-name> <password></password> </local-tx-datasource> </datasources>
In this case the name of you datasource is nameofyourprojectDatasource,and it shouldn't change... unless you manually change it (you can change the connection string and even the driver but keep the name without change).
Regards,
LuxSpes -
7. Re: JDBC
marx3 Mar 5, 2008 9:09 AM (in response to marx3)It's simply - code I do is shared between a few projects. I feel datasource should be defined once in code