Welcome to

Confessions of a build breaker

A blog on Java, JEE and Spring by Jelmer Kuperus

JPA missing non-exotic features

July 14th, 2007 by site admin

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 ?

Posted in General |

4 Responses

  1. Emmanuel Says:

    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. Rob de Boer Says:

    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. site admin Says:

    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. Anonymous Says:

    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

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.

copyright © 2oo6 by Confessions of a build breaker | Powered by Wordpress

Ported by ThemePorter - template by Design4 | Sponsored by 47channel