-->
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: Can i pass hibernate.properties in runtime?
PostPosted: Mon Aug 14, 2006 1:57 pm 
Beginner
Beginner

Joined: Fri Sep 02, 2005 3:42 pm
Posts: 32
Hi,

I need to configure the basic hibernate properties during the execution of my program. Can i do that and still use the hibernate.cfg.xml for mapping the classes?

Alberto


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 14, 2006 4:47 pm 
Expert
Expert

Joined: Tue Apr 25, 2006 12:04 pm
Posts: 260
You can use someting like below to configure properties at runtime

Code:
Configuration c = new Configuration();

Properties p = new Properties();
p.put( "hibernate.connection.driver_class", "oracle.jdbc.OracleDriver" );
p.put( "hibernate.connection.url", "jdbc:oracle:thin:@localhost:1521:MYDB" );
p.put( "hibernate.connection.username", "myuser" );
p.put( "hibernate.connection.password", "mypaswd" );
p.put( "hibernate.transaction.auto_close_session", "false" );
p.put( "hibernate.connection.pool_size", "1" );

c.configure(); // will load properties from hibernate.cfg.xml
c.addProperties( p );
SessionFactory sf = c.buildSessionFactory();


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 14, 2006 5:45 pm 
Beginner
Beginner

Joined: Fri Sep 02, 2005 3:42 pm
Posts: 32
Thanks,

Alberto


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.