Hi currently i'm trying to use the persistence api. I stuck at inserting a one to many relationship. The problem is that the foreign key is always null. I have two entity classes. User and Option. User
Option
The Option Objects are created from strings by a converter from a p:selectManyCheckbox. The field user_fk is not set manually in this converter because i don't have a reference to the User object in the converter. Xpert.ivy creates an entity class for User and adds a "setOpts(List)" method for me.
If there where a "addOpt(Option) method I could add the reference to User myself.
Am I thinking wrong or is it not possible to automate the creation of foreign keys? Best Regards Harald asked 26.03.2014 at 10:25 HaraldWeber |
I used a script step and called ivy.persistence.persistence.persist(in.user); My database looks like this:
I think the problem is how I create new Items for the opts list in the user class.
In the view i have a selectManyCheckbox:
The con.OptionConverter creates one option object from the given string.
There should also be something like option.setUser_fk(user); so the reference from User to Option is set. This is not possible in the converter because there is no reference to the User object. The only way to set the reference of User in Option is in the User Entity Class where the list is set (or built up). But the generated code only sets the list with empty references to User. So the persistence api can't know their connection. Maybe I'm thinking wrong and build the example wrong but without the references set the persistence api will never set the keys. Best Regards Harald answered 31.03.2014 at 09:19 HaraldWeber Now I set the reference of User ins Option myself and it is working now.
(02.04.2014 at 12:37)
HaraldWeber
|
Hi Harald, did you try to persist the dataclass? ivy.persistence.xyz.persist(User); as i know the keys are set within the database server. in our case we used MSSQL and the keys are set by MSSQL table settings. Best regards Roland answered 27.03.2014 at 20:13 roland |
Once you sign in you will be able to subscribe for any updates here
By RSS:Markdown Basics
Tags:
Asked: 26.03.2014 at 10:25
Seen: 2,677 times
Last updated: 02.04.2014 at 12:37