I’m not sure of what your trying to do, but many things seem wrong with your query.
First, using SELECT #{xyz} seems wrong since you probably want the content of your Employee/Address tables as values to insert.
Second, it’s impossible to resolve the property of a list using the dot notation. So employee.empNumber is impossible since employee is a list and lists don’t have a empNumber property. You may wish to use <foreach> tag as defined here: http://www.mybatis.org/core/dynamic-sql.html
Look at this example:
http://www.mybatis.org/core/sqlmap-xml.html#insert_update_and_delete
<insert id="insertAuthor" parameterType="domain.blog.Author">
insert into Author (id,username,password,email,bio)
values (#{id},#{username},#{password},#{email},#{bio})
</insert>
Christian
De : mybati...@googlegroups.com [mailto:mybati...@googlegroups.com] De la part de PP
Envoyé : November-14-12 11:15 PM
À : mybati...@googlegroups.com
Objet : ### Error updating database. Cause: org.apache.ibatis.reflection.ReflectionException - iBatis
Hi All,
When i run insert query through unit testing,i get below exception
org.apache.ibatis.exceptions.IbatisException: ### Error updating database. Cause: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'empNumber' in 'class java.util.ArrayList'### The error may involve WorkplaceDetail.insertWorkplace-Inline### The error occurred while setting parameters### Cause: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'empNumber' in 'class java.util.ArrayList' at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:8) at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:100)Below is my configuration of workplace.xml where i have highlighted insert statement.
<insert id="insertWorkplace" parameterType ="WorkplaceDetail" useGeneratedKeys="true"> <selectKey resultType="int" keyProperty="code" order="BEFORE"> select last_insert_rowId() as code </selectKey> INSERT INTO Workplace (WRegNum,WorkplaceName,EmpNumber,AddressId,notes1) SELECT #{compRegNum}, #{plant}, #{employee.empNumber}, #{address.addressId}, #{note1} FROM Workplaceinner join Employee on (Workplace.[EmpNumber]={employee.empNumber})inner join Address on (Workplace.[AddressID]= #{address.addressId});</insert>
<resultMap id="workplaceResult" type="WorkplaceDetail"> <id property="code" column="WorkplaceCode" jdbcType="INTEGER"/> <result property="compRegNum" column="WRegNum" jdbcType="VARCHAR"/> <result property="plant" column="WorkplaceName" jdbcType="VARCHAR"/> <result property="note5" column="Notes5" jdbcType="VARCHAR"/> <association property="address" column="WorkplaceCode" javaType="Address"> <id property="addressId" column="Address_id" jdbcType="INTEGER"/> </association> <collection property="employee" column="WorkplaceCode" javaType="ArrayList" ofType="Employee"> <id property="empNumber" column="EmpNum" jdbcType="INTEGER"/> <result property="empName" column="EmpName" jdbcType="VARCHAR"/> </collection></resultMap>Workplace.java (POJO)
public class WorkplaceDetail{private int code;private String plant;private String compRegNum;private List <Employee> employee = new ArrayList<Employee>();private Address address;}Please help me out to resolve this issue.
CompanyName , EmployeeName, Address
Oracle, Guy c-102, New jersy