-->
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.  [ 10 posts ] 
Author Message
 Post subject: Access to DB Connection
PostPosted: Wed Feb 18, 2009 7:42 am 
Newbie

Joined: Wed Nov 19, 2008 8:20 am
Posts: 9
Its possibile to access to DB Conncection from org.hibernate.Session ?
I want to pass to another System the connection info that i have in db.cfg.xml .

Thanks,
Luca

_________________
-------------------------------------
La realizzazione di un sogno
aiuta l'animale uomo a vivere
con dignità
-------------------------------------


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 18, 2009 8:21 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
session.connection() returns the underlying DB-connection.

_________________
-----------------
Need advanced help? http://www.viada.eu


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 18, 2009 8:26 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
Session.connection() but it has been deprecated and will be removed in 4.x.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 18, 2009 9:58 am 
Newbie

Joined: Wed Nov 19, 2008 8:20 am
Posts: 9
I have found the method Connection().
This is only way for take the Connection info???

_________________
-------------------------------------
La realizzazione di un sogno
aiuta l'animale uomo a vivere
con dignità
-------------------------------------


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 18, 2009 10:44 am 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
you can get all the stuff from the SessionFactory

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 18, 2009 10:47 am 
Newbie

Joined: Wed Nov 19, 2008 8:20 am
Posts: 9
chirs its possibile one example?
thanks for reply

_________________
-------------------------------------
La realizzazione di un sogno
aiuta l'animale uomo a vivere
con dignità
-------------------------------------


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 18, 2009 10:51 am 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
cast it to SessionFactoryImpl and use

getSettings().getConnectionProvider().getConnection()

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 18, 2009 2:55 pm 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
What kind of info do you need? Do you need to use an actual Connection object or only information about the database url, user name, password, etc?
Why not just read it from the 'db.cfg.xml' that you mentioned in your first post?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 19, 2009 7:17 am 
Newbie

Joined: Wed Nov 19, 2008 8:20 am
Posts: 9
Because i have the an application that call remote Ejb and the info are in remote jar. For this reason i want to pass the object Connection.

_________________
-------------------------------------
La realizzazione di un sogno
aiuta l'animale uomo a vivere
con dignità
-------------------------------------


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 19, 2009 7:54 am 
Newbie

Joined: Wed Nov 19, 2008 8:20 am
Posts: 9
I have treid with:
SessionFactoryImpl session = (SessionFactoryImpl) getSession().getSessionFactory();
return session.getSettings().getConnectionProvider().getConnection();

in jsp i take the connection, execute the query and build the list.
after i can't do nothing because i have this exception:

javax.servlet.ServletException: com.XXXX.utils.ejb.DaoException: Could not enlist in transaction on entering meta-aware object!; - nested throwable: (javax.transaction.SystemException: java.lang.Throwable: Unabled to enlist resource, see the previous warnings. tx=TransactionImple < ac, BasicAction: a3c0225:95e4:499d2bf1:3c2 status: ActionStatus.ABORT_ONLY >); - nested throwable: (org.jboss.resource.JBossResourceException: Could not enlist in transaction on entering meta-aware object!; - nested throwable: (javax.transaction.SystemException: java.lang.Throwable: Unabled to enlist resource, see the previous warnings. tx=TransactionImple < ac, BasicAction: a3c0225:95e4:499d2bf1:3c2 status: ActionStatus.ABORT_ONLY >))

My idea is similar to:
Session sess=sf.openSession();
Statement st=sess.connection().createStatement(); //connection is deprecated
String sql="select * from foo";
st.executeQuery(sql);

i wait new helps...
thanks to all

_________________
-------------------------------------
La realizzazione di un sogno
aiuta l'animale uomo a vivere
con dignità
-------------------------------------


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 10 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.