• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

table name as paramater in hbm file

 
Raja Selvaraj
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<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
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need some help
 
Raja Selvaraj
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
some one please reply for my post
 
Tim McGuire
Ranch Hand
Posts: 820
IntelliJ IDE Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 177
Hibernate Linux Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Raja Selvaraj
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 177
Hibernate Linux Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have no other way i have to use native sql
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic