-->
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.  [ 3 posts ] 
Author Message
 Post subject: Hibernate using a datasource without configuration file
PostPosted: Sat Mar 26, 2011 5:29 pm 
Newbie

Joined: Sat Mar 26, 2011 5:17 pm
Posts: 2
Dear everybody:

I would like to create a SessionFactory without any configuration file. That is, I would like to define the database class (it will be a MysqlDataSource) and its parameters in execution time.

I have been searching a method "configure()" (in Configuration class) with a Properties object as a parameter, but I didn't found it. So i am very lost.

Could anyone give me a very simple example to create a SessionFactory without any configuration file, please? And using datasources (class MysqlDataSource, that implements DataSource interface), not "drivers".

So I would like to know how to continue this source code:

Code:
           
            import javax.sql.DataSource;
            import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;

            ........

            MysqlDataSource bd = new MysqlDataSource();
           
            bd.setServerName("localhost");
            bd.setPort(3306);
            bd.setDatabaseName("test");
            bd.setUser("root");
            bd.setPassword("");

            // Now, I want to obtain a SessionFactory object from this "bd" object,
            // without any XML or property configuration file
            SessionFactory mySessionFactory = ................


Thank you very much for your help :-)


Top
 Profile  
 
 Post subject: Re: Hibernate using a datasource without configuration file
PostPosted: Sun Mar 27, 2011 6:06 am 
Newbie

Joined: Tue Jul 20, 2010 1:53 am
Posts: 18
[color=#0000FF]Yes ...It's possible through .properties file and take this file as an java.util.Properties ;

Properties p=new Properties();
p.load("properties file name");
////in properties you can maintain all dialect , class .....etc

......

cfg.addFile("here place HB Mapping file");

.....than execute normally..[/color]


Top
 Profile  
 
 Post subject: Re: Hibernate using a datasource without configuration file
PostPosted: Sun Mar 27, 2011 10:14 am 
Newbie

Joined: Sat Mar 26, 2011 5:17 pm
Posts: 2
I didn't understand your code very well. Could you writte it a little more complete please?

Thank you very much.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.