-->
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.  [ 2 posts ] 
Author Message
 Post subject: Mapping class to a table witout a table name
PostPosted: Sat Oct 01, 2011 6:52 am 
Newbie

Joined: Sat Oct 01, 2011 6:45 am
Posts: 1
Hi,

I have many tables in my DB with exactly the same structure: same columns names and types.
The only difference between these tables is the their names (which I can only know in runtime).

I would like to create a mapping of a class to a table but giving the name of the table only during runtime (no static @Table annotation).

Is it possible?
Is there any other way to achieve my goal?


Top
 Profile  
 
 Post subject: Re: Mapping class to a table witout a table name
PostPosted: Sun Oct 02, 2011 5:28 pm 
Newbie

Joined: Sun Sep 25, 2011 4:05 pm
Posts: 12
Don't know if that is possible, but I would bet money that you don't need to do things that way. It's most likely that all of those tables with different names correspond to different instances of the same type of object right? Those can probably all be stored in one table. You would have to add one column to the table which maps the row to the instance it belongs to.

For example:

public class Parent {
public Set<Child> children;
}

public class Child {
public Parent parent;
public String name;
}

It sounds like you are making a separate table for every parent, and the each of them holds a list of children. You can combine them into one table for the parent class, not each instance and one table for the child class, not each instance. See the chapter on association mapping in the jboss hibernate manual:
http://docs.jboss.org/hibernate/core/3. ... tions.html


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.