@Override
public LinkedHashSet <String> listHotels() {
Query query = em.createNativeQuery("select * from Hotel");
LinkedHashSet <String> hotel= query.getResultList();
return hotel;
}
I am getting a Warning saying incompatible types. query.getResultList(); returns a List
, but what I want the method to return is a LinkedHashSet
.
The reason why I'm using a LinkedHashSet
here, is to avoid duplicate values being entered to the DB. I will call the method listHotels()
first, and check if it has already contains the value and if doesn't I'll save the values to the DB
EDIT
public void saveHotel(Hotel hotel) {
if (hotel.getId() ==null){
em.persist(hotel);
} else {
em.merge(hotel);
}
}
THis is how i save records to my DB
You can not map a List to a Set. If you just want to eliminate duplicate then you can do so using your DB query