Reputation: 1
Hibernate throws a strange error
Hibernate: select user0_.userID as userID0_, user0_.password as password0_ from user user0_ where user0_.userID='admin' and user0_.password='admin' org.hibernate.hql.ast.QuerySyntaxException: action is not mapped [from action where id = 'MADEX240214'] at org.hibernate.hql.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:181) at org.hibernate.hql.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:110)
is there anything wrong with my code ?
public String insertActions(ArrayList<Action> data , String[] check)
{
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
Query query = null;
try
{
for (int i = 0; i < data.size(); i++)
{
if(check[i].compareTo("Update")==0)
{
query = session.createQuery("update Action set Last = :Last ,"
+ " Adjusted_Last =:Adjusted_Last where idAction = :idAction");
query.setDouble("Last", data.get(i).getLast());
query.setDouble("Adjusted_Last", data.get(i).getAdjustLast());
query.setParameter("idAction", data.get(i).getIdAction());
int result = query.executeUpdate();
}
else
{
session.save(data.get(i));
}
}
}
catch (HibernateException e)
{
e.printStackTrace();
session.getTransaction().rollback();
return "ERROR";
}
session.getTransaction().commit();
return "SUCCESS";
}
Upvotes: 0
Views: 174
Reputation: 87
starting from Hibernate 5.1 we have to write HibernateUtil in such manner
public class HibernateUtil {
private static final SessionFactory SESSION_FACTORY;
static{
try {
StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().configure().build();
SESSION_FACTORY = new MetadataSources(serviceRegistry).buildMetadata().buildSessionFactory();
} catch (Exception e) {
throw new ExceptionInInitializerError(e);
}
}
public static Session openSession() {
return SESSION_FACTORY.openSession();
}
}
Upvotes: 1
Reputation: 691
What's the full stack trace? It doesn't appear to come from that section of code. The error is on a select from 'action', not update.
I notice in your update statement, you reference the table as 'Action'. HQL queries are case sensitive. Check your mappings. 'action' != 'Action'
Upvotes: 0