0

I am pretty new in hibernate community so I do not know which direction to choose. Basically I have an war and db for it, but I have my own project with db. the problem is that some of the tables have the same names, thus is it possible somehow to map tables so the other project will call prefixed table (not the original, e.g. PREFIX_TEST, while originally TEST). I read about Naming Strategy, but I;m not sure if I can use it, I have no persistence.xml

Thanks a lot

bearbearbear
  • 95
  • 1
  • 2
  • 11

1 Answers1

0

If the prefixing is only needed for several tables, you can either define the table mapping:

@Entity
@Table(name="PREFIX_TEST")
public class Test { ... }

or create an entity with a name matching the prefixed table:

@Entity
public class PrefixTest { ... }

If you want to modify the names of all tables, you can use a naming strategy as explained here.

However you would need a persistence.xml for that.

EDIT: The fact that you only have access to the packaged application is not a big issue if all you want to change is the persistence.xml. A [jwe]ar file is a simple zip file, so you can unpack it, add or change the persistence.xml, repack and deploy.

Community
  • 1
  • 1
kostja
  • 60,521
  • 48
  • 179
  • 224
  • I cannot change the annotation, I have it all packed in war. – bearbearbear Jan 29 '14 at 10:43
  • If you want to use different table names, you will have to change something - either the annotations or the classes or the persistence.xml – kostja Jan 29 '14 at 10:45
  • So there is no other way how can I wrap it? :( – bearbearbear Jan 29 '14 at 11:20
  • I'm afraid not. Changing the behaviour without changing neither the code nor the configuration is not possible. – kostja Jan 29 '14 at 11:41
  • There may be a way though, if you are willing to tinker with the contents of the .war file. Please see the edit. – kostja Jan 29 '14 at 11:46
  • sorry for stupid question, if I will be able to change the persistence.xml how should I do that, I mean do you have some example please? – bearbearbear Jan 29 '14 at 12:03
  • No problem, see http://stackoverflow.com/questions/3617687/is-it-possible-to-dynamically-define-column-names-in-hibernate-jpa/3618315 – kostja Jan 29 '14 at 12:06