I'm just starting out with Spring / Hibernate, and I'm trying to understand how hibernate maps objects to tables. I am currently working with the following classes to test CRUD using sleep mode:
@Entity
@Table(name = "Users")
public class UserEntity implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
private String firstName;
private String lastName;
private int age;
}
@Repository
public class UserDAOImpl implements UserDAO {
@Autowired
HibernateTemplate hibernateTemplate;
@Override
public UserEntity getUser(String firstName, String lastName) {
List<UserEntity> users = hibernateTemplate.find("from UserEntity u where u.firstName = ? and u.lastName = ?", firstName, lastName);
return (users.size() == 0 ? null : users.get(0));
}
@Override
public void saveOrUpdate(UserEntity user) {
hibernateTemplate.saveOrUpdate(user);
}
}
The code above works fine, but I'm confused about how UserEntity maps to a table. More specifically, when hibernateTemplate.find("from UserEntity u where u.firstName = ? and u.lastName = ?", firstName, lastName)I call, I get the following message in the log:
Hibernate: select userentity0_.id as id0_, userentity0_.age as age0_, userentity0_.firstName as firstName0_, userentity0_.lastName as lastName0_ from Users userentity0_ where userentity0_.firstName=? and userentity0_.lastName=?
When hibernateTemplate.find()I call, I need to specify the UserEntity table , while the log reports a query for the Users table (as I indicated in the @Table annotation).
UserEntity , UserEntity. ? , HQL SQL-?