I am using OpenSessionInView pattern for hibernate sessions.
Issue: In City table, I want to make sure there is no duplicate entry. I read cities data from a file and use saveOrUpdate()/Save() in a single session to save data in the table.The file can have duplicate city names.
The primary key of the City table is ID. Before creatig new City entity, i do a query (Criterion) to check if there is a city by the name in the table. This query always return null even if a new City entity object has been created and READY to be saved in datadabe. Thats so beacuse entities have not been flushed yet.(it happens on session close).
So I end up having duplicate city names in the table.
I do see that session(before flushed) holds all City entities I created. So I want to get all city objects from session. I know I can get ONE using session.get(City.class,ID) but this is NOT what i want. since I do not know the ID. I know descripton( which I can not use, since It should be serializable ID).