Collection has neither generic type or OneToMany.targetEntity() defined

Exception

org.hibernate.AnnotationException: Collection has neither generic type or OneToMany.targetEntity() defined:

I am getting following Exception

Initial SessionFactory creation failed.org.hibernate.AnnotationException: Collection has neither generic type or OneToMany.targetEntity() defined: com.kruders.bean.Employee.employees
java.lang.ExceptionInInitializerError
    at com.kruders.bean.Main.<clinit>(Main.java:21)
Caused by: org.hibernate.AnnotationException: Collection has neither generic type or OneToMany.targetEntity() defined: com.kruders.bean.Employee.employees
    at org.hibernate.cfg.annotations.CollectionBinder.getCollectionType(CollectionBinder.java:621)
    at org.hibernate.cfg.annotations.CollectionBinder.bind(CollectionBinder.java:509)
    at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:1979)
    at org.hibernate.cfg.AnnotationBinder.processIdPropertiesIfNotAlready(AnnotationBinder.java:796)
    at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:707)
    at org.hibernate.cfg.Configuration$MetadataSourceQueue.processAnnotatedClassesQueue(Configuration.java:4008)
    at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3962)
    at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1371)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1829)
    at com.kruders.bean.Main.<clinit>(Main.java:18)
Exception in thread "main"

Solution

Hibernate must know what type of object is in a Set, so add custom parametrized class in Set as shown below.

private Set employees; //Exception
private Set<Employee> employees; //Works Fine

,

One Response to Collection has neither generic type or OneToMany.targetEntity() defined