-->
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.  [ 16 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: How to dynamic set table names
PostPosted: Fri Nov 10, 2006 12:04 am 
Newbie

Joined: Fri Nov 10, 2006 12:02 am
Posts: 2
In our application, the table name can be set at runtime by the customer. So is there a way in Toplink JPA to set table name at runtime (thru annotation or orm.xml) or programatically? Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 10, 2006 2:42 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
this is a Hibernate JPA forum, not Toplink JPA.

...and in any case then no, it is not possible through the spec, and if you used Hibernate core's API you could change the table, but would require a rebuild of the sessionfactory.

note: are you sure it isn't just the schema you want to switch between ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 10, 2006 10:29 am 
Newbie

Joined: Fri Nov 10, 2006 12:02 am
Posts: 2
oops, we are evaluating both implementations now, so I post (copy/paste) the same question to both forums...

No, we have a set of tables that we allow customer to map to their own tables at runtime. Obviously, the table schema has to be the same. This would definitely be a show stopper if we can't do this.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 10, 2006 10:35 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
well, annotations are not dynamically replacable.

if you fall back to hibernate core api you can mutate the mappings via the Configuration api to get a sessionfactory that does what you want.

with jpa you might be able to do it by putting mappings in orm.xml

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 13, 2006 6:20 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Actually, Hibernate Annotations core has the ability to change the annotations at runtime (even if I did not opened this API), I think creating the ORM.xml is probably easier, but if you're interested in contributing a bit, we can talk about opening this API.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 14, 2006 3:38 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
how can hibernate annotations change statically compiled annotation information into the class ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 14, 2006 11:30 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I do have an abstraction layer when reading annotations. That's the way orm.xml is handled

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 14, 2006 11:44 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
ok - so "Hibernate Annotations core has the ability to change the *mappings* at runtime" not "Hibernate Annotations core has the ability to change the *annotations* at runtime"

now i agree ;)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 14, 2006 1:43 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Well correct, but still. We create annotations for the AnnotationBinder to read them. The abstraction layer either use the class annotations or build its own if mutated

_________________
Emmanuel


Top
 Profile  
 
 Post subject: I have an application that needs the same thing
PostPosted: Wed Nov 15, 2006 7:35 pm 
Newbie

Joined: Wed Nov 15, 2006 7:17 pm
Posts: 2
Location: Idaho
We are building an application in JBOSS using EJB3 and hibernate. Our application will host several domains at once. Each domain will get its own set of database tables for each module it uses. We keep them seperate by using a unique prefix. An example would be domainA.com's blog post table would be called domainA_blogPost, while domainB.com's will be domainB_blogPost. Both tables are the same, except for the name. The name needs to be specified at runtime since the central service controller tells the rest of the application which domain it is servicing and thus which set of tables to use. We will be adding domains dynamically all the time and we can't afford to create new entity sets and recompile the back end for every domain we add. I will be happy to contribute or do what ever it takes for some help with this.

_________________
Dustin Jordan
Digital Magician

BlueLine Grassroots Marketing
http://bluelinegrassroots.com


Top
 Profile  
 
 Post subject: Hibernate Core API
PostPosted: Wed Nov 15, 2006 8:00 pm 
Newbie

Joined: Wed Nov 15, 2006 7:17 pm
Posts: 2
Location: Idaho
Looking at previous posts to this forum. can I use the Configuration.addFile() to pass and xml file that exists outside of the .ear that my application is running in? ...or did you have something else in mind?

_________________
Dustin Jordan
Digital Magician

BlueLine Grassroots Marketing
http://bluelinegrassroots.com


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 23, 2006 12:58 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
use a NamingStrategy. It's done in purpose.

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Re: How to dynamic set table names
PostPosted: Wed Jul 28, 2010 3:23 pm 
Newbie

Joined: Wed Jul 28, 2010 3:02 pm
Posts: 2
Did you ever open this API up as mentioned:

Quote:
Actually, Hibernate Annotations core has the ability to change the annotations at runtime (even if I did not opened this API), I think creating the ORM.xml is probably easier, but if you're interested in contributing a bit, we can talk about opening this API.


I am currently have the same data in 2 datastores, the only difference being that one of them only presents views. The tables are t_<tablename> with views v_<tablename> so I need to be able to switch do something along the lines of:

Code:
           
            ...
            AnnotationConfiguration tableConfig = new AnnotationConfiguration();
            tableConfig.addAnnotatedClass( MyClass1.class );
            tableConfig.addAnnotatedClass( MyClass2.class );
            tableConfig.addAnnotatedClass( MyClass3.class );
            tableSessionFactory = tableConfig.configure( "hibernate_table.cfg.xml" ).buildSessionFactory();

            AnnotationConfiguration viewConfig = new AnnotationConfiguration();
            viewConfig.addAnnotatedClass( MyClass1.class );
            viewConfig.addAnnotatedClass( MyClass2.class );
            viewConfig.addAnnotatedClass( MyClass3.class );
           
            <do something to change the table name from t_my_class_1 to v_my_class_1>
            <do something to change the table name from t_my_class_2 to v_my_class_2>
            <do something to change the table name from t_my_class_3 to v_my_class_3>

            viewSessionFactory = viewConfig.configure( "hibernate_view.cfg.xml" ).buildSessionFactory();
            ...


Top
 Profile  
 
 Post subject: Re: How to dynamic set table names
PostPosted: Thu Jul 29, 2010 4:41 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Code:
I am currently have the same data in 2 datastores, the only difference being that one of them only presents views. The tables are t_<tablename> with views v_<tablename>

assuming "2 datastores" means two differently configured sessionfactories, you can reuse the class definitions and use two different namingstrategies, one prefixing with t_ and the other prefixing with v_

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: How to dynamic set table names
PostPosted: Thu Jul 29, 2010 5:42 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I would favor Sanne's option.
Otherwise the famous API is MetadataProvider which is injected to the reflectionManager via the MetadataProviderInjector interface.

If you go that route, we would simply need to let ou pass a MetadataProvider implementation via the configuration.

But again, Sanne's option is much easier.

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 16 posts ]  Go to page 1, 2  Next

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.