-->
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.  [ 13 posts ] 
Author Message
 Post subject: How to read .properties file in .hbm.xml file
PostPosted: Thu Jan 10, 2008 5:19 pm 
Newbie

Joined: Thu Jan 10, 2008 5:10 pm
Posts: 8
Hi

I am new to the hibernate….I am working on the below .hbm.xml in which i am hard coding the table space name as “IDVPCS01”.
I would like to know whether there is any way to read the table space name from the .properties file.



<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping auto-import="true" default-lazy="false">

<class name="us.oh.mh.cpoe.databean.AllergyCrossSenseDescDataBean"
table="IDVPCS01.ITRDAMCSD0">

<id name="allergyCrossSenseDescCode" type="java.lang.String"
column="DAM_AGCCS">
<generator class="assigned" />
</id>
<property name="allergyCrossSenseDesc" type="java.lang.String"
column="DAM_AGCCSD" />
</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 11, 2008 4:48 am 
Newbie

Joined: Wed Jan 09, 2008 6:26 am
Posts: 19
You may use an XML inclusion:

Code:
Main.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"
   [<!ENTITY TableName SYSTEM "classpath://my/package/TabProp.hbm">]>

<hibernate-mapping>
blah
&TableName;
blah
</hibernate-mapping>

TabProp.hbm:

NameOfMyTable


I don't think .properties could be used...
Hope it helps...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 11, 2008 9:59 am 
Newbie

Joined: Thu Jan 10, 2008 5:10 pm
Posts: 8
thank you for your quick reply.. so this is what I understood..

basically we need to define all table names in TabProp.hbm file and then refer it in our table specific mapping files.

I was trying to figure out the XML node names to define the property in TabProp.hbm file and couldn't find anything..

can you please give some sample code for TabProp.hbm file?

And I guess this is how we refer it in our table specific mapping file..

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping auto-import="true" default-lazy="false">

<class name="us.oh.mh.cpoe.databean.AllergyCrossSenseDescDataBean"
table="${TableName}">

<id name="columnName" type="java.lang.String"
column="Column1">
<generator class="assigned" />
</id>
<property name="columnName2" type="java.lang.String"
column="Column2" />
</class>
</hibernate-mapping>

appreciate your response..


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 11, 2008 12:32 pm 
Newbie

Joined: Wed Jan 09, 2008 6:26 am
Posts: 19
Unfortunately, you must include the full file. So in your case, you can't have a single property file but a property file per table name. I realize it's an awful solution in your case...

In other word, there's no way to have a property file like this:

PROP1=TableName1
PROP2=TableName2
and so on

Sorry...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 11, 2008 12:39 pm 
Newbie

Joined: Wed Jan 09, 2008 6:26 am
Posts: 19
I just realize you wanted to include the table namespace, not the tablename. So my solution works fine!

With your initial example:

Your file (blah.xml):

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"
[<!ENTITY TableSpace SYSTEM "classpath://my/package/TabSpaceProp.hbm">]>

<hibernate-mapping auto-import="true" default-lazy="false">

<class name="us.oh.mh.cpoe.databean.AllergyCrossSenseDescDataBean"
table="&TableSpace;.ITRDAMCSD0">

<id name="allergyCrossSenseDescCode" type="java.lang.String"
column="DAM_AGCCS">
<generator class="assigned" />
</id>
<property name="allergyCrossSenseDesc" type="java.lang.String"
column="DAM_AGCCSD" />


The property file (TabSpaceProp.hbm) [yes, just this, no more words]:

Code:
IDVPCS01


And sorry for the mistakes, i'm not a native english speaker...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 11, 2008 1:32 pm 
Newbie

Joined: Thu Jan 10, 2008 5:10 pm
Posts: 8
Hello aec,

Thanks for your reply.I think still i am missing some thing.
i am getting the error as

"The external entity reference "&&;Tablesapce;" is not permitted in attribute value."

in the below .xml at the line which is highlighted in blue.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"
[<!ENTITY TableSpace SYSTEM "classpath://my/package/TabSpaceProp.hbm">]>

<hibernate-mapping auto-import="true" default-lazy="false">

<class name="us.oh.mh.cpoe.databean.AllergyCrossSenseDescDataBean"
table="&TableSpace;.ITRDAMCSD0">

<id name="allergyCrossSenseDescCode" type="java.lang.String"
column="DAM_AGCCS">
<generator class="assigned" />
</id>

<property name="allergyCrossSenseDesc" type="java.lang.String"
column="DAM_AGCCSD" />

</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 14, 2008 5:39 am 
Newbie

Joined: Wed Jan 09, 2008 6:26 am
Posts: 19
Hello Avalav,

Are you sure the file "TabSpace.hbm" is really located in a package called "my.package" as you wrote in "classpath://my/package/TabSpaceProp.hbm"?

_________________
Don't forget to rate answers! ;-)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 14, 2008 9:51 am 
Newbie

Joined: Thu Jan 10, 2008 5:10 pm
Posts: 8
Hello aec,

Thanks for your reply .
yes , I have pointed the file "TabSpace.hbm" to the correct location .

Then also i am getting the following error.

"The external entity reference "&&;Tablespace;" is not permitted in attribute value."


1) Then I tried giving table attribute value as below

table="${TableSpace};.ITDRUGS"> then i am not getting any error in the xml but the in query ${TableSpace}; is not replaced by actual value.

please help me in resolving this issue.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 14, 2008 10:29 am 
Newbie

Joined: Wed Jan 09, 2008 6:26 am
Posts: 19
This feature needs hibernate 3.2. Are you up to date with hibernate?

_________________
Don't forget to rate answers! ;-)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 14, 2008 10:51 am 
Newbie

Joined: Thu Jan 10, 2008 5:10 pm
Posts: 8
Yes i am using hibernate 3.2


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 14, 2008 1:28 pm 
Newbie

Joined: Wed Jan 09, 2008 6:26 am
Posts: 19
Well... i'm lost... i don't see where is the problem. I will try to test your code in my environnement...

_________________
Don't forget to rate answers! ;-)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 10, 2008 5:01 am 
Newbie

Joined: Tue Jun 10, 2008 4:56 am
Posts: 1
Hi aec,

I also tried using your way... but it didn't work.
Have you guys sorted this out in any way?

_________________
Vivek


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 06, 2008 11:04 am 
Newbie

Joined: Thu Jan 10, 2008 5:10 pm
Posts: 8
Hi aec & vivekbakshi,

If you sorted out this issue, please let me know.

Thanks in advance


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