google-code-export / objectify-appengine

Automatically exported from code.google.com/p/objectify-appengine
MIT License
1 stars 0 forks source link

Scala model class with @Id Long can't be predefined to null [patch inside] #96

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
When coding model classes in scala, we cannot assign a null value to a Long 
(scala limitations), and must predefined it with a value (_, 0).

By changing line 299 of class:
  com.googlecode.objectify.impl.ConcreteEntityMetadata
replacing : 
  if (id != null)
with:
  if (id != null && id > 0)

In order to generate a new value if Long is null or Long is equals or less than 
0. 
1-(Ok now '0' is hard coded but it could be externalized for those who wants to 
have a fined grain control to everything)...
2-(I didn't look if this 0 test was breaking some paradign in the whole 
project) 

With this small change we could now define our model scala classes like this:
package x.y.z.model

import javax.persistence.Id
import scala.reflect.BeanProperty

/** A rabbit is not a binary egyptian sun god */
class Rabbit {

  @Id
  @BeanProperty 
  var id: Long = _ // 

  @BeanProperty
  var name: String = _
}

Thank you for this greeeaaat project!

Original issue reported on code.google.com by jreva...@gmail.com on 11 Jul 2011 at 8:28

GoogleCodeExporter commented 9 years ago
Et voici le fichier modifié

Original comment by jreva...@gmail.com on 11 Jul 2011 at 8:32

Attachments:

GoogleCodeExporter commented 9 years ago
And the test email report

Original comment by jreva...@gmail.com on 11 Jul 2011 at 8:56

Attachments:

GoogleCodeExporter commented 9 years ago
According to a recent post on the Objectify mailing list, you can resolve this 
by declaring the field to be of type java.lang.Long.

The problem with using 0 is that this uninitialized value is a common indicator 
of a bug in the code when you are using natural keys.  I am loathe to remove 
this safety net.

Original comment by lhori...@gmail.com on 29 Jul 2011 at 7:40

GoogleCodeExporter commented 9 years ago
Closing this as WontFix; if it turns out the use of java.lang.Long doesn't work 
please reopen this issue.  Thanks.

Original comment by lhori...@gmail.com on 16 Dec 2011 at 2:36