0

I just started learning Spring and Hibernate and I was trying to do some practice, but I met some problems. The basic structure is sample, like this. enter image description here

However, I met a problem with UnsatisfiedDependencyException:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'administratorController': Unsatisfied dependency expressed through field 'userService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userServiceImpl': Unsatisfied dependency expressed through field 'userDAO'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userDAOImpl': Unsatisfied dependency expressed through field 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/spring-mvc-school-management-sys-servlet.xml]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: com.demo.schoolmanagementsystem.entity.Users.users in com.demo.schoolmanagementsystem.entity.Institution.users

The code I have done is in this Link: https://github.com/LehTia/schoolmanagementsystem. I had looked it all day but I could not find it. Can anyone take a quick look what I had done and tell me where went wrong?

Any help will be appreciated. Thx a lot.

Lemmy
  • 2,437
  • 1
  • 22
  • 30
Lehtia
  • 159
  • 1
  • 3
  • 12

1 Answers1

1

The issue is with mappedBy property, you set property "users" which is not correct. In your case you should use:

@OneToMany(fetch=FetchType.LAZY,
            mappedBy="institution",
            cascade={CascadeType.DETACH, CascadeType.MERGE,CascadeType.PERSIST, CascadeType.REFRESH})
private List<Users> users;

Even you are making the relation between two tables only one of those tables has a foreign key constraint to the other one. "MappedBy allows you to still link from the table not containing the constraint to the other table." Please read Can someone please explain mappedBy in hibernate? and http://www.baeldung.com/hibernate-one-to-many

Lemmy
  • 2,437
  • 1
  • 22
  • 30