Trifork Blog

JPA missing non-exotic features

July 14th, 2007 by
|

Ever since the Java Persistence API was announced there has been a lot of talk, both good and bad, about this specification. Many people have pointed out that a criteria API and something like hibernate filters are currently missing. However these features might be considered “exotic” and I can largely live without them. However a few weeks back I started working on my first JPA project and quickly encountered some missing features that where not exotic at all.

First of all Lists do not preserve ordering. Next time you retrieve your ordered list it will be returned in an unspecified order. This means that if you have to implement an application in which a user can move items up or down in a list, you will have to manage indexing yourself. How’s that for “transparent persistence”. Persisting the order of the List is something that is being considered for inclusion in a subsequent version of the specification.

JPA does not support unidirectional OneToMany relations well
Say you have an Order that contains a collection of OrderLineItems’s and you do not want the OrderLineItem to hold a reference to your Order. In JPA You cannot accomplish this without introducing a jointable.

For both these issues there are vendor specific extensions that help you work around these limitations. But I can’t help but feel flabbergasted that this isn’t supported.

Does anyone know of any more glaring omissions in this spec ?

4 Responses

  1. July 15, 2007 at 17:12 by Emmanuel

    use @joincolumn with your onetomany. This is perfectly standard
    some providers might not support it but that’s a vendor limitation, not a spec one 🙂

  2. July 16, 2007 at 08:12 by Rob de Boer

    IS the ordering of the list really unspecified? I would expect it to order it by database identifier by default. If this isn’t even the case, then I find it especially weird.

  3. July 16, 2007 at 15:37 by site admin

    Its as unspecified as select name from names is. Eg. no ordering is specified so the database is allowed to return the names in any order it pleases.

    You can however specify an explicit ordering by annotating the collection.

  4. July 18, 2007 at 09:09 by Anonymous

    On page 105 of pro ejb java persistence api, co-authored by the jpa speclead it reads

    “Some vendords may provide support for a unidirectional one-to-many target foreign key mapping, where a join column exists in the target table but no relationship exists from the target entity back to the source entity. This is not supported in the current version of the java persistence API”

    And on the jpox site i found this quote

    In strict JPA1 you cannot have a 1-N unidirectional relation using a ForeignKey – they must have a JoinTable. Consequently to use this relation as specified below you must specify the property “org.jpox.jpa.oneToManyUniFkRelations” as “true”

    Hibernate does seem to support @Joincolumn but that seems to be very much not standard