These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Migrating old ORM solution to JPA/Hibernate
PostPosted: Fri May 21, 2010 9:35 am 
Newbie

Joined: Mon Oct 10, 2005 6:11 am
Posts: 10
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.