'Query after save works in Hibernate 3 but not in Hibernate 5.1.2
I have this code who is working in Hibernate 3 but not working in Hibernate 5.1.2 any more. I am not sure why? I debug and session has inside in both version the object but in Hibernate 3 the list is length 1 and in version 5.1.2 is 0. Do you know why? Thank you
@Table( name = "EMPLOYEE" )
public class Employee{
public Employee(String SSN){
socialSecurityNumber = SSN;
}
/* Primary key */
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequence-generator")
protected long id;
@Column(nullable = false, unique = true)
private long socialSecurityNumber;
}
method of test:
@Test
public void testEmployee() throws Exception {
long intId = new EmployeeIdSequence().newLong();
Employee emp = new Employee(intId);
session.save(emp);
@SuppressWarnings("rawtypes")
Employee emp2;
Query query = session.createQuery("FROM EMPLOYEE WHERE socialSecurityNumber = :socialSecurityNumber");
query.setParameter("socialSecurityNumber", new Long(intId), LongType.INSTANCE);
List<Employee> queryList = query.setHibernateFlushMode(FlushMode.MANUAL).list();
if (queryList.size() == 1) {
emp2 = queryList.get(0);
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
