Updating null value for foreign key - oracle

I am working with JPA and I am trying to insert foreign key value its working fine but during modifying it is updating null values..
Please Refer following code
package com.bcits.bfm.model;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
#Entity
#Table(name="JOB_CALENDER")
public class JobCalender implements java.io.Serializable {
private static final long serialVersionUID = 1L;
private int jobCalenderId;
private int scheduleType;
private String title;
private String description;
private String recurrenceRule;
private String recurrenceException;
private int recurrenceId;
private boolean isAllDay;
private Date start;
private Date end;
private String jobNumber;
private String jobGroup;
private int expectedDays;
private String jobPriority;
private String jobAssets;
private MaintainanceTypes maintainanceTypes;
private MaintainanceDepartment departmentName;
private JobTypes jobTypes;
#Id
#Column(name="JOB_CALENDER_ID")
#SequenceGenerator(name = "JOB_CALENDER_SEQUENCE", sequenceName = "JOB_CALENDER_SEQUENCE")
#GeneratedValue(generator = "JOB_CALENDER_SEQUENCE")
public int getJobCalenderId() {
return jobCalenderId;
}
public void setJobCalenderId(int jobCalenderId ) {
this.jobCalenderId = jobCalenderId ;
}
#Column(name="SCHEDULE_TYPE")
public int getScheduleType() {
return scheduleType;
}
public void setScheduleType(int scheduleType) {
this.scheduleType = scheduleType;
}
#Column(name="START_DATE")
public Date getStart() {
return start;
}
public void setStart(Date start) {
this.start = start;
}
#Column(name="END_DATE")
public Date getEnd() {
return end;
}
public void setEnd(Date end) {
this.end = end;
}
#Column(name="Title")
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
#Column(name="DESCRIPTION")
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
#Column(name="RECURRENCE_RULE")
public String getRecurrenceRule() {
return recurrenceRule;
}
public void setRecurrenceRule(String recurrenceRule) {
this.recurrenceRule = recurrenceRule;
}
#Column(name="IS_ALL_DAY")
public boolean getIsAllDay() {
return isAllDay;
}
public void setIsAllDay(boolean isAllDay) {
this.isAllDay = isAllDay;
}
#Column(name="RECURENCE_EXCEPTION")
public String getRecurrenceException() {
return recurrenceException;
}
public void setRecurrenceException(String recurrenceException) {
this.recurrenceException = recurrenceException;
}
#Column(name="RECURRENCE_ID")
public int getRecurrenceId() {
return recurrenceId;
}
public void setRecurrenceId(int recurrenceId) {
this.recurrenceId = recurrenceId;
}
/*Custom Columns*/
#Column(name = "JOB_NUMBER", nullable = false, length = 45)
public String getJobNumber() {
return this.jobNumber;
}
public void setJobNumber(String jobNumber) {
this.jobNumber = jobNumber;
}
#Column(name = "JOB_GROUP", nullable = false, length = 45)
public String getJobGroup() {
return this.jobGroup;
}
public void setJobGroup(String jobGroup) {
this.jobGroup = jobGroup;
}
#Column(name = "EXPECTED_DAYS", nullable = false, precision = 11, scale = 0)
public int getExpectedDays() {
return this.expectedDays;
}
public void setExpectedDays(int expectedDays) {
this.expectedDays = expectedDays;
}
#Column(name = "JOB_PRIORITY", nullable = false, length = 45)
public String getJobPriority() {
return this.jobPriority;
}
public void setJobPriority(String jobPriority) {
this.jobPriority = jobPriority;
}
#Column(name = "JOB_ASSETS", nullable = false, length = 4000)
public String getJobAssets() {
return this.jobAssets;
}
public void setJobAssets(String jobAssets) {
this.jobAssets = jobAssets;
}
#ManyToOne(fetch = FetchType.EAGER)
#JoinColumn(name = "JOB_DEPT_ID",referencedColumnName="MT_DP_IT",nullable = false)
public MaintainanceDepartment getMaintainanceDepartment() {
return this.departmentName;
}
public void setMaintainanceDepartment(
MaintainanceDepartment departmentName) {
this.departmentName = departmentName;
}
#ManyToOne(fetch = FetchType.EAGER)
#JoinColumn(name = "JOB_TYPE_ID",referencedColumnName="JT_ID",nullable = false)
public JobTypes getJobTypes() {
return this.jobTypes;
}
public void setJobTypes(JobTypes jobTypes) {
this.jobTypes = jobTypes;
}
#ManyToOne(fetch = FetchType.EAGER)
#JoinColumn(name = "MAINTAINANCE_TYPE_ID",nullable = false)
public MaintainanceTypes getMaintainanceTypes() {
return this.maintainanceTypes;
}
public void setMaintainanceTypes(MaintainanceTypes maintainanceTypes) {
this.maintainanceTypes = maintainanceTypes;
}
}
And Parent Table Is
package com.bcits.bfm.model;
import java.sql.Timestamp;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
/**
* MaintainanceTypes entity. #author MyEclipse Persistence Tools
*/
#Entity
#Table(name = "MAINTAINANCE_TYPES")
public class MaintainanceTypes implements java.io.Serializable {
private static final long serialVersionUID = 1L;
// Fields
private int mtId;
private String maintainanceType;
private String description;
private Timestamp mtDt;
private String createdBy;
private String lastUpdatedBy;
private Timestamp lastUpdatedDt;
private Set<JobCards> jobCardses = new HashSet<JobCards>(0);
private Set<JobCalender> jobCalenders = new HashSet<JobCalender>(0);
// Constructors
/** default constructor */
public MaintainanceTypes() {
}
/** minimal constructor */
public MaintainanceTypes(int mtId, String maintainanceType, Timestamp mtDt) {
this.mtId = mtId;
this.maintainanceType = maintainanceType;
this.mtDt = mtDt;
}
/** full constructor */
public MaintainanceTypes(int mtId, String maintainanceType,
String description, Timestamp mtDt, String createdBy,
String lastUpdatedBy, Timestamp lastUpdatedDt,
Set<JobCards> jobCardses) {
this.mtId = mtId;
this.maintainanceType = maintainanceType;
this.description = description;
this.mtDt = mtDt;
this.createdBy = createdBy;
this.lastUpdatedBy = lastUpdatedBy;
this.lastUpdatedDt = lastUpdatedDt;
this.jobCardses = jobCardses;
}
// Property accessors
#Id
#Column(name = "MT_ID", unique = true, nullable = false, precision = 11, scale = 0)
#SequenceGenerator(name = "MAINTENANCE_TYPES_SEQ", sequenceName = "MAINTENANCE_TYPES_SEQ")
#GeneratedValue(generator = "MAINTENANCE_TYPES_SEQ")
public int getMtId() {
return this.mtId;
}
public void setMtId(int mtId) {
this.mtId = mtId;
}
#Column(name = "MAINTAINANCE_TYPE", nullable = false, length = 20)
public String getMaintainanceType() {
return this.maintainanceType;
}
public void setMaintainanceType(String maintainanceType) {
this.maintainanceType = maintainanceType;
}
#Column(name = "DESCRIPTION", length = 200)
public String getDescription() {
return this.description;
}
public void setDescription(String description) {
this.description = description;
}
#Column(name = "MT_DT", nullable = false, length = 11)
public Timestamp getMtDt() {
return this.mtDt;
}
public void setMtDt(Timestamp mtDt) {
this.mtDt = mtDt;
}
#Column(name = "CREATED_BY", length = 45)
public String getCreatedBy() {
return this.createdBy;
}
public void setCreatedBy(String createdBy) {
this.createdBy = createdBy;
}
#Column(name = "LAST_UPDATED_BY", length = 45)
public String getLastUpdatedBy() {
return this.lastUpdatedBy;
}
public void setLastUpdatedBy(String lastUpdatedBy) {
this.lastUpdatedBy = lastUpdatedBy;
}
#Column(name = "LAST_UPDATED_DT", length = 11)
public Timestamp getLastUpdatedDt() {
return this.lastUpdatedDt;
}
public void setLastUpdatedDt(Timestamp lastUpdatedDt) {
this.lastUpdatedDt = lastUpdatedDt;
}
#OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "maintainanceTypes")
public Set<JobCards> getJobCardses() {
return this.jobCardses;
}
public void setJobCardses(Set<JobCards> jobCardses) {
this.jobCardses = jobCardses;
}
#OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "maintainanceTypes")
public Set<JobCalender> getJobCalenders() {
return this.jobCalenders;
}
public void setJobCalenders(Set<JobCalender> jobCalenders) {
this.jobCalenders = jobCalenders;
}
}
I am calling below method to Update
public void Update(JobCalender jobCalender) {
update(jobCalender); //update() is generic method
}
public T update(final T t) {
BfmLogger.logger.info("updating "+t+" instance");
try {
T result = this.entityManager.merge(t);
BfmLogger.logger.info("update successful");
return result;
} catch (RuntimeException re) {
BfmLogger.logger.error("update failed", re);
throw re;
}
}
My Controller Code
#RequestMapping(value = "/index/create", method = RequestMethod.POST)
public #ResponseBody List<?> create(#RequestBody Map<String, Object>model,#ModelAttribute JobCalender jobCalender,BindingResult bindingResult, HttpServletRequest request) throws ParseException {
jobCalender.setDescription((String)model.get("description"));
jobCalender.setTitle((String)model.get("title"));
SimpleDateFormat iso8601 = new SimpleDateFormat("yyyy-M-dd'T'HH:mm:ss.SSS'Z'");
iso8601.setTimeZone(TimeZone.getTimeZone("UTC"));
jobCalender.setStart(iso8601.parse((String)model.get("start")));
jobCalender.setEnd(iso8601.parse((String)model.get("end")));
jobCalender.setIsAllDay((boolean) model.get("isAllDay"));
jobCalender.setRecurrenceRule((String)model.get("recurrenceRule"));
jobCalender.setRecurrenceException((String)model.get("recurrenceException"));
if(model.get("recurrenceId")!=null)
jobCalender.setRecurrenceId((Integer)model.get("recurrenceId"));
jobCalender.setScheduleType(Integer.parseInt(model.get("scheduleType").toString()));
jobCalender.setJobNumber((String) model.get("jobNumber"));
jobCalender.setDescription((String) model.get("description"));
jobCalender.setJobGroup((String) model.get("jobGroup"));
jobCalender.setMaintainanceDepartment(maintainanceDepartmentService.find(Integer.parseInt(model.get("departmentName").toString())));
jobCalender.setMaintainanceTypes(maintainanceTypesService.find(Integer.parseInt(model.get("maintainanceTypes").toString())));
jobCalender.setJobTypes(jobTypesService.find(Integer.parseInt(model.get("jobTypes").toString())));
jobCalender.setJobPriority((String) model.get("jobPriority"));
String ids="";
#SuppressWarnings("unchecked")
List<Map<String, Object>> listAssets = (ArrayList<Map<String, Object>>) model.get("assetName");// this is what you have already
for (Map<String, Object> map1 :listAssets) {
for (Map.Entry<String, Object> entry : map1.entrySet()) {
if(entry.getKey().equalsIgnoreCase("assetId")){
ids+=entry.getValue()+",";
}
}
}
jobCalender.setJobAssets(ids);
jobCalenderService.Update(jobCalender);
}
while Updating JOB_CALENDER Table it is Adding NULL Value For MAINTAINANCE_TYPE_ID Column
Please Help Me
Thank You
Regards
Manjunath Kotagi

Related

The primary key of the parent table is the primary key of the child table, How can I map it using jpa?

This is the diagram:
References: https://docs.spring.io/spring-batch/docs/current/reference/html/index-single.html
I get the list from the batch_job_execution_params table but the data is repeated with the information in the first row, the count is correct.
My Entity classes are as follows:
BATCH_JOB_EXECUTION TABLE
package com.maxcom.interfact_services.entity;
import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import javax.persistence.*;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Set;
#Entity
#Table(name = "BATCH_JOB_EXECUTION")
public class BatchJobExecutionEntity implements Serializable {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
#Column(name = "JOB_EXECUTION_ID", nullable = false)
private Long jobExecutionId;
#Column(name = "VERSION")
private Long version;
#ManyToOne
#JoinColumn(name = "JOB_INSTANCE_ID", nullable = false, updatable = false)
private BatchJobInstanceEntity jobInstanceId;
#Column(name = "CREATE_TIME")
#Temporal(TemporalType.TIMESTAMP)
private Date createTime;
#Column(name = "START_TIME")
#Temporal(TemporalType.TIMESTAMP)
private Date startTime;
#Column(name = "END_TIME")
#Temporal(TemporalType.TIMESTAMP)
private Date endTime;
#Column(name = "STATUS")
private String status;
#Column(name = "EXIT_CODE")
private String exitCode;
#Column(name = "EXIT_MESSAGE")
private String exitMessage;
#Column(name = "LAST_UPDATED")
#Temporal(TemporalType.TIMESTAMP)
private Date lastUpdated;
#Column(name = "JOB_CONFIGURATION_LOCATION")
private String jobConfigurationLocation;
#OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "batchJobExecutionEntity", orphanRemoval = true)
private Set<BatchStepExecutionEntity> batchSteps;
#JsonManagedReference
#MapsId("jobExecutionId")
#OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "jobExecutionId", orphanRemoval = true)
// #JsonIgnoreProperties("batchJobExecutionEntity")
private List<BatchJobExecutionParamsEntity> batchJobParams = new ArrayList<>();
public BatchJobExecutionEntity() {
}
public Long getJobExecutionId() {
return jobExecutionId;
}
public void setJobExecutionId(Long jobExecutionId) {
this.jobExecutionId = jobExecutionId;
}
public Long getVersion() {
return version;
}
public void setVersion(Long version) {
this.version = version;
}
#JsonBackReference
public BatchJobInstanceEntity getJobInstanceId() {
return jobInstanceId;
}
public void setJobInstanceId(BatchJobInstanceEntity jobInstanceId) {
this.jobInstanceId = jobInstanceId;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public Date getStartTime() {
return startTime;
}
public void setStartTime(Date startTime) {
this.startTime = startTime;
}
public Date getEndTime() {
return endTime;
}
public void setEndTime(Date endTime) {
this.endTime = endTime;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getExitCode() {
return exitCode;
}
public void setExitCode(String exitCode) {
this.exitCode = exitCode;
}
public String getExitMessage() {
return exitMessage;
}
public void setExitMessage(String exitMessage) {
this.exitMessage = exitMessage;
}
public Date getLastUpdated() {
return lastUpdated;
}
public void setLastUpdated(Date lastUpdated) {
this.lastUpdated = lastUpdated;
}
public String getJobConfigurationLocation() {
return jobConfigurationLocation;
}
public void setJobConfigurationLocation(String jobConfigurationLocation) {
this.jobConfigurationLocation = jobConfigurationLocation;
}
#JsonManagedReference
public Set<BatchStepExecutionEntity> getBatchSteps() {
return batchSteps;
}
public void setBatchSteps(Set<BatchStepExecutionEntity> batchSteps) {
this.batchSteps = batchSteps;
}
public List<BatchJobExecutionParamsEntity> getBatchJobParams() {
return batchJobParams;
}
public void setBatchJobParams(List<BatchJobExecutionParamsEntity> batchJobParams) {
this.batchJobParams = batchJobParams;
}
}
BATCH_JOB_EXECUTION_PARAMS TABLE
package com.maxcom.interfact_services.entity;
import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
#Entity
#Table(name = "BATCH_JOB_EXECUTION_PARAMS")
public class BatchJobExecutionParamsEntity implements Serializable {
#Id
// #GeneratedValue(strategy = GenerationType.AUTO)
#Column(name = "JOB_EXECUTION_ID", length = 20)
private Long jobExecutionId;
// #JsonBackReference
// #ManyToOne(fetch = FetchType.LAZY)
// #JoinColumn(name= "JOB_EXECUTION_ID", insertable = false, updatable = false)
// #JsonIgnoreProperties("batchJobParams")
// private BatchJobExecutionEntity batchJobExecutionEntity;
#Column(name = "TYPE_CD", length = 6)
private String typeCd;
#Column(name = "KEY_NAME", length = 100)
private String keyName;
#Column(name = "STRING_VAL", length = 250)
private String stringVal;
#Column(name = "DATE_VAL")
#Temporal(TemporalType.TIMESTAMP)
private Date dateVal;
#Column(name = "LONG_VAL")
private Long longVal;
#Column(name = "DOUBLE_VAL")
private Double doubleVal;
#Column(name = "IDENTIFYING", columnDefinition = "char(1)")
private String identifying;
public BatchJobExecutionParamsEntity() {
}
public Long getJobExecutionId() {
return jobExecutionId;
}
public void setJobExecutionId(Long jobExecutionId) {
this.jobExecutionId = jobExecutionId;
}
public String getTypeCd() {
return typeCd;
}
public void setTypeCd(String typeCd) {
this.typeCd = typeCd;
}
public String getKeyName() {
return keyName;
}
public void setKeyName(String keyName) {
this.keyName = keyName;
}
public String getStringVal() {
return stringVal;
}
public void setStringVal(String stringVal) {
this.stringVal = stringVal;
}
public Date getDateVal() {
return dateVal;
}
public void setDateVal(Date dateVal) {
this.dateVal = dateVal;
}
public Long getLongVal() {
return longVal;
}
public void setLongVal(Long longVal) {
this.longVal = longVal;
}
public Double getDoubleVal() {
return doubleVal;
}
public void setDoubleVal(Double doubleVal) {
this.doubleVal = doubleVal;
}
public String getIdentifying() {
return identifying;
}
public void setIdentifying(String identifying) {
this.identifying = identifying;
}
/*
public BatchJobExecutionEntity getBatchJobExecutionEntity() {
return batchJobExecutionEntity;
}
public void setBatchJobExecutionEntity(BatchJobExecutionEntity batchJobExecutionEntity) {
this.batchJobExecutionEntity = batchJobExecutionEntity;
}
*/
}
How to map 1:N of this scenario?
Having a non-unique primary key is a recipe for disaster (/duplicates).
You missed Appendix B.3:
Note that there is no primary key for this table. This is because the framework has no use for one and, thus, does not require it. If need be, you can add a primary key may be added with a database generated key without causing any issues to the framework itself.
So you can either add a generated primary key to the table and use it as Id or create an EmbeddedId / IdClass on BatchJobExecutionParamsEntity with all the fields.
my solution was the following based on the answer from #Lookslikeitsnot and also to the following article: https://fullstackdeveloper.guru/2021/08/25/what-is-mapsid-used-for-in-jpa-hibernate-part-ii/
The keywords in this scenario were:
#Embeddable
#EmbeddedId
#MapsId
I Share my final code:
- BatchJobExecutionParamsEntity: (Child Table)
package com.maxcom.interfact_services.entity;
import com.fasterxml.jackson.annotation.JsonBackReference;
import javax.persistence.*;
import java.io.Serializable;
#Entity
#Table(name = "BATCH_JOB_EXECUTION_PARAMS")
public class BatchJobExecutionParamsEntity implements Serializable {
#EmbeddedId
private BatchJobParamIdEmbedded id;
#JsonBackReference
#ManyToOne
#MapsId("jobExecutionId")
#JoinColumn(name= "JOB_EXECUTION_ID", insertable = false, updatable = false)
private BatchJobExecutionEntity batchJobExecutionEntity;
public BatchJobExecutionParamsEntity() {
}
public BatchJobParamIdEmbedded getId() {
return id;
}
public void setId(BatchJobParamIdEmbedded id) {
this.id = id;
}
public BatchJobExecutionEntity getBatchJobExecutionEntity() {
return batchJobExecutionEntity;
}
public void setBatchJobExecutionEntity(BatchJobExecutionEntity batchJobExecutionEntity) {
this.batchJobExecutionEntity = batchJobExecutionEntity;
}
}
- BatchJobParamIdEmbedded: (Embedded Entity)
package com.maxcom.interfact_services.entity;
import javax.persistence.Column;
import javax.persistence.Embeddable;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import java.io.Serializable;
import java.util.Date;
#Embeddable
public class BatchJobParamIdEmbedded implements Serializable {
private Long jobExecutionId; // composite key class
#Column(name = "TYPE_CD", length = 6)
private String typeCd;
#Column(name = "KEY_NAME", length = 100)
private String keyName;
#Column(name = "STRING_VAL", length = 250)
private String stringVal;
#Column(name = "DATE_VAL")
#Temporal(TemporalType.TIMESTAMP)
private Date dateVal;
#Column(name = "LONG_VAL")
private Long longVal;
#Column(name = "DOUBLE_VAL")
private Double doubleVal;
#Column(name = "IDENTIFYING", columnDefinition = "char(1)")
private String identifying;
public Long getJobExecutionId() {
return jobExecutionId;
}
public void setJobExecutionId(Long jobExecutionId) {
this.jobExecutionId = jobExecutionId;
}
public String getTypeCd() {
return typeCd;
}
public void setTypeCd(String typeCd) {
this.typeCd = typeCd;
}
public String getKeyName() {
return keyName;
}
public void setKeyName(String keyName) {
this.keyName = keyName;
}
public String getStringVal() {
return stringVal;
}
public void setStringVal(String stringVal) {
this.stringVal = stringVal;
}
public Date getDateVal() {
return dateVal;
}
public void setDateVal(Date dateVal) {
this.dateVal = dateVal;
}
public Long getLongVal() {
return longVal;
}
public void setLongVal(Long longVal) {
this.longVal = longVal;
}
public Double getDoubleVal() {
return doubleVal;
}
public void setDoubleVal(Double doubleVal) {
this.doubleVal = doubleVal;
}
public String getIdentifying() {
return identifying;
}
public void setIdentifying(String identifying) {
this.identifying = identifying;
}
}
- BatchJobExecutionEntity: (Parent Table)
package com.maxcom.interfact_services.entity;
import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import javax.persistence.*;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
#Entity
#Table(name = "BATCH_JOB_EXECUTION")
public class BatchJobExecutionEntity implements Serializable {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
#Column(name = "JOB_EXECUTION_ID", nullable = false)
private Long jobExecutionId;
#Column(name = "VERSION")
private Long version;
#ManyToOne
#JoinColumn(name = "JOB_INSTANCE_ID", nullable = false, updatable = false)
private BatchJobInstanceEntity jobInstanceId;
#Column(name = "CREATE_TIME")
#Temporal(TemporalType.TIMESTAMP)
private Date createTime;
#Column(name = "START_TIME")
#Temporal(TemporalType.TIMESTAMP)
private Date startTime;
#Column(name = "END_TIME")
#Temporal(TemporalType.TIMESTAMP)
private Date endTime;
#Column(name = "STATUS")
private String status;
#Column(name = "EXIT_CODE")
private String exitCode;
#Column(name = "EXIT_MESSAGE")
private String exitMessage;
#Column(name = "LAST_UPDATED")
#Temporal(TemporalType.TIMESTAMP)
private Date lastUpdated;
#Column(name = "JOB_CONFIGURATION_LOCATION")
private String jobConfigurationLocation;
#OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "batchJobExecutionEntity", orphanRemoval = true)
private List<BatchStepExecutionEntity> batchSteps;
#JsonManagedReference
#OneToMany(mappedBy = "batchJobExecutionEntity", cascade = CascadeType.ALL, fetch = FetchType.LAZY, orphanRemoval = true)
private List<BatchJobExecutionParamsEntity> batchJobParams = new ArrayList<>();
public BatchJobExecutionEntity() {
}
public Long getJobExecutionId() {
return jobExecutionId;
}
public void setJobExecutionId(Long jobExecutionId) {
this.jobExecutionId = jobExecutionId;
}
public Long getVersion() {
return version;
}
public void setVersion(Long version) {
this.version = version;
}
#JsonBackReference
public BatchJobInstanceEntity getJobInstanceId() {
return jobInstanceId;
}
public void setJobInstanceId(BatchJobInstanceEntity jobInstanceId) {
this.jobInstanceId = jobInstanceId;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public Date getStartTime() {
return startTime;
}
public void setStartTime(Date startTime) {
this.startTime = startTime;
}
public Date getEndTime() {
return endTime;
}
public void setEndTime(Date endTime) {
this.endTime = endTime;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getExitCode() {
return exitCode;
}
public void setExitCode(String exitCode) {
this.exitCode = exitCode;
}
public String getExitMessage() {
return exitMessage;
}
public void setExitMessage(String exitMessage) {
this.exitMessage = exitMessage;
}
public Date getLastUpdated() {
return lastUpdated;
}
public void setLastUpdated(Date lastUpdated) {
this.lastUpdated = lastUpdated;
}
public String getJobConfigurationLocation() {
return jobConfigurationLocation;
}
public void setJobConfigurationLocation(String jobConfigurationLocation) {
this.jobConfigurationLocation = jobConfigurationLocation;
}
#JsonManagedReference
public List<BatchStepExecutionEntity> getBatchSteps() {
return batchSteps;
}
public void setBatchSteps(List<BatchStepExecutionEntity> batchSteps) {
this.batchSteps = batchSteps;
}
public List<BatchJobExecutionParamsEntity> getBatchJobParams() {
return batchJobParams;
}
public void setBatchJobParams(List<BatchJobExecutionParamsEntity> batchJobParams) {
this.batchJobParams = batchJobParams;
}
/* Add an batchJobParam to jobExecution Entity to maintain the bi-directional OneToMapping */
public void addBatchJobExecutionParam(BatchJobExecutionParamsEntity batchJobParam) {
this.batchJobParams.add(batchJobParam);
batchJobParam.setBatchJobExecutionEntity(this);
}
}
As shown in the following image, I now get different objects, of course encapsulated in the id (BatchJobParamIdEmbedded):
The second picture shows more details:
Thank you all for your support.
Best regards

problem with saving data in many-to-many intermediate table spring boot

following are my entity
package bt.gov.dit.inventoryservice.model;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
//import org.hibernate.mapping.Set;
import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
#Entity
#Table(name = "items")
public class Items implements Serializable {
private Long Id;
#Column(name = "item_name")
private String itemName;
// #ManyToOne(fetch = FetchType.LAZY)
// #JoinColumn(name = "categories_id",nullable = false, referencedColumnName = "id")
private Categories categories;
private Stores stores;
//#Temporal(TemporalType.TIMESTAMP)
#Column(name = "insert_date")
private Date insertDate = new Date();
// #Temporal(TemporalType.TIMESTAMP)
#Column(name = "update_date")
private Date updateDate = new Date();
private Set<Logs> logs = new HashSet<Logs>() ;
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
public Long getId() {
return Id;
}
public void setId(Long id) {
Id = id;
}
public String getItemName() {
return itemName;
}
public void setItemName(String itemName) {
this.itemName = itemName;
}
#ManyToOne(fetch = FetchType.LAZY)
#JoinColumn(name = "categories_id", nullable = false, referencedColumnName = "id")
public Categories getCategories() {
return categories;
}
public void setCategories(Categories categories) {
this.categories = categories;
}
#ManyToOne(fetch = FetchType.LAZY)
#JoinColumn(name = "stores_id", nullable = false, referencedColumnName = "id")
public Stores getStores() {
return stores;
}
public void setStores(Stores stores) {
this.stores = stores;
}
public Date getInsertDate() {
return insertDate;
}
public void setInsertDate(Date insertDate) {
this.insertDate = insertDate;
}
public Date getUpdateDate() {
return updateDate;
}
public void setUpdateDate(Date updateDate) {
this.updateDate = updateDate;
}
#ManyToMany(cascade = CascadeType.ALL)
#JoinTable(name = "items_logs", joinColumns = #JoinColumn(name = "items_id", referencedColumnName = "id"), inverseJoinColumns = #JoinColumn(name = "logs_id",referencedColumnName = "id") )
public Set<Logs> getLogs() {
return logs;
}
public void setLogs(Set<Logs> logs) {
this.logs = logs;
}
}
package bt.gov.dit.inventoryservice.model;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
#Entity
#Table(name = "logs")
public class Logs {
private Long id;
#Column(name = "cadet_id")
private Long cadetId;
private Set<Items> items = new HashSet<Items>() ;
#Column(name = "borrowed_date")
//#Temporal(TemporalType.TIMESTAMP)
private Date borrowedDate = new Date();
private String status;
private String comments;
#Id
#GeneratedValue
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Long getCadetId() {
return cadetId;
}
public void setCadetId(Long cadetId) {
this.cadetId = cadetId;
}
public Date getBorrowedDate() {
return borrowedDate;
}
public void setBorrowedDate(Date borrowedDate) {
this.borrowedDate = borrowedDate;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getComments() {
return comments;
}
public void setComments(String comments) {
this.comments = comments;
}
#ManyToMany(fetch = FetchType.LAZY,mappedBy = "logs")
public Set<Items> getItems() {
return items;
}
public void setItems(Set<Items> items) {
this.items = items;
}
}
I have many to many relationship between them. Due to that there is an intermediate table created with field item_id and log_id. Now I don't know how to save data in that table. I can save items and i can save log. But I have problem with saving the many-to-many relationship between them?

Dynamic type caste Spring pathvariable

I am planning to create one simple Spring Rest Service Project with JPA which will fetch the details from the database based on the entity name and entity id given in path variables.
consider following code.
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ds.dao.EntityDAO;
import com.ds.entities.Employees;
import javax.persistence.Entity;
#Controller
#RequestMapping("/")
public class DynaRestController {
#Autowired
EntityDAO entityDAO;
#RequestMapping(value = "{entityName}/{enityId}",method = RequestMethod.GET)
public #ResponseBody Object getEntity(#PathVariable("entityName") String entityName,#PathVariable("enityId") Object id) {
return entityDAO.getEntityById(entityName, id);
}
}
Entity DAO Class
public class EntityDAO {
#Autowired
EntityManager entityManager;
public Object getEntityById(String entityName, Object id) {
EntityType<?> entityType = getEntityByName(entityName);
Object idcasted = entityType.getIdType().getJavaType().cast(id);
System.out.println(idcasted.getClass().getName());
Object entity = entityManager.find(entityType.getJavaType(), idcasted);
System.out.println("Entity.. Name .." + entityName);
// Employees entity = session.load(Employees.class, id);
return entity;
}
private EntityType<?> getEntityByName(String name) {
Set<EntityType<?>> entities = entityManager.getMetamodel().getEntities();
for (Iterator<EntityType<?>> iterator = entities.iterator(); iterator.hasNext();) {
EntityType<?> entityType = (EntityType<?>) iterator.next();
if (entityType.getName().equals(name))
return entityType;
}
return null;
}
}
Employees Class
#Configurable
#Entity
#Table(name = "employees", catalog = "employees")
public class Employees implements java.io.Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private int empNo;
private Date birthDate;
private String firstName;
private String lastName;
private String gender;
private Date hireDate;
private Set<Titles> titleses = new HashSet<Titles>(0);
private Set<Salaries> salarieses = new HashSet<Salaries>(0);
private Set<DeptEmp> deptEmps = new HashSet<DeptEmp>(0);
private Set<DeptManager> deptManagers = new HashSet<DeptManager>(0);
public Employees() {
}
public Employees(int empNo, Date birthDate, String firstName, String lastName, String gender, Date hireDate) {
this.empNo = empNo;
this.birthDate = birthDate;
this.firstName = firstName;
this.lastName = lastName;
this.gender = gender;
this.hireDate = hireDate;
}
public Employees(int empNo, Date birthDate, String firstName, String lastName, String gender, Date hireDate,
Set<Titles> titleses, Set<Salaries> salarieses, Set<DeptEmp> deptEmps, Set<DeptManager> deptManagers) {
this.empNo = empNo;
this.birthDate = birthDate;
this.firstName = firstName;
this.lastName = lastName;
this.gender = gender;
this.hireDate = hireDate;
this.titleses = titleses;
this.salarieses = salarieses;
this.deptEmps = deptEmps;
this.deptManagers = deptManagers;
}
#Id
#Column(name = "emp_no", unique = true, nullable = false)
public int getEmpNo() {
return this.empNo;
}
public void setEmpNo(int empNo) {
this.empNo = empNo;
}
#Temporal(TemporalType.DATE)
#Column(name = "birth_date", nullable = false, length = 10)
public Date getBirthDate() {
return this.birthDate;
}
public void setBirthDate(Date birthDate) {
this.birthDate = birthDate;
}
#Column(name = "first_name", nullable = false, length = 14)
public String getFirstName() {
return this.firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
#Column(name = "last_name", nullable = false, length = 16)
public String getLastName() {
return this.lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
#Column(name = "gender", nullable = false, length = 2)
public String getGender() {
return this.gender;
}
public void setGender(String gender) {
this.gender = gender;
}
#Temporal(TemporalType.DATE)
#Column(name = "hire_date", nullable = false, length = 10)
public Date getHireDate() {
return this.hireDate;
}
public void setHireDate(Date hireDate) {
this.hireDate = hireDate;
}
#OneToMany(fetch = FetchType.LAZY, mappedBy = "employees")
public Set<Titles> getTitleses() {
return this.titleses;
}
public void setTitleses(Set<Titles> titleses) {
this.titleses = titleses;
}
#OneToMany(fetch = FetchType.LAZY, mappedBy = "employees")
public Set<Salaries> getSalarieses() {
return this.salarieses;
}
public void setSalarieses(Set<Salaries> salarieses) {
this.salarieses = salarieses;
}
#OneToMany(fetch = FetchType.LAZY, mappedBy = "employees")
#JsonBackReference
public Set<DeptEmp> getDeptEmps() {
return this.deptEmps;
}
public void setDeptEmps(Set<DeptEmp> deptEmps) {
this.deptEmps = deptEmps;
}
#OneToMany(fetch = FetchType.LAZY, mappedBy = "employees")
public Set<DeptManager> getDeptManagers() {
return this.deptManagers;
}
public void setDeptManagers(Set<DeptManager> deptManagers) {
this.deptManagers = deptManagers;
}
}
When i am dynamically casting the path variable by using following code
Object idcasted = entityType.getIdType().getJavaType().cast(id);
Object entity = entityManager.find(entityType.getJavaType(), idcasted);
it is throwing ClassCastExpcetion
java.lang.ClassCastException: Cannot cast java.lang.String to int
at java.lang.Class.cast(Class.java:3369) ~[na:1.8.0_112]
at com.techm.att.ds.dao.EntityDAO.getEntityById(EntityDAO.java:33) ~[classes/:na]
at com.techm.att.ds.dao.EntityDAO$$FastClassBySpringCGLIB$$8e64d745.invoke() ~[classes/:na]
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) ~[spring-core-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:738) ~[spring-aop-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) ~[spring-aop-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136) ~[spring-tx-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.13.RELEASE.jar:4.3.13.RELEASE]
any Help will be highly appriciated..
I write you a simple example regarding the comments.
This is the same behavior. Your RestController gets actually a string:
public static void main(String[] args) {
Object myString = "myString";
System.out.println(myString.getClass()); // class java.lang.String
int.class.cast(myString);
}
The cast method checks the instanceof your given value and it fails:
public T cast(Object obj) {
if (obj != null && !isInstance(obj))
throw new ClassCastException(cannotCastMsg(obj));
return (T) obj;
}

How to retrieve data from a one to one mapped entity after a filter is applied on to the mapped entity's attribute spring

How to retrieve data from a one to one mapped entity after a filter is applied on to the mapped entity's attribute.
This is my Hotel Entity Class..
package com.springmvcweb.model;
import javax.persistence.*;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
#Entity
#Table(name = "HOTEL", schema = "HOTEL")
public class HotelEntity implements Serializable{
private long hotelId;
private String hotelName;
private String hotelDescription;
private String hotelWebsite;
private Long hotelPhoneNo;
private String hotelEmail;
private Long hotelStarRating;
private AddressEntity addressEntity;
private CategoryEntity categoryEntity;
private List<AmenityEntity> amenitiesList;
#ManyToMany(cascade = {CascadeType.MERGE,CascadeType.PERSIST,CascadeType.DETACH,CascadeType.REFRESH})
#JoinTable(name = "HOTEL_AMENITY", joinColumns = {#JoinColumn(name = "HOTEL_ID", referencedColumnName = "HOTEL_ID")},
inverseJoinColumns = {#JoinColumn(name = "AMENITY_ID", referencedColumnName = "AMENITY_ID")})
public List<AmenityEntity> getAmenitiesList() {
return amenitiesList;
}
public void setAmenitiesList(List<AmenityEntity> amenitiesList) {
this.amenitiesList = amenitiesList;
}
#OneToOne(cascade = CascadeType.ALL)
#JoinColumn(name = "HOTEL_ADDRESS_ID")
public AddressEntity getAddressEntity() {
return addressEntity;
}
public void setAddressEntity(AddressEntity addressEntity) {
this.addressEntity = addressEntity;
}
#ManyToOne(cascade = {CascadeType.MERGE,CascadeType.PERSIST,CascadeType.DETACH,CascadeType.REFRESH})
#JoinColumn(name = "HOTEL_CATEGORY_ID")
public CategoryEntity getCategoryEntity() {
return categoryEntity;
}
public void setCategoryEntity(CategoryEntity categoryEntity) {
this.categoryEntity = categoryEntity;
}
#Id
#Column(name = "HOTEL_ID")
public long getHotelId() {
return hotelId;
}
public void setHotelId(long hotelId) {
this.hotelId = hotelId;
}
#Basic
#Column(name = "HOTEL_NAME")
public String getHotelName() {
return hotelName;
}
public void setHotelName(String hotelName) {
this.hotelName = hotelName;
}
#Basic
#Column(name = "HOTEL_DESCRIPTION")
public String getHotelDescription() {
return hotelDescription;
}
public void setHotelDescription(String hotelDescription) {
this.hotelDescription = hotelDescription;
}
#Basic
#Column(name = "HOTEL_WEBSITE")
public String getHotelWebsite() {
return hotelWebsite;
}
public void setHotelWebsite(String hotelWebsite) {
this.hotelWebsite = hotelWebsite;
}
#Basic
#Column(name = "HOTEL_PHONE_NO")
public Long getHotelPhoneNo() {
return hotelPhoneNo;
}
public void setHotelPhoneNo(Long hotelPhoneNo) {
this.hotelPhoneNo = hotelPhoneNo;
}
#Basic
#Column(name = "HOTEL_EMAIL")
public String getHotelEmail() {
return hotelEmail;
}
public void setHotelEmail(String hotelEmail) {
this.hotelEmail = hotelEmail;
}
#Basic
#Column(name = "HOTEL_STAR_RATING")
public Long getHotelStarRating() {
return hotelStarRating;
}
public void setHotelStarRating(Long hotelStarRating) {
this.hotelStarRating = hotelStarRating;
}
public void addAmenities(AmenityEntity amenityEntity){
if(amenitiesList==null){
amenitiesList = new ArrayList<>();
}
amenitiesList.add(amenityEntity);
}
#Override
public String toString() {
return "HotelEntity{" +
"hotelId=" + hotelId +
", hotelName='" + hotelName + '\'' +
", hotelDescription='" + hotelDescription + '\'' +
", hotelWebsite='" + hotelWebsite + '\'' +
", hotelPhoneNo=" + hotelPhoneNo +
", hotelEmail='" + hotelEmail + '\'' +
", hotelStarRating=" + hotelStarRating +
", addressEntity=" + addressEntity +
", categoryEntity=" + categoryEntity +
", amenitiesList=" + amenitiesList +
'}';
}
}
This is AddressEntity Class:
package com.springmvcweb.model;
import javax.persistence.*;
import java.io.Serializable;
#Entity
#Table(name = "ADDRESS", schema = "HOTEL")
public class AddressEntity implements Serializable {
private long addressId;
private String addressLine1;
private String addressLine2;
private String cityName;
private String stateName;
private String countryName;
private Long pincode;
#Id
#Column(name = "ADDRESS_ID")
public long getAddressId() {
return addressId;
}
public void setAddressId(long addressId) {
this.addressId = addressId;
}
#Basic
#Column(name = "ADDRESS_LINE1")
public String getAddressLine1() {
return addressLine1;
}
public void setAddressLine1(String addressLine1) {
this.addressLine1 = addressLine1;
}
#Basic
#Column(name = "ADDRESS_LINE2")
public String getAddressLine2() {
return addressLine2;
}
public void setAddressLine2(String addressLine2) {
this.addressLine2 = addressLine2;
}
#Basic
#Column(name = "CITY_NAME")
public String getCityName() {
return cityName;
}
public void setCityName(String cityName) {
this.cityName = cityName;
}
#Basic
#Column(name = "STATE_NAME")
public String getStateName() {
return stateName;
}
public void setStateName(String stateName) {
this.stateName = stateName;
}
#Basic
#Column(name = "COUNTRY_NAME")
public String getCountryName() {
return countryName;
}
public void setCountryName(String countryName) {
this.countryName = countryName;
}
#Basic
#Column(name = "PINCODE")
public Long getPincode() {
return pincode;
}
public void setPincode(Long pincode) {
this.pincode = pincode;
}
}
Now I want to retrieve all those hotels filtered by their location(say cityname or statename) and I'm using query like this:
#Override
public List<HotelEntity> getHotelsByLocation(String location) {
try{
session = sessionFactory.getCurrentSession();
}catch (Exception e){
session = sessionFactory.openSession();
}
Query query = session.createQuery("from HotelEntity where HotelEntity.addressEntity.cityName " +
"like :location");
query.setParameter("location",location);
return query.getResultList();
}
Also I've used FetchType as EAGER in the HotelEntity OneToOne Mapping like this:
#OneToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
#JoinColumn(name = "HOTEL_ADDRESS_ID")
public AddressEntity getAddressEntity() {
return addressEntity;
}
Right now it is giving me a null pointer exception. Please guide.
#OneToOne relationship is eagerly fetched anyway so adding that information is redundant.
Regarding the query I would form it like the following:
" select he from HotelEntity he
" inner join he.addressEntity ae"
" where ae.cityName like :location");

javax.el.MethodNotFoundException: Method not found:

Spring - Hibernate
Newbie here, can please somebody help me locate what i'm missing. I am trying to do a onetomany relationship of payee and payor. My issue is im getting this error:
javax.el.MethodNotFoundException: Method not found: class com.supportmanagement.model.Payee.getPayor()
javax.el.Util.findWrapper(Util.java:349)
javax.el.Util.findMethod(Util.java:211)
javax.el.BeanELResolver.invoke(BeanELResolver.java:150)
List.jsp
{payeelist} came from my controller via map.put("payeelist", payeeServices.getPayees());
...
<c:forEach items="${payeelist}" var="payee" varStatus="payeeindex">
<tr>
<td class="pad-0"> </td>
<td><c:out value="${payee.getCaseNumber()}" /></td>
<td><c:out value="${payee.getLastname()}" /></td>
<td><c:out value="${payee.getFirstname()}" /></td>
<td><c:out value="${payee.getMiddlename()}" /></td>
<td class="text-center"><a href="/SupportManager/payor/add?casenumber=${payee.getCaseNumber()}">
${payee.getPayor().getCaseNumber()}
</a></td>
<td class="text-center">ADD PAYMENT <i class="glyphicon glyphicon-envelope"></i> </td>
</tr>
</c:forEach>
...
Payee.java
package com.supportmanagement.model;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.Table;
#Entity
#Table(name = "payeeMaster")
public class Payee implements Serializable {
private static final long serialVersionUID = 5876875389515595233L;
#Id
#Column(name = "CaseNumber", unique = true, nullable = false)
private String CaseNumber;
#Column(name = "Firstname")
private String Firstname;
#Column(name = "Lastname")
private String Lastname;
#Column(name = "Middlename")
private String Middlename;
#Column(name = "Address1")
private String Address1;
#Column(name = "Address2")
private String Address2;
#Column(name = "City")
private String City;
#Column(name = "State")
private String State;
#Column(name = "Zip")
private String Zip;
#Column(name = "HomePhone")
private String HomePhone;
#Column(name = "MobilePhone")
private String MobilePhone;
#Column(name = "Active")
private int Active;
#Column(name = "Comments")
private String Comments;
#Column(name = "StateCode")
private String StateCode;
#Column(name = "PA")
private int PA;
#Column(name = "OSE")
private int OSE;
#Column(name = "Envelope")
private int Envelope;
#Column(name = "AccountNumber")
private String AccountNumber;
#Column(name = "DNumber")
private String DNumber;
#Column(name = "LastModified")
private Date LastModified;
#Column(name = "ModifiedBy")
private String ModifiedBy;
private List<Payor> payor;
#OneToMany(mappedBy="Payor", cascade=CascadeType.ALL, fetch = FetchType.LAZY)
#JoinColumn(name="CaseNumber")
public List<Payor> getPayor() {
return payor;
}
public void setPayor(List<Payor> payor) {
this.payor = payor;
}
public String getCaseNumber() {
return CaseNumber;
}
public void setCaseNumber(String caseNumber) {
CaseNumber = caseNumber;
}
public String getFirstname() {
return Firstname;
}
public void setFirstname(String firstname) {
Firstname = firstname;
}
public String getLastname() {
return Lastname;
}
public void setLastname(String lastname) {
Lastname = lastname;
}
public String getMiddlename() {
return Middlename;
}
public void setMiddlename(String middlename) {
Middlename = middlename;
}
public String getAddress1() {
return Address1;
}
public void setAddress1(String address1) {
Address1 = address1;
}
public String getAddress2() {
return Address2;
}
public void setAddress2(String address2) {
Address2 = address2;
}
public String getCity() {
return City;
}
public void setCity(String city) {
City = city;
}
public String getState() {
return State;
}
public void setState(String state) {
State = state;
}
public String getZip() {
return Zip;
}
public void setZip(String zip) {
Zip = zip;
}
public String getHomePhone() {
return HomePhone;
}
public void setHomePhone(String homePhone) {
HomePhone = homePhone;
}
public String getMobilePhone() {
return MobilePhone;
}
public void setMobilePhone(String mobilePhone) {
MobilePhone = mobilePhone;
}
public int getActive() {
return Active;
}
public void setActive(int active) {
Active = active;
}
public String getComments() {
return Comments;
}
public void setComments(String comments) {
Comments = comments;
}
public String getStateCode() {
return StateCode;
}
public void setStateCode(String stateCode) {
StateCode = stateCode;
}
public int getPA() {
return PA;
}
public void setPA(int pA) {
PA = pA;
}
public int getOSE() {
return OSE;
}
public void setOSE(int oSE) {
OSE = oSE;
}
public int getEnvelope() {
return Envelope;
}
public void setEnvelope(int envelope) {
Envelope = envelope;
}
public String getAccountNumber() {
return AccountNumber;
}
public void setAccountNumber(String accountNumber) {
AccountNumber = accountNumber;
}
public String getDNumber() {
return DNumber;
}
public void setDNumber(String dNumber) {
DNumber = dNumber;
}
public Date getLastModified() {
return LastModified;
}
public void setLastModified(Date lastModified) {
LastModified = lastModified;
}
public String getModifiedBy() {
return ModifiedBy;
}
public void setModifiedBy(String modifiedBy) {
ModifiedBy = modifiedBy;
}
}
Payor.java
package com.supportmanager.model;
import java.io.Serializable;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
#Entity
#Table(name = "payorMaster")
public class Payor implements Serializable {
private static final long serialVersionUID = -1896406931521329889L;
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
#Column(name = "PayorID")
private Integer PayorID;
#Column(name = "CaseNumber")
private String CaseNumber;
#Column(name = "PayorFirstname")
private String PayorFirstname;
#Column(name = "PayorLastname")
private String PayorLastname;
#Column(name = "PayorMiddlename")
private String PayorMiddlename;
#Column(name = "PayorAddress1")
private String PayorAddress1;
#Column(name = "PayorAddress2")
private String PayorAddress2;
#Column(name = "PayorCity")
private String PayorCity;
#Column(name = "PayorState")
private String PayorState;
#Column(name = "PayorZip")
private String PayorZip;
#Column(name = "PayorHomePhone")
private String PayorHomePhone;
#Column(name = "PayorMobilePhone")
private String PayorMobilePhone;
#Column(name = "PayorActive")
private int PayorActive;
#Column(name = "PayorComments")
private String PayorComments;
#ManyToOne
#JoinColumn(name="CaseNumber")
private List<Payee> payee;
public Integer getPayorID() {
return PayorID;
}
public void setPayorID(Integer payorID) {
PayorID = payorID;
}
public String getCaseNumber() {
return CaseNumber;
}
public void setCaseNumber(String caseNumber) {
CaseNumber = caseNumber;
}
public String getPayorFirstname() {
return PayorFirstname;
}
public void setPayorFirstname(String payorFirstname) {
PayorFirstname = payorFirstname;
}
public String getPayorLastname() {
return PayorLastname;
}
public void setPayorLastname(String payorLastname) {
PayorLastname = payorLastname;
}
public String getPayorMiddlename() {
return PayorMiddlename;
}
public void setPayorMiddlename(String payorMiddlename) {
PayorMiddlename = payorMiddlename;
}
public String getPayorAddress1() {
return PayorAddress1;
}
public void setPayorAddress1(String payorAddress1) {
PayorAddress1 = payorAddress1;
}
public String getPayorAddress2() {
return PayorAddress2;
}
public void setPayorAddress2(String payorAddress2) {
PayorAddress2 = payorAddress2;
}
public String getPayorCity() {
return PayorCity;
}
public void setPayorCity(String payorCity) {
PayorCity = payorCity;
}
public String getPayorState() {
return PayorState;
}
public void setPayorState(String payorState) {
PayorState = payorState;
}
public String getPayorZip() {
return PayorZip;
}
public void setPayorZip(String payorZip) {
PayorZip = payorZip;
}
public String getPayorHomePhone() {
return PayorHomePhone;
}
public void setPayorHomePhone(String payorHomePhone) {
PayorHomePhone = payorHomePhone;
}
public String getPayorMobilePhone() {
return PayorMobilePhone;
}
public void setPayorMobilePhone(String payorMobilePhone) {
PayorMobilePhone = payorMobilePhone;
}
public int getPayorActive() {
return PayorActive;
}
public void setPayorActive(int payorActive) {
PayorActive = payorActive;
}
public String getPayorComments() {
return PayorComments;
}
public void setPayorComments(String payorComments) {
PayorComments = payorComments;
}
}
ApplicationContext.xml
....
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan" value="com.supportmanagement.model" />
<property name="hibernateProperties">
<props>
<prop key="dialect">org.hibernate.dialect.SQLServerDialect</prop>
<prop key="show_sql">true</prop>
<prop key="enable_lazy_load_no_trans">true</prop>
<prop key="default_schema">SupportManagerDB</prop>
<prop key="format_sql">true</prop>
<prop key="use_sql_comments">true</prop>
</props>
</property>
<property name="annotatedClasses">
<list>
<value>com.supportmanagement.model.Payee</value>
<value>com.supportmanagement.model.Payor</value>
</list>
</property>
</bean>
....
In you jsp page you use:
${payee.getPayor().getCaseNumber()}
Now.. getPayor() returns a List<Payor> and a List does not have the getCaseNumber() method.
You can get a certain Payor from the list and then invoke the method:
${payee.payor[index].caseNumber}
Where index is a hardcode value or a variable.

Resources