Hi,
Many of my project uses an old orm solution, which i developed couple of years ago. I would like to switch to JPA/Hibernate, with the least effort possible. I'm thinking about not rewriting everything from scratch, but to keep the interfaces from my orm soulution, and rewrite only the core orm project.
Here is a sample entity:
Code:
@Entity(cacheable = true, cacheClass = HardReferenceCache.class)
public final class CityImpl extends AbstractGeographic<Country> implements City {
private transient Country _country;
public CityImpl() {
super();
}
public CityImpl(final String iataCode, final String name) {
setKey(iataCode);
setName(name);
}
public CityImpl(final String iataCode, final String name,
final Country country) {
this(iataCode, name);
setSuperiorGeographic(country);
}
public ObjectIdentifierString getCountryOID() {
return new ObjectIdentifierString(
getStaCityIsoCountryCode().getValueAsString());
}
public GeographicPrecision getGeographicPrecision() {
return GeographicPrecision.CITY;
}
public String getKey() {
return getObjectIdentifier().getValueAsString();
}
public String getName() {
return getStaCityName().getValueAsString();
}
@Attribute(key = PrimaryKey.KEY_OBJECT_IDENTIFIER, primaryKey = true)
@Override
public CityPK getObjectIdentifier() {
return (CityPK) getPrimaryKey();
}
@Attribute(key = KEY_SUPERIOR_GEORGAPHIC)
@ManyToOne(targetEntity = CountryImpl.class, fetch = FetchType.LAZY, mappedBy = StaCityIsoCountryCode.FIELD_NAME, cascade = CascadeType.REFRESH)
public Country getSuperiorGeographic() throws PersistenceException {
if (_country == null) {
_country = (Country) getAttribute(KEY_SUPERIOR_GEORGAPHIC);
}
return _country;
}
@Attribute(key = StaCityIsoCountryCode.FIELD_NAME)
protected StaCityIsoCountryCode getStaCityIsoCountryCode() {
return (StaCityIsoCountryCode) getAttribute(StaCityIsoCountryCode.FIELD_NAME);
}
@Attribute(key = StaCityName.FIELD_NAME)
protected StaCityName getStaCityName() {
return (StaCityName) getAttribute(StaCityName.FIELD_NAME);
}
protected void setKey(final String value) {
setAttribute(AttributeFactory.getInstance(
StaCityIataCityCode.class,
value));
}
protected void setName(final String name) {
setAttribute(AttributeFactory.getInstance(StaCityName.class, name));
}
} // end class CityImpl
A little explanation:
As you can see the framework is annotation based, with very similar annotations as JPA. Every getter that has an @Attribute returns a persistent value. The returned value is not a primitive, but an attribute class, which wraps the primitive value. The are no instance variables for the getters/setters, they just call setAttriubte/getAttribute on the superclass.
Is this possible somehow?
Thanks.