私はちょっと立ち往生し、何が起こっているのか分からない。JPAとスカラーの "匿名"クラス
java.lang.IllegalArgumentException: Unknown entity:persistence.dao.EntityDaoTest$$anonfun$13$$anonfun$14$$anon$5
at org.hibernate.internal.SessionImpl.firePersist(SessionImpl.java:777)
この1作品:
val myEntity = new Entity()
entity.owner = "some owner 1"
session.persist(myEntity)
なぜ この1つは
@Entity
@DynamicInsert
@DynamicUpdate
@SelectBeforeUpdate
@Table
class Entity {
@Column(nullable = false)
var owner: String = _
}
val myEntity = new Entity() {
owner = "some owner 1"
}
session.persist(myEntity)
Hibernateが例外をスロー動作しませんか?休止状態で私のEntity
インスタンスが認識されないのはなぜですか?
UPD: @Sheinbergon、ありがとうございます。注釈が失われていることを完全に忘れてしまった。エンティティフィールドにショートカットを設定する可能性はありますか? 書き込み
val myEntity = new MyEntity()
myEntity.owner = "some owner"
myEntity.someOtherProperty = "value"
はスーパー退屈だ
もう一つ質問 この1作品:
val parent = new Parent
parent.owner = "Our parent"
parent.addChild(new Child() {
name = "First parent's child"
addGrandChild(new GrandChild() {
name = "Grand child name"
addGrandGrandChild(new GrandGrandChild() {
name = "Grand Grand child name"
address = new Address() {
id = 1L
}
})
})
})
なぜ?子供、GrandChild、GrandGrandChildも匿名で作成されています。 addChild、addGrandChild、addGrandGrandChildは単なるリストミューテータです。 Scalaで匿名クラスをインスタンス化し、よく...それは(Javaで匿名インタフェースをインスタンス化するように)あなたのクラスEntity
の匿名の実装を作成しているあなたがここでやっている
def addChild(child: Child): Unit = {
if (children == null) {
children = new util.ArrayList[Child]()
}
if (Option(child.parent).isEmpty) {
child.parent = this
}
children.add(child)
}
私の答え(いずれも)があなたを助けたので、「受け入れてください」。私はあなたが提出した新しいサブ質問に関連する以下の答えに別のセクションを追加しました – Sheinbergon
完了、ありがとう!今すぐ明白です – Sergey