JPA and table prefix

JPA is great but it doesn’t manage a standard way to add a prefix to database tables out of the box.

All (known) vendors have some hooks to do so but that’s not obvious or specified. For hibernate you have to play with NamingStrategy, with OpenJPA you either define a custom DBDictionary or a NamingDefaults and with EclipseLink you have to implement a SessionCustomizer and play with eclipselink model.

That’s why in OpenEJB and TomEE we started to work on it.

What we expect is to simply define a string in a good place to prefix all tables. It sounds logical to consider as a good place the persistence unit and more particularly the place where we define vendor specific properties: the properties tag.

The “magic” property name is openejb.jpa.table_prefix.

So for instance you can define:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
  <persistence-unit name="demo">
      <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)"/>
      <property name="openejb.jpa.table_prefix" value="DEMO_"/>

Then it should prefix your tables.

Note: that’s an in progress feature. If you encounter any issue with it please report it on OpenEJB mailing list (

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s