In the example of customer banking, how can we not proceed? The following error occurs:Object type cannot be converted to target type.
What I want to do is: I have slightly changed the requirements. The customer and bank are no longer one-to-one, but one-to-one.
In the configuration file, change it:
Customer. HBM. xml
<Bag name = "customerbanks"
Cascade = "all"
Order-by = "bankname ASC">
<Key column = "customerid"/>
<One-to-operate class = "data. Bank, data"/>
</Bag>
Bank. HBM. xml
<Role-to-one name = "bankcustomer" class = "data. Customer, data"
Cascade = "all" outer-join = "Auto"
Column = "customerid"
Not-null = "false"/>
Detailed configuration files, domain model, and DB model are downloaded here!
Then I want to insert the bank at the same time when inserting the customer. The implementation code is as follows:
Customer acustomer = new customer ();
Acustomer. customertitle = "Developer ";
Acustomer. customerage = 25;
Acustomer. updatetimestamp = datetime. now;
Bank abank = New Bank ();
Abank. bankname = "CICB ";
Abank. banlance = 1233453.234 m;
Abank. updatetimestamp = acustomer. updatetimestamp;
// Bind the two object to each other.
Abank. bankcustomer = acustomer;
Acustomer. customerbanks. Add (abank );
Aentityrule. Save (acustomer );
Why is an error,
Object type cannot be converted to target type.
I used SQL profile to check and found that no SQL statements were generated at all. Please give me some advice on what went wrong.