Home >Java >javaTutorial >Why am I getting \'Could not determine type for: java.util.List\' when using Hibernate\'s @OneToMany annotation?
Problem:
When using Hibernate for data operations, you encounter the error "Could not determine type for: java.util.List." This occurs while defining a One-To-Many relationship between College and Student entities using @OneToMany and @ManyToOne annotations.
Background:
The error arises because Hibernate is unable to determine the type of the collection (List
Solution:
To resolve the error, modify the @OneToMany annotation in the College class to be applied directly to the field instead of the getter method. Here's the corrected code:
<code class="java">// College.java @Entity public class College { @Id @GeneratedValue(strategy=GenerationType.AUTO) private int collegeId; private String collegeName; @OneToMany(targetEntity=Student.class, mappedBy="college", fetch=FetchType.EAGER) private List<Student> students; // Other getters and setters omitted }</code>
Additional Considerations:
The above is the detailed content of Why am I getting \'Could not determine type for: java.util.List\' when using Hibernate\'s @OneToMany annotation?. For more information, please follow other related articles on the PHP Chinese website!