I got exception
Code:
org.springframework.orm.hibernate3.HibernateSystemException: Provided id of the wrong type. Expected: class java.lang.Long, got class java.lang.Integer; nested exception is org.hibernate.TypeMismatchException: Provided id of the wrong type. Expected: class java.lang.Long, got class java.lang.Integer
at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:679)
at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:411)
at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
at org.springframework.orm.hibernate3.HibernateTemplate.loadAll(HibernateTemplate.java:584)
at tour.spring.bc.dao.impl.AbstractHibernateDAOImpl.loadAll(AbstractHibernateDAOImpl.java:55)
at tour.spring.bc.bo.impl.TourBoImpl.queryAll(TourBoImpl.java:27)
at tour.spring.bc.bo.TourBoTest.testQueryAll(TourBoTest.java:31)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:82)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:240)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:180)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.hibernate.TypeMismatchException: Provided id of the wrong type. Expected: class java.lang.Long, got class java.lang.Integer
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:86)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:879)
at org.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:847)
at org.hibernate.type.AnyType.resolveAny(AnyType.java:111)
at org.hibernate.type.AnyType.resolve(AnyType.java:101)
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:120)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:854)
at org.hibernate.loader.Loader.doQuery(Loader.java:729)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.doList(Loader.java:2217)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2108)
at org.hibernate.loader.Loader.list(Loader.java:2103)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:94)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1570)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
at org.springframework.orm.hibernate3.HibernateTemplate$5.doInHibernate(HibernateTemplate.java:590)
at org.springframework.orm.hibernate3.HibernateTemplate$5.doInHibernate(HibernateTemplate.java:1)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:406)
... 34 more
Tour.java
Code:
@Entity
public class Tour {
private long id;
private int placeQuantity;
private Date dateFrom;
private Date dateTo;
private Hotel hotel;
private List<FoodType> foodType;
private List<Room> rooms;
@ManyToMany
@JoinTable(name = "TourFoodType",
joinColumns = @JoinColumn(name = "tour_id"),
inverseJoinColumns = @JoinColumn(name = "foodtype_id"))
public List<FoodType> getFoodType() {
return foodType;
}
public void setFoodType(List<FoodType> foodType) {
this.foodType = foodType;
}
@Column(name="place_quantity")
public int getPlaceQuantity() {
return placeQuantity;
}
public void setPlaceQuantity(int placeQuantity) {
this.placeQuantity = placeQuantity;
}
@Column(name="date_from")
public Date getDateFrom() {
return dateFrom;
}
public void setDateFrom(Date dateFrom) {
this.dateFrom = dateFrom;
}
@Column(name="date_to")
public Date getDateTo() {
return dateTo;
}
public void setDateTo(Date dateTo) {
this.dateTo = dateTo;
}
@ManyToOne
@JoinColumn(name="hotel_id")
public Hotel getHotel() {
return hotel;
}
public void setHotel(Hotel hotel) {
this.hotel = hotel;
}
@ManyToMany
@JoinTable(name = "TourRoom",
joinColumns = @JoinColumn(name = "tour_id"),
inverseJoinColumns = @JoinColumn(name = "room_id"))
public List<Room> getRooms() {
return rooms;
}
public void setRooms(List<Room> rooms) {
this.rooms = rooms;
}
@Column
@Id
@SequenceGenerator(name="tour_seq", sequenceName="tour_seq")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator="tour_seq")
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
}
TourDaoImpl.java
Code:
@Repository
public class TourDaoImpl extends AbstractHibernateDAOImpl<Tour> implements TourDao{
public TourDaoImpl() {
super(Tour.class);
}
}
AbstractHibernateDAOImpl.java
Code:
public class AbstractHibernateDAOImpl<E> implements AbstractHibernateDAO<E> {
private HibernateTemplate hibernateTemplate;
private final Class<E> entityClass;
public AbstractHibernateDAOImpl(final Class<E> aEntityClass) {
this.entityClass = aEntityClass;
hibernateTemplate = new HibernateTemplate();
}
@Autowired
public void setSessionFactory(SessionFactory sessionFactory) {
hibernateTemplate.setSessionFactory(sessionFactory);
}
public HibernateTemplate getHibernateTemplate() {
return hibernateTemplate;
}
public Class<E> getEntityClass() {
return entityClass;
}
public List<E> loadAll() {
return hibernateTemplate.loadAll(entityClass);
}
}
TourBoImpl.java
Code:
@Service
public class TourBoImpl implements TourBo {
@Autowired
private TourDao tourDao;
@Autowired
private TourAssembler tourAssembler;
public Collection<TourDto> queryAll() {
return tourAssembler.convertToDto(tourDao.loadAll());
}
}
Why calling hibernateTemaplate.loadAll(entityClass) causes exception? ID of Tour is long so where is the problem?