You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by chintan4181 <ch...@gmail.com> on 2011/04/30 00:26:02 UTC

Entity without primary key

Hi,

In my existing db schema, i have few look tables which doesnt have primary
key defined. When i generate entities from tables, i am getting error saying
"Every entity must have primary key". Since this is exisitng schema, i dont
want to change these tables.

is there a way to avoid these error?

Thanks
chintan--
View this message in context: http://openjpa.208410.n2.nabble.com/Entity-without-primary-key-tp6318428p6318428.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: Entity without primary key

Posted by chintan4181 <ch...@gmail.com>.
thanks kevin.

I understood what i want. @ElementCollection and @CollectionTable will be
useful in my case. 



--
View this message in context: http://openjpa.208410.n2.nabble.com/Entity-without-primary-key-tp6318428p6328314.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: Entity without primary key

Posted by Kevin Sutter <kw...@gmail.com>.
A little more detail on the content of these tables and the entities that
consume them would be helpful.  But, it sounds like @ElementCollection and
@CollectionTable might be of use.  You can reference the spec [1], or the
Pro JPA 2 book [2], or some of these other urls for examples.

[1]  http://www.jcp.org/en/jsr/detail?id=317
[2]
http://www.amazon.com/Pro-JPA-Mastering-Persistence-Technology/dp/1430219564
[3]  http://en.wikibooks.org/wiki/Java_Persistence/ElementCollection

http://www.developer.com/java/ent/article.php/3898336/The-Top-5-New-Annotations-in-JPA-2.htm

On Mon, May 2, 2011 at 5:57 PM, chintan4181 <ch...@gmail.com> wrote:

> Yes these tables are used by other entities as Set .
>
> What would you suggest?
>
> --
> View this message in context:
> http://openjpa.208410.n2.nabble.com/Entity-without-primary-key-tp6318428p6325602.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>

Re: Entity without primary key

Posted by chintan4181 <ch...@gmail.com>.
Yes these tables are used by other entities as Set .

What would you suggest?

--
View this message in context: http://openjpa.208410.n2.nabble.com/Entity-without-primary-key-tp6318428p6325602.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: Entity without primary key

Posted by Kevin Sutter <kw...@gmail.com>.
Entities by definition require an id, or primary key.  OpenJPA provides a
DataStore ID mechanism [1] which provides a surrogate key instead of an
explicit primary key declaration, but to be honest, this is not used all
that often.

How are these other tables used?  Are the values in these non-primary key
tables used by other Entities?  Maybe the ElementCollection and/or
CollectionTable annotations are applicable to your situation.

The Reverse Mapping tools for generating Entity classes are meant to give
you a starting point.  The classes that are generated should give you a good
basis, but tweaks will undoubtedly be required to complete your O/R Mapping.

Kevin

[1]
http://openjpa.apache.org/builds/latest/docs/manual/manual.html#ref_guide_pc_oid_datastore

On Mon, May 2, 2011 at 2:06 PM, Rick Curtis <cu...@gmail.com> wrote:

> Have you tried creating your Entities by hand and see how OpenJPA handles
> them at runtime?
>
> Thanks,
> Rick
>
> On Fri, Apr 29, 2011 at 5:26 PM, chintan4181 <ch...@gmail.com>
> wrote:
>
> > Hi,
> >
> > In my existing db schema, i have few look tables which doesnt have
> primary
> > key defined. When i generate entities from tables, i am getting error
> > saying
> > "Every entity must have primary key". Since this is exisitng schema, i
> dont
> > want to change these tables.
> >
> > is there a way to avoid these error?
> >
> > Thanks
> > chintan-
>

Re: Entity without primary key

Posted by Rick Curtis <cu...@gmail.com>.
Have you tried creating your Entities by hand and see how OpenJPA handles
them at runtime?

Thanks,
Rick

On Fri, Apr 29, 2011 at 5:26 PM, chintan4181 <ch...@gmail.com> wrote:

> Hi,
>
> In my existing db schema, i have few look tables which doesnt have primary
> key defined. When i generate entities from tables, i am getting error
> saying
> "Every entity must have primary key". Since this is exisitng schema, i dont
> want to change these tables.
>
> is there a way to avoid these error?
>
> Thanks
> chintan-