Je suis un peu coincé et je ne comprends pas ce qui se passe. Celui-ci ne fonctionne pasJPA et classes "anonymes" en scala
@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 lance exception:
java.lang.IllegalArgumentException: Unknown entity:persistence.dao.EntityDaoTest$$anonfun$13$$anonfun$14$$anon$5
at org.hibernate.internal.SessionImpl.firePersist(SessionImpl.java:777)
Celui-ci fonctionne:
val myEntity = new Entity()
entity.owner = "some owner 1"
session.persist(myEntity)
Pourquoi? Pourquoi hibernate ne reconnaît pas mon instance Entity
?
UPD: @Sheinbergon, merci, c'est clair. J'ai complètement oublié que les annotations sont perdues. Est-il possible de définir des champs d'entité avec un raccourci? écriture
val myEntity = new MyEntity()
myEntity.owner = "some owner"
myEntity.someOtherProperty = "value"
est super ennuyeux
Une question Celui-ci fonctionne:
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
}
})
})
})
Pourquoi? Enfant, GrandChild, GrandGrandChild également créé anonymement. addChild, addGrandChild, addGrandGrandChild ne sont que des mutateurs de liste.
def addChild(child: Child): Unit = {
if (children == null) {
children = new util.ArrayList[Child]()
}
if (Option(child.parent).isEmpty) {
child.parent = this
}
children.add(child)
}
S'il vous plaît "accepter" ma réponse (l'un d'entre eux) comme il vous a aidé. J'ai ajouté une autre section à la réponse ci-dessous qui se rapporte aux nouvelles sous-questions que vous avez soulevées – Sheinbergon
Fait, merci!Maintenant c'est clair – Sergey