You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by Dain Sundstrom <da...@iq80.com> on 2007/04/11 05:36:40 UTC
Float primary key?
I know it is a really really really stupid idea to use an approximate
type at a primary key, but there is a test in the CMP test suite that
uses a float for a primary key. When I deploy this bean, I get an
exception like the following:
Caused by: <0.9.7-incubating-SNAPSHOT fatal user error>
org.apache.openjpa.persistence.ArgumentException: Type "class
foo.FloatBeanEJB" declares field "cmpID" as a primary key, but keys
of type "java.lang.Float" are not supported.
at org.apache.openjpa.meta.ClassMetaData.validateAppIdClass
(ClassMetaData.java:1800)
at org.apache.openjpa.meta.ClassMetaData.validateIdentity
(ClassMetaData.java:1779)
at org.apache.openjpa.meta.ClassMetaData.validateMeta
(ClassMetaData.java:1696)
at org.apache.openjpa.meta.ClassMetaData.resolve
(ClassMetaData.java:1569)
at org.apache.openjpa.meta.MetaDataRepository.processBuffer
(MetaDataRepository.java:656)
at org.apache.openjpa.meta.MetaDataRepository.resolveMeta
(MetaDataRepository.java:556)
at org.apache.openjpa.meta.MetaDataRepository.resolve
(MetaDataRepository.java:481)
at org.apache.openjpa.meta.MetaDataRepository.getMetaData
(MetaDataRepository.java:285)
at org.apache.openjpa.meta.MetaDataRepository.resolveMeta
(MetaDataRepository.java:521)
at org.apache.openjpa.meta.MetaDataRepository.resolve
(MetaDataRepository.java:481)
at org.apache.openjpa.meta.MetaDataRepository.getMetaData
(MetaDataRepository.java:285)
at org.apache.openjpa.jdbc.meta.MappingRepository.getMapping
(MappingRepository.java:276)
at org.apache.openjpa.jdbc.meta.MappingTool.getMapping
(MappingTool.java:667)
at org.apache.openjpa.jdbc.meta.MappingTool.buildSchema
(MappingTool.java:739)
at org.apache.openjpa.jdbc.meta.MappingTool.run(MappingTool.java:
637)
at
org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory.synchronizeMappings
(JDBCBrokerFactory.java:161)
at org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory.newBrokerImpl
(JDBCBrokerFactory.java:127)
at org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker
(AbstractBrokerFactory.java:171)
at org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker
(DelegatingBrokerFactory.java:139)
at
org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityMana
ger(EntityManagerFactoryImpl.java:187)
at
org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityMana
ger(EntityManagerFactoryImpl.java:52)
Is there any way I can turn off this warning? Maybe we can add an
"AllowStupidApproximatePrimaryKeys" flag.
Please :)
-dain
Re: Float primary key?
Posted by Dain Sundstrom <da...@iq80.com>.
On Apr 11, 2007, at 7:28 AM, Kevin Sutter wrote:
> Okay, I looked at the spec a bit closer and it looks like we need
> to allow
> for floats as primary keys:
>
> "The primary key (or field or property of a composite primary key)
> should be
> one of the following types:
> any Java primitive type; any primitive wrapper type; java.lang.String;
> java.util.Date;
> java.sql.Date. In general, however, approximate numeric types (e.g.,
> floating point types) should
> never be used in primary keys."
>
> Although the spec clearly recommends against the use of floating
> points,
> floats are a primitive type (or the Float wrapper) and need to be
> allowed.
> With no special "AllowStupidApproximatePrimaryKeys" flag. :-)
>
> Am I trying to read too much into the spec or Dain's request? This
> seems to
> be something that we need to support.
That's all I needed.
Thanks,
-dain
Re: Float primary key?
Posted by Kevin Sutter <kw...@gmail.com>.
On 4/11/07, Abe White <aw...@bea.com> wrote:
> Given the spec section you quoted, you're definitely right. It's
> something we need to support.
https://issues.apache.org/jira/browse/OPENJPA-214
Re: Float primary key?
Posted by Abe White <aw...@bea.com>.
> Although the spec clearly recommends against the use of floating
> points,
> floats are a primitive type (or the Float wrapper) and need to be
> allowed.
> With no special "AllowStupidApproximatePrimaryKeys" flag. :-)
>
> Am I trying to read too much into the spec or Dain's request? This
> seems to
> be something that we need to support.
Given the spec section you quoted, you're definitely right. It's
something we need to support.
Notice: This email message, together with any attachments, may contain information of BEA Systems, Inc., its subsidiaries and affiliated entities, that may be confidential, proprietary, copyrighted and/or legally privileged, and is intended solely for the use of the individual or entity named in this message. If you are not the intended recipient, and have received this message in error, please immediately return this by email and then delete it.
Re: Float primary key?
Posted by Kevin Sutter <kw...@gmail.com>.
Okay, I looked at the spec a bit closer and it looks like we need to allow
for floats as primary keys:
"The primary key (or field or property of a composite primary key) should be
one of the following types:
any Java primitive type; any primitive wrapper type; java.lang.String;
java.util.Date;
java.sql.Date. In general, however, approximate numeric types (e.g.,
floating point types) should
never be used in primary keys."
Although the spec clearly recommends against the use of floating points,
floats are a primitive type (or the Float wrapper) and need to be allowed.
With no special "AllowStupidApproximatePrimaryKeys" flag. :-)
Am I trying to read too much into the spec or Dain's request? This seems to
be something that we need to support.
Kevin
On 4/11/07, Kevin Sutter <kw...@gmail.com> wrote:
>
> Dain,
> When you mention the "CMP test suite" are you referring to the CTS TCK?
> If so, how does "CMP" correspond to EJB's and their use of JPA (in the EJB3
> sense)? I understand your request. I'm just trying to understand whether
> this is a "requirement" or just a bad test case in the CTS TCK. The JPA
> spec is pretty clear that approximate types should never be used for primary
> keys -- although I suppose you could read it that some providers could allow
> this use. It just wouldn't be portable.
>
> Kevin
>
> On 4/10/07, Dain Sundstrom <da...@iq80.com> wrote:
> >
> > I know it is a really really really stupid idea to use an approximate
> > type at a primary key, but there is a test in the CMP test suite that
> > uses a float for a primary key. When I deploy this bean, I get an
> > exception like the following:
> >
> > Caused by: <0.9.7-incubating-SNAPSHOT fatal user error>
> > org.apache.openjpa.persistence.ArgumentException: Type "class
> > foo.FloatBeanEJB" declares field "cmpID" as a primary key, but keys
> > of type "java.lang.Float" are not supported.
> > at org.apache.openjpa.meta.ClassMetaData.validateAppIdClass
> > (ClassMetaData.java:1800)
> > at org.apache.openjpa.meta.ClassMetaData.validateIdentity
> > (ClassMetaData.java:1779)
> > at org.apache.openjpa.meta.ClassMetaData.validateMeta
> > (ClassMetaData.java:1696)
> > at org.apache.openjpa.meta.ClassMetaData.resolve
> > (ClassMetaData.java:1569)
> > at org.apache.openjpa.meta.MetaDataRepository.processBuffer
> > (MetaDataRepository.java:656)
> > at org.apache.openjpa.meta.MetaDataRepository.resolveMeta
> > (MetaDataRepository.java:556)
> > at org.apache.openjpa.meta.MetaDataRepository.resolve
> > (MetaDataRepository.java :481)
> > at org.apache.openjpa.meta.MetaDataRepository.getMetaData
> > (MetaDataRepository.java:285)
> > at org.apache.openjpa.meta.MetaDataRepository.resolveMeta
> > (MetaDataRepository.java:521)
> > at org.apache.openjpa.meta.MetaDataRepository.resolve
> > (MetaDataRepository.java:481)
> > at org.apache.openjpa.meta.MetaDataRepository.getMetaData
> > (MetaDataRepository.java:285)
> > at org.apache.openjpa.jdbc.meta.MappingRepository.getMapping
> > (MappingRepository.java :276)
> > at org.apache.openjpa.jdbc.meta.MappingTool.getMapping
> > (MappingTool.java:667)
> > at org.apache.openjpa.jdbc.meta.MappingTool.buildSchema
> > (MappingTool.java:739)
> > at org.apache.openjpa.jdbc.meta.MappingTool.run (MappingTool.java:
> > 637)
> > at
> > org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory.synchronizeMappings
> > (JDBCBrokerFactory.java:161)
> > at org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory.newBrokerImpl
> > (JDBCBrokerFactory.java :127)
> > at org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker
> > (AbstractBrokerFactory.java:171)
> > at org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker
> > (DelegatingBrokerFactory.java:139)
> > at
> > org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityMana
> > ger(EntityManagerFactoryImpl.java:187)
> > at
> > org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityMana
> > ger(EntityManagerFactoryImpl.java :52)
> >
> > Is there any way I can turn off this warning? Maybe we can add an
> > "AllowStupidApproximatePrimaryKeys" flag.
> >
> > Please :)
> >
> > -dain
> >
>
>
Re: Float primary key?
Posted by Kevin Sutter <kw...@gmail.com>.
Dain,
When you mention the "CMP test suite" are you referring to the CTS TCK? If
so, how does "CMP" correspond to EJB's and their use of JPA (in the EJB3
sense)? I understand your request. I'm just trying to understand whether
this is a "requirement" or just a bad test case in the CTS TCK. The JPA
spec is pretty clear that approximate types should never be used for primary
keys -- although I suppose you could read it that some providers could allow
this use. It just wouldn't be portable.
Kevin
On 4/10/07, Dain Sundstrom <da...@iq80.com> wrote:
>
> I know it is a really really really stupid idea to use an approximate
> type at a primary key, but there is a test in the CMP test suite that
> uses a float for a primary key. When I deploy this bean, I get an
> exception like the following:
>
> Caused by: <0.9.7-incubating-SNAPSHOT fatal user error>
> org.apache.openjpa.persistence.ArgumentException: Type "class
> foo.FloatBeanEJB" declares field "cmpID" as a primary key, but keys
> of type "java.lang.Float" are not supported.
> at org.apache.openjpa.meta.ClassMetaData.validateAppIdClass
> (ClassMetaData.java:1800)
> at org.apache.openjpa.meta.ClassMetaData.validateIdentity
> (ClassMetaData.java:1779)
> at org.apache.openjpa.meta.ClassMetaData.validateMeta
> (ClassMetaData.java:1696)
> at org.apache.openjpa.meta.ClassMetaData.resolve
> (ClassMetaData.java:1569)
> at org.apache.openjpa.meta.MetaDataRepository.processBuffer
> (MetaDataRepository.java:656)
> at org.apache.openjpa.meta.MetaDataRepository.resolveMeta
> (MetaDataRepository.java:556)
> at org.apache.openjpa.meta.MetaDataRepository.resolve
> (MetaDataRepository.java:481)
> at org.apache.openjpa.meta.MetaDataRepository.getMetaData
> (MetaDataRepository.java:285)
> at org.apache.openjpa.meta.MetaDataRepository.resolveMeta
> (MetaDataRepository.java:521)
> at org.apache.openjpa.meta.MetaDataRepository.resolve
> (MetaDataRepository.java:481)
> at org.apache.openjpa.meta.MetaDataRepository.getMetaData
> (MetaDataRepository.java:285)
> at org.apache.openjpa.jdbc.meta.MappingRepository.getMapping
> (MappingRepository.java:276)
> at org.apache.openjpa.jdbc.meta.MappingTool.getMapping
> (MappingTool.java:667)
> at org.apache.openjpa.jdbc.meta.MappingTool.buildSchema
> (MappingTool.java:739)
> at org.apache.openjpa.jdbc.meta.MappingTool.run(MappingTool.java:
> 637)
> at
> org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory.synchronizeMappings
> (JDBCBrokerFactory.java:161)
> at org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory.newBrokerImpl
> (JDBCBrokerFactory.java:127)
> at org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker
> (AbstractBrokerFactory.java:171)
> at org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker
> (DelegatingBrokerFactory.java:139)
> at
> org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityMana
> ger(EntityManagerFactoryImpl.java:187)
> at
> org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityMana
> ger(EntityManagerFactoryImpl.java:52)
>
> Is there any way I can turn off this warning? Maybe we can add an
> "AllowStupidApproximatePrimaryKeys" flag.
>
> Please :)
>
> -dain
>
Re: Float primary key?
Posted by Abe White <aw...@bea.com>.
I believe that OpenJPA will allow float pk fields, it's just that
there's no built-in id class for them (see util.LongId, ShortId,
etc). So you'd have to either add a built-in id class and alter
OpenJPA's internal code to use it appropriately, or create your own
id class and use it via the @IdClass annotation, as you would for a
compound pk.
Notice: This email message, together with any attachments, may contain information of BEA Systems, Inc., its subsidiaries and affiliated entities, that may be confidential, proprietary, copyrighted and/or legally privileged, and is intended solely for the use of the individual or entity named in this message. If you are not the intended recipient, and have received this message in error, please immediately return this by email and then delete it.