Quantcast

JPA annotations fails when using 2.8 beta (also rc2)

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

JPA annotations fails when using 2.8 beta (also rc2)

steffensphoto
Hi

I am trying to get JPA and Scala 2.8 beta rc2 to compile but I get the
following error both in netbeans 2.8 rc2 and in (x)sbt:

Project.scala:16: error: expected start of definition
@Table{ val name="projects" }

Project.scala:22: error: expected start of definition
@GeneratedValue{ val strategy=GenerationType.IDENTITY }
two errors found

The code is taken from http://www.hars.de/2009/03/jpa-with-scala.html:

package dk.scala.model

import _root_.javax.persistence._

object Project {
  def find(id: Int)(implicit em: EntityManager) : Project =
    em.find(classOf[Project], id).asInstanceOf[Project]
}

@Entity
@Table{ val name="projects" }
class Project(name: String) {

  def this() = this("")

  @Id
  @GeneratedValue{ val strategy=GenerationType.IDENTITY }
  var id : Int = _

  @Version
  var version : Int = _

  var title : String = name
}


I have tried to outcomment the lines with errors and then it compiles,
but I thought this should be allowed in 2.8?

Perhaps someone can point me to a good example of using jpa in scala
besides the lift page?

Thanx in advance
Steffen
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: JPA annotations fails when using 2.8 beta (also rc2)

Lukas Rytz
The syntax has changed in 2.8, you should use named arguments:

@Table(name = "projects")
class Project(name: String) {
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  var id: Int = _
}


By the way, the `@GeneratedValue` annotation will be added to the
(private) field only, but not to the compiler-generated (public) getter and
setter.
This behavior can be controlled using the meta-annotations in package
`scala.annotation.target`. See documentation in
http://lampsvn.epfl.ch/trac/scala/browser/scala/trunk/src/library/scala/annotation/target/getter.scala


Lukas

On Mon, Dec 7, 2009 at 13:10, Steffen Egelund Jensen <[hidden email]> wrote:
Hi

I am trying to get JPA and Scala 2.8 beta rc2 to compile but I get the
following error both in netbeans 2.8 rc2 and in (x)sbt:

Project.scala:16: error: expected start of definition
@Table{ val name="projects" }

Project.scala:22: error: expected start of definition
@GeneratedValue{ val strategy=GenerationType.IDENTITY }
two errors found

The code is taken from http://www.hars.de/2009/03/jpa-with-scala.html:

package dk.scala.model

import _root_.javax.persistence._

object Project {
 def find(id: Int)(implicit em: EntityManager) : Project =
   em.find(classOf[Project], id).asInstanceOf[Project]
}

@Entity
@Table{ val name="projects" }
class Project(name: String) {

 def this() = this("")

 @Id
 @GeneratedValue{ val strategy=GenerationType.IDENTITY }
 var id : Int = _

 @Version
 var version : Int = _

 var title : String = name
}


I have tried to outcomment the lines with errors and then it compiles,
but I thought this should be allowed in 2.8?

Perhaps someone can point me to a good example of using jpa in scala
besides the lift page?

Thanx in advance
Steffen

Loading...