Inserting data into table with the referance of second table using mysql
I have two tables 1 is "contact_info" - having fields like (owner_id, contact_type, contact_value), another one is "contact" -having fields like (id, f_name, l_name, email). Now i want to insert into contact_info with the reference from table contact- id.
I am using code as below...
//=======Contact.开发者_StackOverflow社区xml============//
<insert id="insert_con_info" parameterClass="Contact">
INSERT INTO CONTACT_INFO(OWNER_ID, CONTACT_TYPE, CONTACT_VALUE)
VALUES((SELECT ID FROM CONTACT WHERE ID=#id#), #contact_type#, #contact_value#);
</insert>
And Main Class contain code as below...
Contact con = new Contact(2,"Office", 12345678);
sqlMap.insert("Contact.insert_con_info", con);
But it throws exception like
"There is no READABLE property named 'contact_type' in class 'Contact'"
please give me suggestion if possible
Thanks in Advance...
Try:
<insert id="insert_con_info" parameterClass="Contact">
INSERT INTO CONTACT_INFO(OWNER_ID, CONTACT_TYPE, CONTACT_VALUE)
SELECT ID, #contact_type#, #contact_value# FROM CONTACT WHERE ID=#id#;
</insert>
精彩评论