Re: Hibernate
On Wed, 4 May 2011, Arved Sandstrom wrote:
On 11-05-03 06:24 PM, Steve Sobol wrote:
I've finally started using Hibernate again, after a long sabbatical. I
really disliked having to declare each object in a separate XML file,
and I am very happy that I now only need hibernate.cfg.xml and some
annotations.
Let me make one recommendation, Steve. Especially given that you have
used Hibernate before, and some time ago. Try not to use Hibernate
native APIs - stick to JPA. [...] With JPA 1.0 there were sizeable API
gaps that made forays into native ORM (Toplink, EclipseLink, Hibernate,
OpenJPA etc) APIs justifiable and somewhat common. But even with JPA
1.0-compliant implementations you could do most of your work with
standard JPA. With JPA 2.0 it's much more comprehensive.
In my limited experience of it, it does seem that way.
There are still things missing, though. Do we have any idea what's going
to be in JPA 3.0, or whatever the next significant feature release is
going to be?
Off the top of my head, things i'd like to see (caveat - these might
already be supported; there are many, many corners of JPA i don't know):
* A standardised way to add new type mappings (eg i'd like to be able to
have a @Basic property of type Locale that gets stored as a varchar like
"en_GB" rather than a BLOB of serialized data as now.
* Support for mapping properties of type SortedSet and SortedMap with
@OrderBy (at the moment, AFAIK, it has to be a list, which is not really
the right type, since if you're doing a normal mappedBy-type plural
property, you can't actually have duplicates!).
* An easier way of handling composite keys - i'd like to be able to do
something like annotate multiple properties with @Id, and then use object
arrays (or perhaps instances of Tuple) as keys. Similar to the situation
with @IdClass now, but without having to write a class just to wrap the
key.
I was also going to say that i wanted support for using as part of a
composite key: eg if i have a Price for each combination of Country and
SKU, i'd like to have fields @Id @ManyToOne Country country and @Id
@ManyToOne SKU sku, which i had only come across slightly iffy ways of
doing (involving an @IdClass where the ID class and entity have different
types for the fields). But just this minute, i came across @MapsId:
http://download.oracle.com/javaee/6/api/javax/persistence/MapsId.html
Which i think lets me write:
@Embeddable
public class PriceKey implements Serializable {
private String countryCode;
private int skuNumber;
// etc
}
@Entity
public class Price {
@EmbeddedId
private PriceKey key;
@MapsId("countryCode")
@ManyToOne
private Country country;
@MapsId("skuNumber")
@ManyToOne
private SKU sku;
}
Which is more or less exactly what i wanted. I think. Haven't actually
tried this.
Any other suggestions?
tom
--
Voltan tires of life upon Super Secret Sea-Base Beta. Perhaps this
Holloway Road of which you speak is the solution. Voltan shall investigate
it during Voltans campaign to overrun London. (This is but a part of
Voltans plan for world domination.) -- Voltan