The moose likes Object Relational Mapping and the fly likes table name as paramater in hbm file Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Reply Bookmark "table name as paramater in hbm file" Watch "table name as paramater in hbm file" New topic
Author

table name as paramater in hbm file

Raja Selvaraj
Greenhorn

Joined: May 12, 2012
Posts: 13
<hibernate-mapping>
<class name="com.to.Person" table="TAB_PERSON">

is there is any way to pass the table name as parameter in hbm file
Raja Selvaraj
Greenhorn

Joined: May 12, 2012
Posts: 13
I need some help
Raja Selvaraj
Greenhorn

Joined: May 12, 2012
Posts: 13
some one please reply for my post
Tim McGuire
Ranch Hand

Joined: Apr 30, 2003
Posts: 819

Raja Selvaraj wrote:some one please reply for my post


I think that nobody understands your question. As it stands, "pass table name as parameter in hbm file" does not mean anything to me, so you will need to explain more: What are you trying to accomplish? In general, table names are only referenced once and not "passed around" as that defeats the point of hibernate.
Raja Selvaraj
Greenhorn

Joined: May 12, 2012
Posts: 13
I am using 4 tables with same fields , and there is a chance to increase in no of tables

1. I have to avoid creating hbm and java file for each table(Because table creating is done at run time)

2.I have to use single hbm file dynamically is it possible

Ex.

<class name="com.Person" table="TABLE_NAME">


is it possible to replace TABLE_NAME with STUDENT ,EMPLOYEE at run time
Manuel Petermann
Ranch Hand

Joined: Jul 19, 2011
Posts: 175

You should overlook your database design.
A Database structure should be kept as normalized as possible. Database normalization
You may do this by simply extending from your table_name class and choosing an inheritance strategy. Or you could tell us what the relationships/dependencies are and we might figure out something better.


Please correct my English.
Raja Selvaraj
Greenhorn

Joined: May 12, 2012
Posts: 13
1. I have to choose the table at run time

2.No of tables is not fixed it may increase

3.PERSON (STUDENT,TEACHER,EMPLOYEE) in future the tables may increase

4.If i use inheritance I have to touch my code again it is not possible for me

4.But I am keeping all the table names in separate table there i can refer which table i have to look based on login but hbm file?
Manuel Petermann
Ranch Hand

Joined: Jul 19, 2011
Posts: 175

What do you refer to as runtime?
Runtime as in the program is running and connected with an EntityManager/SessionFactory and you want to change the structure or your program is running but not yet connected with an EntityManager/SessionFactory and you want to choose which table to use.
The first one is not possible as far as I know. The later could be done via editing the properties given to the builder of the EntityManager/SessionFactory.
To 4: You have to add a feature without touching the code? I really do hope I never have to do that!
Without adding any code I would say this is not possible.
Raja Selvaraj
Greenhorn

Joined: May 12, 2012
Posts: 13
I have no other way i have to use native sql
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: table name as paramater in hbm file
 
Similar Threads
Hibernate Newbie - 1 to Many Relation Tutorial
First timer with Hibernate - unknown entity error
Mapping same POJO to more than one table in Hibernate XML mapping files
I have a POJO ,Now I want to generate mapping File (.hbm) and table .Hoe It can be done?
Dynamic sql with hibernate