我只想在我的hibernate实体中执行一对一映射。我面临一个奇怪的问题,我在谷歌搜索了很多但没有找到任何解决方案。以下是我的实体和课程。
JobAlertsEntity.java
@Entity
@Table(name = "job_alerts")
public class JobAlertsEntity {
@Id
@GeneratedValue
@Column(name = "id")
private int id;
@Column(name = "job_id")
private int job_id;
@Column(name = "user_id")
private int user_id;
@Column(name = "sent_date")
private String sent_date;
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name="job_id", insertable = false, updatable = false)
private JobsEntity jobsEntity;
JobsEntity.java
@Entity
@Table(name = "employers_job")
public class JobsEntity {
@Id
@GeneratedValue
@Column(name = "job_id")
private int job_id;
@Column(name = "emp_name")
private String emp_name;
@Column(name = "designation")
private String designation;
@Column(name = "skills")
private String skills;
@Column(name = "job_description")
private String job_description;
@Column(name = "location")
private String location;
@Column(name = "experience")
private String experience;
@Column(name = "exp_from")
private String exp_from;
@Column(name = "exp_to")
private String exp_to;
@Column(name = "ctc")
private String ctc;
@Column(name = "func_area")
private String func_area;
@Column(name = "industry")
private String industry;
@Column(name = "postgrad")
private String postgrad;
@Column(name = "gender")
private String gender;
@Column(name = "contactno")
private String contactno;
@Column(name = "caddress")
private String caddress;
@Column(name = "date_of_posting")
private String date_of_posting;
@Column(name = "status")
private String status;
@Column(name = "job_expire_date")
private String job_expire_date;
@Column(name = "company_name")
private String company_name;
@Column(name = "company_desc")
private String company_desc;
@Column(name = "job_viewed")
private String job_viewed;
@Column(name = "email")
private String email;
这是我的代码: -
public List<Jobs> getAllJobAlerts(String jobseeker_id) {
Transaction transaction = null;
Session session = null;
List<Jobs> alerts = null;
try {
session = sessionFactory.openSession();
session.setFlushMode(FlushMode.COMMIT);
transaction = session.beginTransaction();
List<JobAlertsEntity> jobs_data = (List<JobAlertsEntity>) session.createQuery("from JobAlertsEntity je where je.user_id = "+jobseeker_id+"").list();
if(jobs_data != null) {
for(Iterator data = jobs_data.iterator(); data.hasNext();) {
JobAlertsEntity je = (JobAlertsEntity) data.next();
JobsEntity jo = je.getJobsEntity();
Jobs job = new Jobs();
job.setEmp_name(jo.getEmp_name());
alerts.add(job);
}
}
transaction.commit();
} catch (Exception e) {
e.printStackTrace();
transaction.rollback();
session.clear();
session.close();
}
return alerts;
}
每次出现此异常时都会收到: -
*org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is java.lang.StackOverflowError
org.springframework.web.servlet.DispatcherServlet.triggerAfterCompletionWithError(DispatcherServlet.java:1284)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:965)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:876)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852)
javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118)
org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:154)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:150)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.authentication.ui.DefaultLoginPageGeneratingFilter.doFilter(DefaultLoginPageGeneratingFilter.java:155)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:199)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:110)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:50)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:108)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)
org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:344)
org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:261)
root cause
java.lang.StackOverflowError
org.jobsdhamaka.serviceimpl.JobAlertsServiceImpl.getAllJobAlerts(JobAlertsServiceImpl.java:18)
org.jobsdhamaka.serviceimpl.JobAlertsServiceImpl.getAllJobAlerts(JobAlertsServiceImpl.java:18)
org.jobsdhamaka.serviceimpl.JobAlertsServiceImpl.getAllJobAlerts(JobAlertsServiceImpl.java:18)
org.jobsdhamaka.serviceimpl.JobAlertsServiceImpl.getAllJobAlerts(JobAlertsServiceImpl.java:18)*
请在我的代码中告诉我我做错了什么。