Reputation: 2183
I want if is possible change the JPA default behavior, I want to make the default value of all fields as "transient"
I have a Embedable
<embeddable class="beans.Address" metadata-complete="false" >
<attributes >
<basic name="id">
<column name="address_id"></column>
</basic>
<basic name="description">
<column name="address_description"></column>
</basic>
<transient name="city"></transient>
</attributes>
</embeddable>
<entity class="beans.Membership" >
<table name="cc_membership">
</table>
<!-- -->
<attributes>
<id name="id">
<column name="id"/>
<generated-value generator="sq_cc_membership" strategy="SEQUENCE"/>
</id>
<!--more properties-->
<basic name="shortName">
<column name="shortName"/>
</basic>
<version name="version"></version>
<many-to-one name="physicalPerson">
<join-column name="physical_person_id"></join-column>
</many-to-one>
<embedded name="address">
</embedded>
</attributes>
</entity>
The "beans.Address" class have more properties, but when I am going adding more properties, I do not want see more fields in My cc_membership table,
What is the Best Way to do that
thanks,
Upvotes: 0
Views: 869
Reputation: 21145
This cannot be done in standard JPA and so you would resort to provider specific features.
Eclipselink-Orm.xml has an exclude-default-mappings tag that you can use with the xml-mapping-metadata-complete orm.xml tag as described here: https://wiki.eclipse.org/EclipseLink/Examples/JPA/EclipseLink-ORM.XML#.3Cexclude-default-mappings.2F.3E
I don't know if Hibernate has something similar.
Upvotes: 1
Reputation: 24423
I'm not sure you can (or even if you would want to) change the default JPA behavior, but to accomplish this you could create an object which would hold all new fields, ant mark the whole object as transient. Something like this
public class TransientFields {
private String field1;
private String field2;
...
// getters and setters
}
And Address
would look like this
@Embeddable
public class Address {
// persistent fields
...
@Transient
private TransientFields transientFields;
// getters and setters
}
Then, you could change TransientFields
without affecting the database.
Upvotes: 0