Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-09-2007, 03:24 AM
bbq bbq is offline
Senior Member
 
Join Date: Jun 2007
Posts: 134
bbq is on a distinguished road
variables in hibernate.cfg.xml file
Does anybody know how can I refer a variable from hibernate.cfg.xml?

Code:
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <property name="show_sql">$value</property> <property name="hibernate.connection.username">$value</property> <property name="hibernate.dialect">$value</property> <property name="hibernate.jdbc.batch_size">$value</property> </session-factory> </hibernate-configuration>
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-09-2007, 03:27 AM
Senior Member
 
Join Date: Jun 2007
Posts: 119
Peter is on a distinguished road
You can construct the hibernate.cfg file at execution time, and then you create the procedure that you send as parameter an array or list
It would be something like that
Code:
public static void buildOtherConfiguration(String args[]) { try { Configuration cfg = new Configuration(); cfg.setProperty("hibernate.connection.driver_class","com.microsoft.jdbc.sqlserver.SQLServerDriver "); cfg.setProperty("hibernate.connection.url",args[0]); cfg.setProperty("hibernate.connection.databasename",args[1]); cfg.setProperty("hibernate.connection.username ",args[2]); cfg.setProperty("hibernate.connection.password",args[3]); cfg.setProperty("dialect",args[4]); cfg.setProperty(Environment.DIALECT,args[5]); cfg.setProperty("transaction.factory_class","org.hibernate.transaction.JDBCTransactionFactory"); cfg.setProperty("hibernate.cache.provider_class","org.hibernate.cache.HashtableCacheProvider "); cfg.addResource("model/ventas/entity/Client.hbm.xml"); cfg.addResource("model/ventas/entity/Sell.hbm.xml"); } catch (Throwable ex) { ex.printStackTrace(); } }
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 07-01-2008, 10:56 AM
Member
 
Join Date: Jul 2008
Posts: 2
shalini is on a distinguished road
I want to use variable in the password tag in hibernate.cfg.xml file.please help me .
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 07-01-2008, 10:57 AM
Member
 
Join Date: Jul 2008
Posts: 2
shalini is on a distinguished road
Not getting you....where I wll call the procedure..?
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 07-05-2008, 07:47 AM
Member
 
Join Date: Jul 2008
Posts: 42
racerxadam is on a distinguished road
You can do this with ANT

build.xml
Code:
<?xml version="1.0"?> <project default="setup-hibernate.cfg.xml" name="TEST" basedir="."> <property file="${user.home}/build.properties" /> <loadproperties srcfile="build.properties" /> <target name="prompt"> <input message="Database: " addproperty="test.input.dialect" defaultvalue="${test.default.dialect}" validargs="${test.build.dialect.options}" /> </target> <target name="set_conditions"> <condition property="test.input.dialect" value="${test.default.dialect}"> <not> <isset property="test.input.dialect" /> </not> </condition> <condition property="hibernate.dialect" value="${test.hibernate.dialect.db2}"> <equals arg1="${test.input.dialect}" arg2="db2" casesensitive="false" /> </condition> <condition property="hibernate.dialect" value="${test.hibernate.dialect.sqlserver}"> <equals arg1="${test.input.dialect}" arg2="sqlserver" casesensitive="false" /> </condition> <condition property="hibernate.dialect" value="${test.hibernate.dialect.oracle}"> <equals arg1="${test.input.dialect}" arg2="oracle" casesensitive="false" /> </condition> </target> <target name="setup-hibernate.cfg.xml" depends="prompt, set_conditions"> <delete dir="build/temp" /> <filter token="hibernateDialect" value="${hibernate.dialect}" /> <mkdir dir="build/temp" /> <copy todir="build/temp" filtering="true"> <fileset dir="."> <include name="hibernate.cfg.xml" /> </fileset> </copy> </target> </project>
build.properties
Code:
# Default Dialect test.default.dialect=db2 # Available Dialects test.build.dialect.options=db2,sqlserver,oracle # Dialect Replacement Strings test.hibernate.dialect.sqlserver=org.hibernate.dialect.SQLServerDialect test.hibernate.dialect.db2=org.hibernate.dialect.DB2Dialect test.hibernate.dialect.oracle=org.hibernate.dialect.Oracle9Dialect
hibernate.cfg.xml
Code:
<?xml version="1.0" encoding="utf-8"?> <hibernate-configuration> <session-factory name="TestSessionFactory"> <property name="dialect">@hibernateDialect@</property> </session-factory> </hibernate-configuration>
resulting hibernate.cfg.xml if you run the default target and select sqlserver as the input dialect
Code:
<?xml version="1.0" encoding="utf-8"?> <hibernate-configuration> <session-factory name="TestSessionFactory"> <property name="dialect">org.hibernate.dialect.SQLServerDialect</property> </session-factory> </hibernate-configuration>
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
boolean variables ravian New To Java 3 12-31-2007 06:58 AM
Variables mew New To Java 3 12-11-2007 02:44 PM
building file and variable names from variables madad2005 New To Java 2 07-18-2007 06:47 PM
org.hibernate.ejb.Version <clinit> INFO: Hibernate EntityManager 3.2.0.CR1 Heather Database 2 06-30-2007 05:01 PM


All times are GMT +3. The time now is 01:17 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org