Note that there are some explanatory texts on larger screens.

plurals
  1. POQuartz - While doing transaction in hibernate with spring, Exception occurs
    primarykey
    data
    text
    <p>I am coding one facebook application. Once user authorize my app @ fb, their landing page would be view-profile page. Though I pulling lots of data viz., likes, groups etc.. It takes lots of time to redirect him to landing page. So what I thought is, Just get user email ID, educational and employment details then redirect him to landing page. Mean gap I started a thread before redirection, which will pull all the data from his account in background. So I created a class which implements runnable, then I started that thread from controller. It works fine until I get the data from fb. While calling DAO's save(obj) method I am getting the following error.</p> <pre><code>org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here </code></pre> <p>One of my friend suggested me to go with quartz scheduler. So Here is what I tried.</p> <p><strong>FBController:</strong></p> <pre><code> SchedulerFactory sf = new StdSchedulerFactory(); Scheduler shed = null; try { shed = sf.getScheduler(); shed.start(); } catch (SchedulerException e) { e.printStackTrace(); } JobDetail jobDetail = new JobDetail("FB_Details", null, FacebookControllerHelper.class); jobDetail.getJobDataMap().put("Users", user); jobDetail.getJobDataMap().put("accessToken", accessToken); jobDetail.getJobDataMap().put("fbService", facebookService); jobDetail.getJobDataMap().put("OAuth", service); Trigger trigger = TriggerUtils.makeImmediateTrigger(0, 1); trigger.setName("FB_Details"); try { shed.scheduleJob(jobDetail, trigger); } catch (SchedulerException e) { System.out.println("Ended In Exception"); e.printStackTrace(); } </code></pre> <p><strong>FBControllerHelper:</strong></p> <pre><code>public class FacebookControllerHelper implements Job{ private Users users; private Token accessToken; private FacebookService facebookService; private OAuthService service; Gson gson = new Gson(); private static final String PROTECTED_RESOURCE_URL_LIKE = "https://graph.facebook.com/me?fields=likes.limit(1000).fields(id,name,description,website)"; public FacebookControllerHelper(){ } public void execute(JobExecutionContext context) throws JobExecutionException{ JobDataMap dataMap = context.getJobDetail().getJobDataMap(); users = (Users) dataMap.get("Users"); accessToken = (Token) dataMap.get("accessToken"); facebookService = (FacebookService) dataMap.get("fbService"); service = (OAuthService) dataMap.get("OAuth"); this.getUserLikes(accessToken, users); } @Transactional public void getUserLikes(Token accessToken, Users user){ System.out.println("Entering getUserLikes Method"); OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL_LIKE); service.signRequest(accessToken, request); Response response = request.send(); FBUserLikes fbuserLikes = gson.fromJson(response.getBody(), FBUserLikes.class); System.out.println(response.getBody()); facebookService.saveUserLikes(user, fbuserLikes); } } </code></pre> <p><code>response.getBody()</code> is printing what json it got from facbook. But while passing it to service, there I am calling DAO'S save() method. At that point I am getting the following error,</p> <pre><code>[ERROR] [DefaultQuartzScheduler_Worker-2] org.quartz.core.JobRunShell - Job DEFAULT.FB_Details threw an unhandled Exception: org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here </code></pre> <p>I googled my error and I got some solution, which doesn't suits my application. I am using spring 3.0.5 Version and quartz 1.8.6. And many blogs and similar results shows me how to run a cron job in a particular interval. But that is of no use for me. I would be grateful if some one help me out to solve this issue. Hope my question is clear.</p> <p>Thankyou in Advance.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload