Results 1 to 5 of 5
- 07-09-2007, 01:24 AM #1
Senior Member
- Join Date
- Jun 2007
- Posts
- 132
- Rep Power
- 0
variables in hibernate.cfg.xml file
Does anybody know how can I refer a variable from hibernate.cfg.xml?
Java 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>
- 07-09-2007, 01:27 AM #2
Senior Member
- Join Date
- Jun 2007
- Posts
- 119
- Rep Power
- 0
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
Java 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(); } }
- 07-01-2008, 08:56 AM #3
Member
- Join Date
- Jul 2008
- Posts
- 2
- Rep Power
- 0
I want to use variable in the password tag in hibernate.cfg.xml file.please help me .
- 07-01-2008, 08:57 AM #4
Member
- Join Date
- Jul 2008
- Posts
- 2
- Rep Power
- 0
Not getting you....where I wll call the procedure..?
- 07-05-2008, 05:47 AM #5
Member
- Join Date
- Jul 2008
- Posts
- 68
- Rep Power
- 0
You can do this with ANT
build.xml
build.propertiesJava 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>
hibernate.cfg.xmlJava 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
resulting hibernate.cfg.xml if you run the default target and select sqlserver as the input dialectJava Code:<?xml version="1.0" encoding="utf-8"?> <hibernate-configuration> <session-factory name="TestSessionFactory"> <property name="dialect">@hibernateDialect@</property> </session-factory> </hibernate-configuration>
Java 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>
Similar Threads
-
boolean variables
By ravian in forum New To JavaReplies: 3Last Post: 12-31-2007, 04:58 AM -
Variables
By mew in forum New To JavaReplies: 3Last Post: 12-11-2007, 12:44 PM -
building file and variable names from variables
By madad2005 in forum New To JavaReplies: 2Last Post: 07-18-2007, 04:47 PM -
org.hibernate.ejb.Version <clinit> INFO: Hibernate EntityManager 3.2.0.CR1
By Heather in forum JDBCReplies: 2Last Post: 06-30-2007, 03:01 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks