Here is my function:
private boolean CheckPassword(String type, String login, String passwordHash) {
EntityManagerFactory entityManagerFactory
= Persistence.createEntityManagerFactory("kwestionariuszFor" + type);
EntityManager entityManager
= entityManagerFactory.createEntityManager();
type = type.substring(0, 1).toUpperCase() + type.substring(1, type.length());
List<Object> entities
= entityManager.createNamedQuery(type + ".findByLogin").setParameter("login", login).getResultList();
if (passwordHash.equals(entities.get(0).Password)) {
return true;
}
else {
return false;
}
}
The Java doesn’t “know” that there IS Password column in any of the tables. I was thinking that the way to tell it so may look like this:
List<type.toClass()>
or something… is there any way to achieve what I want? I don’t want to create if, after if, after if… -_-‘
You must create a common type for all of your classes that represent database tables.
Like this:
I don’t know if the method
createNamedQuerywould be able to return aList<PassowrdObject>, but if not, you can just cast it like this (as long as it’s safe to do so, which you can only tell by the way you use it):