tagged: jpa-databasemapping

JPA: Mapping to an existing database

In your persistence.xml you can specify an XML mapping file. Anything in this will overrule whatever is in your annotations.
Let's say the a column name is changed in a UAT database, but not in production. You can create a mapping file that remaps the annotation for the UAT database, by specifying this in your persistence.xml under the persistence-unit tag:


In that file you can set remap the column like so:

<?xml version="1.0" encoding="UTF-8" ?>
<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm    http://java.sun.com/xml/ns/persistence/orm_2_0.xsd"
    <entity class="org.denevell.tomcat.entities.write.AnotherThing">
       <table name="anotherthing" />
         <basic name="text">
           <column name="sometext" nullable="false" />

After the car-crash of schema declarations, the entity specifies which class to map, to what table, and then the attributes within. The basic tag tells us the name of the property or field in your Java class. Then the column tags tell you want to map it to.

jpa jpa-databasemapping

Page 1 of 1