2

I have a WebService that was created by a developer that is no longer with us, that uses the following syntax @Table(name = "Tax", catalog = "dbProduction", schema = "")

the database has been renamed and the webservice no longer works, I manually renamed the @Table annotations to @Table(name = "Tax", catalog = "dbProduction2013", schema = "")

I would like to know if there is a simple way to make this a parameter that automatically finds the database name given a connection? Is there a way to make the whole process automatic? I am using NetBeans 7.2.1

Roman C
  • 49,761
  • 33
  • 66
  • 176
Astronaut
  • 6,691
  • 18
  • 61
  • 99

1 Answers1

0

You could easily set the "catalog" in orm.xml (as per http://www.datanucleus.org/products/accessplatform_3_2/jpa/metadata_xml.html#catalog ) and then it is in a single place. Obviously that means that you are no longer embedding deployment information in individual classes, which ought to be a recommended practice in most organisations.

DataNucleus
  • 15,497
  • 3
  • 32
  • 37
  • Thanks for the tip, we dont have an orm.xml file, still it's not an automatic way, I still need to rename it right? is there a way to setup that value automatically? – Astronaut Jan 09 '13 at 21:57
  • if you ever wanted to use a different catalog then you change it in one place (just like a parameter). After all, JPA is not psychic, so nothing will be "automatic". Having an orm.xml (under META-INF) is standard JPA, but then if you want to pollute your model with deployment info then fine – DataNucleus Jan 10 '13 at 06:26
  • I am trying to get the name of the database based on the connection string and use that, if it's not possible to have a dynamic solution than your solution is much more appropriate than what is currently implemented. I have very little experience with Java EE. I have to see how I can implement the orm.xml file, since currently what is used are annotations... can I have annotations and orm.xml configurations? – Astronaut Jan 10 '13 at 09:58
  • The problem with "javax.persistence.jdbc.url" is that its structure will differ for each type of datastore, so getting something from that would be problematic, unless you were only interested in one type of datastore and it included that info in the url. JPA does allow annotations + orm.xml at the same time, with orm.xml supplanting what was defined in annotations. – DataNucleus Jan 10 '13 at 10:05