user2991030 user2991030 - 3 months ago 10
Java Question

How to mapping two table (one to many )using hibernate annotation + Spring MVC

1.I am using spring mvc + Hibernate
2.I implement a project using two table it has one to many mapping,it is working very well
3.then i wanted to use another 2 tables they also have one to many .is fallowed my same scenario for that..but give a Error,it seems to be configure Error,i am new for that any one can help me

This is my MODEL## (MeetingTypes and Meetings has 1 to many)

package pearson.dashboard.model;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;



@Entity
public class MeetingTypes {
@Id
@Column
@GeneratedValue(strategy=GenerationType.AUTO)
private int meetingTypeID;
@Column
private String typeName;
@OneToMany(mappedBy = "meetingTypes",fetch = FetchType.EAGER)

private List<Meetings> meetings;
public List<Meetings> getMeetings() {
return meetings;
}

public void setMeetings(List<Meetings> meetings) {
this.meetings = meetings;
}

public MeetingTypes() {

// TODO Auto-generated constructor stub
}

public MeetingTypes(int meetingTypeID, String typeName
) {
super();
this.meetingTypeID = meetingTypeID;
this.typeName = typeName;

}

public int getMeetingTypeID() {
return meetingTypeID;
}

public void setMeetingTypeID(int meetingTypeID) {
this.meetingTypeID = meetingTypeID;
}

public String getTypeName() {
return typeName;
}

public void setTypeName(String typeName) {
this.typeName = typeName;
}





}


#

package pearson.dashboard.model;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;

@Entity
public class Meetings {
@Id
@Column
@GeneratedValue(strategy=GenerationType.AUTO)
private int meetingID;
@Column
private Date sheduleTime;
@Column
private String meetingHeading;
@Column
private String comment;
@Column
private String roomName;

@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "meetingTypeID")

private MeetingTypes meetingTypes;

public MeetingTypes getMeetingTypes() {
return meetingTypes;
}

public void setMeetingTypes(MeetingTypes meetingTypes) {
this.meetingTypes = meetingTypes;
}

public Meetings() {

// TODO Auto-generated constructor stub
}

public Meetings(int meetingID, Date sheduleTime, String meetingHeading,
String comment, String roomName) {
super();
this.meetingID = meetingID;
this.sheduleTime = sheduleTime;
this.meetingHeading = meetingHeading;
this.comment = comment;
this.roomName = roomName;

}

public int getMeetingID() {
return meetingID;
}

public void setMeetingID(int meetingID) {
this.meetingID = meetingID;
}

public Date getSheduleTime() {
return sheduleTime;
}

public void setSheduleTime(Date sheduleTime) {
this.sheduleTime = sheduleTime;
}

public String getMeetingHeading() {
return meetingHeading;
}

public void setMeetingHeading(String meetingHeading) {
this.meetingHeading = meetingHeading;
}

public String getComment() {
return comment;
}

public void setComment(String comment) {
this.comment = comment;
}

public String getRoomName() {
return roomName;
}

public void setRoomName(String roomName) {
this.roomName = roomName;
}




}


This part of controller##

@Controller
public class MeetingTypesController {
@Autowired
private MeetingTypeService meetingTypeService;
@Autowired
private MeetingService meetingService;
@RequestMapping("/detailsPage")
public String getAllmeeting(Map<String, Object> map){
map.put("meetingList", meetingTypeService.getAllMeetingTypes());

return "details";

}


This my part of DAO##

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import pearson.dashboard.dao.MeetingTypeDao;

@Transactional
@Repository
public class MeetingTypeDaoImpl implements MeetingTypeDao {
@Autowired
private SessionFactory sessionFactory;


public List getAllMeetingTypes() {
// TODO Auto-generated method stub
return sessionFactory.getCurrentSession().createQuery("from MeetingTypes").list();
}

}


this VIEW in JSP ##()
when i run only fist for reach it is working,but when i run both it give bellow Error..the thing is this the way i did previously ..it worked

<c:forEach items="${meetingList}" var="meetingType">

<td> This from MeetingTypes: ${meetingType.typeName}</td>

<c:forEach items="meetingType.Meetings" var="meet">

<td> This from Meetings: ${meet.roomName} </td>
</c:forEach>
</c:forEach>


This is My Error##

Hibernate: select teams0_.teamID as teamID0_, teams0_.name as name0_ from Teams teams0_
Hibernate: select releases0_.teamID as teamID0_1_, releases0_.releaseID as releaseID1_, releases0_.releaseID as releaseID1_0_, releases0_.cabCall as cabCall1_0_, releases0_.orcleCode as orcleCode1_0_, releases0_.prodDate as prodDate1_0_, releases0_.releaseName as releaseN5_1_0_, releases0_.remarks as remarks1_0_, releases0_.rrr as rrr1_0_, releases0_.staging as staging1_0_, releases0_.status as status1_0_, releases0_.teamID as teamID1_0_ from Releases releases0_ where releases0_.teamID=?
Hibernate: select releases0_.teamID as teamID0_1_, releases0_.releaseID as releaseID1_, releases0_.releaseID as releaseID1_0_, releases0_.cabCall as cabCall1_0_, releases0_.orcleCode as orcleCode1_0_, releases0_.prodDate as prodDate1_0_, releases0_.releaseName as releaseN5_1_0_, releases0_.remarks as remarks1_0_, releases0_.rrr as rrr1_0_, releases0_.staging as staging1_0_, releases0_.status as status1_0_, releases0_.teamID as teamID1_0_ from Releases releases0_ where releases0_.teamID=?
Hibernate: select releases0_.teamID as teamID0_1_, releases0_.releaseID as releaseID1_, releases0_.releaseID as releaseID1_0_, releases0_.cabCall as cabCall1_0_, releases0_.orcleCode as orcleCode1_0_, releases0_.prodDate as prodDate1_0_, releases0_.releaseName as releaseN5_1_0_, releases0_.remarks as remarks1_0_, releases0_.rrr as rrr1_0_, releases0_.staging as staging1_0_, releases0_.status as status1_0_, releases0_.teamID as teamID1_0_ from Releases releases0_ where releases0_.teamID=?
Hibernate: select releases0_.teamID as teamID0_1_, releases0_.releaseID as releaseID1_, releases0_.releaseID as releaseID1_0_, releases0_.cabCall as cabCall1_0_, releases0_.orcleCode as orcleCode1_0_, releases0_.prodDate as prodDate1_0_, releases0_.releaseName as releaseN5_1_0_, releases0_.remarks as remarks1_0_, releases0_.rrr as rrr1_0_, releases0_.staging as staging1_0_, releases0_.status as status1_0_, releases0_.teamID as teamID1_0_ from Releases releases0_ where releases0_.teamID=?
Hibernate: select releases0_.teamID as teamID0_1_, releases0_.releaseID as releaseID1_, releases0_.releaseID as releaseID1_0_, releases0_.cabCall as cabCall1_0_, releases0_.orcleCode as orcleCode1_0_, releases0_.prodDate as prodDate1_0_, releases0_.releaseName as releaseN5_1_0_, releases0_.remarks as remarks1_0_, releases0_.rrr as rrr1_0_, releases0_.staging as staging1_0_, releases0_.status as status1_0_, releases0_.teamID as teamID1_0_ from Releases releases0_ where releases0_.teamID=?
Hibernate: select releases0_.teamID as teamID0_1_, releases0_.releaseID as releaseID1_, releases0_.releaseID as releaseID1_0_, releases0_.cabCall as cabCall1_0_, releases0_.orcleCode as orcleCode1_0_, releases0_.prodDate as prodDate1_0_, releases0_.releaseName as releaseN5_1_0_, releases0_.remarks as remarks1_0_, releases0_.rrr as rrr1_0_, releases0_.staging as staging1_0_, releases0_.status as status1_0_, releases0_.teamID as teamID1_0_ from Releases releases0_ where releases0_.teamID=?
Hibernate: select releases0_.teamID as teamID0_1_, releases0_.releaseID as releaseID1_, releases0_.releaseID as releaseID1_0_, releases0_.cabCall as cabCall1_0_, releases0_.orcleCode as orcleCode1_0_, releases0_.prodDate as prodDate1_0_, releases0_.releaseName as releaseN5_1_0_, releases0_.remarks as remarks1_0_, releases0_.rrr as rrr1_0_, releases0_.staging as staging1_0_, releases0_.status as status1_0_, releases0_.teamID as teamID1_0_ from Releases releases0_ where releases0_.teamID=?
Hibernate: select releases0_.teamID as teamID0_1_, releases0_.releaseID as releaseID1_, releases0_.releaseID as releaseID1_0_, releases0_.cabCall as cabCall1_0_, releases0_.orcleCode as orcleCode1_0_, releases0_.prodDate as prodDate1_0_, releases0_.releaseName as releaseN5_1_0_, releases0_.remarks as remarks1_0_, releases0_.rrr as rrr1_0_, releases0_.staging as staging1_0_, releases0_.status as status1_0_, releases0_.teamID as teamID1_0_ from Releases releases0_ where releases0_.teamID=?
Hibernate: select meetingtyp0_.meetingTypeID as meetingT1_2_, meetingtyp0_.typeName as typeName2_ from MeetingTypes meetingtyp0_
Hibernate: select meetings0_.meetingTypeID as meetingT6_2_1_, meetings0_.meetingID as meetingID1_, meetings0_.meetingID as meetingID3_0_, meetings0_.comment as comment3_0_, meetings0_.meetingHeading as meetingH3_3_0_, meetings0_.meetingTypeID as meetingT6_3_0_, meetings0_.roomName as roomName3_0_, meetings0_.sheduleTime as sheduleT5_3_0_ from Meetings meetings0_ where meetings0_.meetingTypeID=?
Hibernate: select meetings0_.meetingTypeID as meetingT6_2_1_, meetings0_.meetingID as meetingID1_, meetings0_.meetingID as meetingID3_0_, meetings0_.comment as comment3_0_, meetings0_.meetingHeading as meetingH3_3_0_, meetings0_.meetingTypeID as meetingT6_3_0_, meetings0_.roomName as roomName3_0_, meetings0_.sheduleTime as sheduleT5_3_0_ from Meetings meetings0_ where meetings0_.meetingTypeID=?
Nov 21, 2013 7:34:07 PM org.apache.catalina.core.ApplicationDispatcher invoke
SEVERE: Servlet.service() for servlet jsp threw exception
javax.el.PropertyNotFoundException: Property 'roomName' not found on type java.lang.String
at javax.el.BeanELResolver$BeanProperties.get(BeanELResolver.java:237)
at javax.el.BeanELResolver$BeanProperties.access$400(BeanELResolver.java:214)
at javax.el.BeanELResolver.property(BeanELResolver.java:325)
at javax.el.BeanELResolver.getValue(BeanELResolver.java:85)
at org.apache.jasper.el.JasperELResolver.getValue(JasperELResolver.java:104)
at org.apache.el.parser.AstValue.getValue(AstValue.java:183)
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:185)
at org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:1026)
at org.apache.jsp.WEB_002dINF.views.details_jsp._jspx_meth_c_005fforEach_005f1(details_jsp.java:750)
at org.apache.jsp.WEB_002dINF.views.details_jsp._jspx_meth_c_005fforEach_005f0(details_jsp.java:707)
at org.apache.jsp.WEB_002dINF.views.details_jsp._jspService(details_jsp.java:256)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:749)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:487)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:412)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:339)
at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238)
at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:262)
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1180)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:950)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:931)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)

Nov 21, 2013 7:34:07 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [appServlet] in context with path [/controller] threw exception [javax.el.PropertyNotFoundException: Property 'roomName' not found on type java.lang.String] with root cause
javax.el.PropertyNotFoundException: Property 'roomName' not found on type java.lang.String
at javax.el.BeanELResolver$BeanProperties.get(BeanELResolver.java:237)
at javax.el.BeanELResolver$BeanProperties.access$400(BeanELResolver.java:214)
at javax.el.BeanELResolver.property(BeanELResolver.java:325)
at javax.el.BeanELResolver.getValue(BeanELResolver.java:85)
at org.apache.jasper.el.JasperELResolver.getValue(JasperELResolver.java:104)
at org.apache.el.parser.AstValue.getValue(AstValue.java:183)
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:185)
at org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:1026)
at org.apache.jsp.WEB_002dINF.views.details_jsp._jspx_meth_c_005fforEach_005f1(details_jsp.java:750)
at org.apache.jsp.WEB_002dINF.views.details_jsp._jspx_meth_c_005fforEach_005f0(details_jsp.java:707)
at org.apache.jsp.WEB_002dINF.views.details_jsp._jspService(details_jsp.java:256)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:749)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:487)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:412)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:339)
at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238)
at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:262)
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1180)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:950)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:931)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)


on Browser ####

HTTP Status 500 - javax.el.PropertyNotFoundException: Property 'roomName' not found on type java.lang.String

type Exception report

message javax.el.PropertyNotFoundException: Property 'roomName' not found on type java.lang.String

description The server encountered an internal error that prevented it from fulfilling this request.

exception

Answer

I see an error in jsp: meetingType.Meetings in second forEach should be ${meetingType.Meetings}. Here is the corrected version:

<c:forEach items="${meetingList}" var="meetingType">
    <td>  This from MeetingTypes:  ${meetingType.typeName}</td> 
    <c:forEach items="${meetingType.Meetings}" var="meet">
        <td>  This from Meetings:   ${meet.roomName}   </td>        
    </c:forEach>
</c:forEach>