I am using below jars to run jpa program but am getting an exception:
hibernate-entitymanager-3.4.0.GA.jar
hibernate-annotations-3.4.0.GA.jar
hibernate-commons-annotations-3.3.0.ga.jar
hibernate-core-3.3.1.GA.jar
javax.persistence.jar
The exception is:
org.hibernate.AnnotationException: @Temporal should only be set on a java.util.Date or java.util.Calendar property: asso_attrib_overrides.FulltimeEmployee.currentProjects.
My entity:
@Entity
public class FulltimeEmployee extends Employee {
@ElementCollection
@CollectionTable(name="EMP_PROJECTS", joinColumns=@JoinColumn(name="MY_EMP_ID"))
@Temporal(TemporalType.DATE)
@MapKeyJoinColumn(name="THE_PROJECT_ID")
@Column(name="STARTDATE")
protected Map<Project, Date> currentProjects;
public Map<Project, Date> getCurrentProjects() {
return currentProjects;
}
public void setCurrentProjects(Map<Project, Date> currentProjects) {
this.currentProjects = currentProjects;
}
According tag you are using JPA 2.0. That is not exactly true, because 3.4 is JPA 1.0 implementation. Only Hibernate versions from 3.5.x on are implementations of JPA 2.0 API.
That causes problem, because concept of using @Temporal with ElementCollection was introduced in JPA 2.0. This error is not silently ignored, because @Temporal annotation existed already in earlier version, but usage was widened in JPA 2.0 to cover your usecase. Other annotations that exist only in later specification are silently ignored and that is also likely to cause problems.
What you can do is to update Hibernate to newer version, for example to 3.6.10. If you are creating new software, there is no migration issues, so it makes sense to update directly to 4.x.