본문 바로가기

Development/Web & Server

[Play Framework2] JPA & Json model

Java는 POJO 객체로 JPA와 Json이 아주 자유로웠지만 Scala에서는 정말 헤매는 부분이 많았다. 그리고 본인이 가장 간편하다고 생각하는 방법을 설명하겠다. 특별히 Play Framework2 이외에 다른 라이브러리를 사용하지 않고 내부적인 라이브러리를 통해 쉬운 방법을 찾았다. (one to many 와 many to many 는 아직 방법을 찾지 못함..)


import play.db.jpa._

import javax.persistence._

import play.api.libs.json._

import play.api.libs.functional.syntax._

import scala.annotation.meta.field


@Entity

@Table (name = "class")

case class Class (

  @(Id @field) @(GeneratedValue @field)@(Column @field)(name = "no") var no : Long,

  @(ManyToOne @field) @(JoinColumn @field) (name = "school_no") var school : School,

  @(Column @field)(name = "grade") var grade: Long,

  @(Column @field)(name = "group_number") var group: Long

) {

  def this() = this(0, null, 0, 0)

}


object Class {

  implicit val classWriters = Json.writes[Class]

  implicit val classReads = Json.reads[Class]

}



'Development > Web & Server' 카테고리의 다른 글

typesafe activator 삭제하기  (0) 2015.07.18
[Play Framework2] Json polymorphism  (0) 2015.06.17
[Play Framework2] Json  (0) 2015.06.01
[Play Framework2] JPA  (0) 2015.06.01
[Play Framework2] WebSockets  (0) 2015.05.26