1
我有一個簡單的實體類像;Ebean不堅持外鍵
case class Place(var name: String) extends Model with GeoLocPoint with HasGeoLoc with ContainsTime with HasId {
var number: String = _ // Building number on the street.
var placeGroupId: Long = _
var chainId: Long = _
@OneToOne
@JoinColumn(name = "logo_id")
var logo: Image = _
@OneToOne
@JoinColumn(name = "cover_id")
var cover: Image = _
...
}
而圖像類是;
package models.images
import javax.persistence.Entity
import models.HasId
import models.places.placegroups.places.{Place, LinkedToPlace}
import play.api.libs.json._
import play.db.ebean.Model
import play.db.ebean.Model.Finder
/**
* Created by asheshambasta on 31/12/14.
*/
@Entity
case class Image(
filePath: String,
src: String,
format: String,
role: String // C: cover, L: logo, G: gallery
) extends Model with HasId with LinkedToPlace {
var caption: String = _
}
現在,當創建一個地方時,我附加了一個默認圖像;
newPlace.save
val imgDir = Play.current.configuration.getString("static.dir").getOrElse("/tmp")
val imgUrl = Play.current.configuration.getString("static.url.img").getOrElse("/static/img")
val imgType = Play.current.configuration.getString("img.default.type").getOrElse("image/jpeg")
val coverFile = Play.current.configuration.getString("img.default.cover.file").getOrElse("default-cover.jpg")
val logoFile = Play.current.configuration.getString("img.default.cover.file").getOrElse("default-cover.jpg")
val cover = new Image(imgDir + "/" + coverFile, imgUrl + "/" + coverFile, imgType, "C")
cover.place = newPlace
cover.save
val logo = new Image(imgDir + "/" + logoFile, imgUrl + "/" + logoFile, imgType, "L")
logo.place = newPlace
logo.save
newPlace.cover = cover
newPlace.logo = logo
newPlace.update
但隨後每一次,我看到的圖像得到與正確的place_id的地方,而是標誌和蓋正確地堅持不要。他們保持空。
這看起來很簡單,但它不起作用。有沒有人有任何指向爲什麼?
是我的回答有幫助嗎?我沒有收到你的任何反饋。 – rtruszk