<@U3NCE6L8G> Did you try to map a List? I'm not ge...
# tornadofx
m
@bkenn Did you try to map a List? I'm not getting
b
I haven't tried. Ill see if i can get it to work
Alright, I figured it out. Hibernate doesn't have any handling of Observables so we need to have getters and setters for List<T>. So you need to create those are add the annotations onto the getter function.
Copy code
@get:Transient
    val customersProperty: ObservableList<Customer> = FXCollections.observableArrayList()

 @OneToMany(fetch = FetchType.EAGER, cascade = [CascadeType.ALL])
    fun getCustomers(): List<Customer> = customersProperty.toList()

    fun setCustomers(customers: List<Customer>) {
        customersProperty.setAll(customers)
    }
Something like this
Also note that you should make all fetchings eager because you don't want to make database calls on the FX Thread.
m
@bkenn Hello, The edit function isn't working, error : org.springframework.orm.jpa.JpaSystemException: Exception occurred inside setter of com.github.bkenn.jpafx.model.Vendor.customers; nested exception is org.hibernate.PropertyAccessException: Exception occurred inside setter of com.github.bkenn.jpafx.model.Vendor.customers
Did you see that?
b
Actually yeah. I do. I didn't test for updates. Doing it now.
Strange behavior. When I wrap the
this.customers.setAll(customers)
, inside the
setCustomers
, in a try-catch, I receive a
java.lang.UnsupportedOperationException: Operation is not supported for read-only collection
I am going to try plain java
Ok I think I have a solution. My update test has passed.
I am going to try some types of updates
Until I am better acquainted with Hibernate's logic, here is one solution I found a way to update a @OneToMany relationship. We have to remove the
CascadeType.ALL
from `Vendor`'s
customers
. Then we have to save the customer entity before we add the
customer
to the pre-saved
vendor
and then we can save the
vendor
.
m
Ok, I am go see