0

in JPA annotation @Table(x+"_Name"), I want the x to be fed by spring config file. Is it possible in JPA? actually all our db tables name have prefix with application name, and I want to use that prefix at dynamically configure by passing to spring bean config.

in spring config:

<bean id="x" class="java.lang.String">
<constructor-arg value="JOE" />
</bean>
Slava Semushin
  • 14,904
  • 7
  • 53
  • 69
kneethan
  • 423
  • 1
  • 8
  • 22
  • 2
    http://stackoverflow.com/questions/4313095/jpa-hibernate-and-custom-table-prefixes – zmf Sep 27 '11 at 18:25
  • http://stackoverflow.com/questions/2444962/in-tablename-tablename-make-tablename-a-variable-in-jpa – atrain Sep 28 '11 at 14:58
  • Thanks @zmf for cross link to solution. is it possible to have two different prefix for same project? ie, x for bunch of tables and y prefix for another bunch of tables? – kneethan Oct 11 '11 at 05:24
  • @kneethan if you're using hibernate(my previous link assumes that you are), once you implement a custom NamingStrategy I'd imagine you can do any sort of prefixing that you'd like. Whether or not that's a good idea is up for debate. – zmf Oct 12 '11 at 17:11

1 Answers1

2

Unfortunately, You can't. Any value you will set as @Table annotation parameter you will receive

"The value for annotation attribute Table.name must be a constant expression" error

danny.lesnik
  • 18,479
  • 29
  • 135
  • 200