openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kevin Sutter <kwsut...@gmail.com>
Subject Re: @DataStoreId + Generator + omitting any @Id-Fields
Date Fri, 22 May 2009 18:23:54 GMT
Hi Heiko,
My apologies if my other reply implied that no PK would be required.  What
the @DataStoreId provides is the ability to hide an PK field from the Entity
definition.  But, JPA itself (and OpenJPA) requires a PK field of some sort
in order to perform normal Entity operations (insert, find, etc).  Hope this
helps clarify the usage.

Kevin


On Fri, May 22, 2009 at 8:24 AM, <it-media.kopp@daimler.com> wrote:

> Hello,
>
> as I was reading the thread 'Can we have entities without @Id' carefully,
> I read about the possibility to use @DataStoreId to modify the way a
> primary key column can be retrieved. However, I do NOT understand
> correctly how to do this.
>
> I have an issue where I'm not able to change the table-model within the
> database, but have to create entities from a table that does not provide a
> primary key at all. As it is simply necessary to read information from
> this table I wanted to use DataStoreId to let JPA generate an Id Column
> itself and add it to the entity.
>
> However, this does not seem to work as I expected. I added the following
> code:
>
> @Entity
> @Table(name = "WBZ")
> @DataStoreId(strategy = GenerationType.SEQUENCE, generator="time")
> public class WirtschaftlicheBeziehung
> {
>        // no id fields in here
> }
>
> As far as I can see in the openJPA source, this leads to an automatic
> generation of an 'id' column. My problem now is, I do not have an 'id'
> column in the database, thus this crashes with an exception, that the
> table WBZ lacks a column named 'id'.
>
> My question now is, is there a way to use DataStoreId to handle tables
> without primary key columns? I do not fully understand the usage of the
> special annotation of DataStoreId when it still searches for a column in
> the database. I thought I do not have to have such a column?
>
> Thanks for your time!
>
> Heiko
>
> If you are not the intended addressee, please inform us immediately that
> you have received this e-mail in error, and delete it. We thank you for your
> cooperation.

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message