Home > Back-end >  Java entity class reference properties do not agree with the field type in the database of the probl
Java entity class reference properties do not agree with the field type in the database of the probl

Time:02-20

Beginners Java, write a try demo met headaches,

Two table with employee and department, department for a new employee, so I joined the department in the empolyee entity class types of attributes, but can't put objects in the database table, the employee table into the departemntid to identify subordinate departments,
Want to add a new Employee, so he wrote a instance of Employee instance with Deaprtment inside department, want to take this department objects into corresponding departmentid field in the Employee table, so I mapper XML statement wrote

Insert into mybatis. The employee (` lastName `, ` email `, ` gender `, ` dpartmentid `, ` birth `)
The value (# # {lastName}, {email}, # {gender}, # {department. GetId ()} , # {birth. The toString ()});

I think this is feasible, the run times wrong: There is no getter for property named 'getId ()' in 'class com. Wt. Pojo. Department'
Carefully check my this getter some ah, that affirmation is mybatis don't let such use,,
Thought for a few hours, check didn't find a lot of similar problem, want to come out a clumsy solution: object to the service layer and the service attributes of the objects one by one into the corresponding fields in the database type,, but it's too stupid,,
Please comment,
  • Related