error no hibernate session bound to thread

Ngoding hibernate dan spring dapat error begini

SEVERE: >>org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
Tambahkan @Transaction pada method yang terjadi error

SEVERE: >>org.hibernate.QueryException: Not all named parameters have been set: [noMesin] [from StockRinci a where a.noMesin = :noMesin]

Awalnya coding query seperti ini :

@Transactional
public StokRinci findByNomesin(String noMesin) {
String stringQuery = "from StokRinci a where a.noMesin = :noMesin";
Query query = getHibernateTemplate().getSessionFactory().getCurrentSession().createQuery(stringQuery);

StokRinci st = (StokRinci) query.uniqueResult();
return st;
}

ya iya lah error🙂 ,, kan di stringQuery mendifinisikan parameter tp pada object query kok ga dikasih parameter ,

OK bos,, saya tambahkan parameter ini aja

query.setParameter("noMesin", noMesin);
@Transactional
public StokRinci findByNomesin(String noMesin) {
String stringQuery = "from StokRinci a where a.noMesin = :noMesin";
Query query = getHibernateTemplate().getSessionFactory().getCurrentSession().createQuery(stringQuery);
query.setParameter("noMesin", noMesin);
StokRinci st = (StokRinci) query.uniqueResult();
return st;
}

Ops ,, beres ternyata🙂

Alhamdulillah.

Published by

saifiahmada

Begin a big Process with a bit trying

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s