tags:

views:

68

answers:

1

We have common modules (for configuration, security, notifications, etc.) that define the entities and the logic for the module as a reusable JAR. The only imposed dependency is the name of the table that the JPA entities map to (we use JPA annotations were possible, Hibernate annotations were JPA doesn't define one).

Is there a way to remap a JPA entity to a different table (ideally applications would change the table name prefix to comply with the app's table prefix name)? We can't use the MappedSuperClass annotation because the HQL use the entity name and our DAOs are generified on the entity.

A: 

You could have each application provide it's own orm.xml file with the appropriate table mapping there, and use JPA annotations for everything else.

orm.xml:

<?xml version="1.0" encoding="UTF-8"?>
<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_1_0.xsd"
  version="1.0">

  <entity class="com.mydomain.Customer">
    <table name="PROD1_CUSTOMER"/>
  </entity>

</entity-mappings>
mtpettyp
Excellent! This is just what I needed.
kabram