• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Annotations attributes and multiple DB Schemas

 
Aaron Wilt
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I'm trying to figure out the best way to change the schema values of my annotations as my app moves from dev to test to prod schemas.

My oracle DB schemas look like this:

DevSchema
-tables a, b, c

TestSchema
-tables a, b, c

ProdSchema
-tables a, b, c

My Product Entity class looks like this:

@Entity
@Table(name="DevSchema.a")
Public class Product
{

}

The problem is what happens when I move to test? The @Table name should be "TestSchema.a" yet when I try to make "DevSchema" a variable I get an error saying that the name attribute value must be a constant.

Is there a way I can use Ant to dynamically change all my entities when creating a war ? I didnt think ant could change java files.

Thanks,
Aaron
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why not put the schema information into the hibernate.cfg.xml or persistence.xml file instead. Becauase if you have lots of Entities, going through each and every one of them will be a pain.

Mark
 
Aaron Wilt
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mark, could you give me an example of how this is done?

Thanks for the reply.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at table 3.3

The other solution is to not use schema in your query, just deploy a different Datasource that changes which schema it points to, but with the same datasource name.


So in one datasource it points to the test schema, another that points to production. And deploy the one that you want ot work with at that moment.

Mark
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mark Spritzler:
Look at table 3.3

The other solution is to not use schema in your query, just deploy a different Datasource that changes which schema it points to, but with the same datasource name.


So in one datasource it points to the test schema, another that points to production. And deploy the one that you want ot work with at that moment.

Mark


DOH!. I guess I forgot to add the link. Sorry

http://www.hibernate.org/hib_docs/reference/en/html/session-configuration.html

Mark
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic