openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Craig L Russell <Craig.Russ...@Sun.COM>
Subject Re: Can we have an entity with no @Id?
Date Wed, 20 May 2009 17:49:09 GMT

Tables without primary keys is one of the features of JDO that was not  
adopted by JPA.

Maybe you should look at JDO implementations.


On May 20, 2009, at 8:12 AM, is_maximum wrote:

> Hello
> To Andrei I want to say that because it is simple to create an  
> object and
> send it to be persisted however this could be a good idea.
> And to Kevin, if in secondary table we have only a foreign key to  
> distinct
> records that would be enough because the id for the secondary table   
> is not
> used anywhere. All we need from these two tables is a report that  
> tells us
> what kind of events (secondary table) have been occurred for a  
> specific
> operation in specific time (master table) and order is not important  
> since
> the time of event will order those records in right way. So what is  
> this ID
> good for? In case of existence of this ID we have to either create  
> an Oracle
> sequence (which is a bottleneck in database because it takes up cache
> particularly in a clustered environment) or selecting the maximum ID  
> (which
> is required to scan all the records) or create a sequence table  
> managed by
> ORM (That will end up with a select statement and an update  
> following that)
> or create that id manually (that it is almost impossible)
> Kevin Sutter wrote:
>> Hi is_maximum,
>> I'm still a little confused by your scenario.  Following your  
>> described
>> scenario...  Your master table would have an Id field, but your  
>> secondary
>> table would not have an explicit Id field.  The foreign key from your
>> master
>> to secondary would just be some arbitrary column from the secondary  
>> table?
>> Do I have that right?  And, why would removing an Id field help with
>> performance?  You mention to get rid of its sequence, but there's no
>> requirement to define an Id field with a sequence.
>> Even though I'm still a little confused by your scenario, there are a
>> couple
>> of items to be aware of from an OpenJPA perspective.  The JPA spec
>> requires
>> an Id field, but OpenJPA does not require one.  Well, not exactly.
>> Instead
>> of declaring an explicit Id field, you could instead declare an Id  
>> via the
>> @DataStoreId annotation [1].  This hides the Id field from your  
>> Entity
>> definition, but under the covers we still use an implicit Id field in
>> order
>> to insert and find records.
>> Another possibility is coming with the updated JPA 2 specification  
>> and the
>> use of derived identities.  I'm probably stretching this one a bit,  
>> but
>> this
>> support would allow you to derive an identity for an Entity based  
>> on the
>> identity of a "parent" Entity.  This is normally used when the  
>> dependent
>> Entity is the owner of a many-to-one or one-to-one relationship to  
>> the
>> parent entity.  Here again, OpenJPA provides a similar  
>> functionality with
>> their Entities as Identity fields.
>> So, bottom line is that some type of Identity is required for proper
>> Entity
>> definition and usage.  But, OpenJPA (and eventually the JPA 2 spec)
>> provides
>> for some methods to get around the explicit definition of an Id  
>> field.
>> Hope this helps,
>> Kevin
>> [1]
>> [2]
>> On Wed, May 20, 2009 at 7:14 AM, is_maximum <> wrote:
>>> Hi
>>> We have some tables in which id is not important and actually it is
>>> useless.
>>> For example we have two logging tables, one is master and the  
>>> other is
>>> keeping details. The only foreign key from the master table is  
>>> enough and
>>> the second table has no relationship with other tables so if we  
>>> remove
>>> its
>>> ID we can get rid of its sequence and this will be great in terms of
>>> performance since this table is considered to keep lots of records  
>>> and
>>> its
>>> purpose is for preserving events took place in the system
>>> Now my question is how to remove its @Id from the entity since the
>>> OpenJPA
>>> complains if the entity has no field marked as id
>>> Thanks
>>> --
>>> View this message in context:
>>> Sent from the OpenJPA Users mailing list archive at
> -----
> --
> Regards
> Mohammad
> Pixelshot
> -- 
> View this message in context:
> Sent from the OpenJPA Users mailing list archive at

Craig L Russell
Architect, Sun Java Enterprise System
408 276-5638
P.S. A good JDO? O, Gasp!

View raw message