i have project for school, in my project I want to do a run the automatic and periodic execution of tasks like Windows task scheduler, But I didn't find the correct code do that. I do this business class, but which step i do for schedule the job?
how can i run the batch file and schedule the jobs ?
Please who can help me.
#SuppressWarnings("serial")
#Entity
#Table(name ="task")
public class Task implements Serializable{
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
#Column(name = "id")
private Integer id;
#Column(name = "nom_job", length = 20,nullable = false)
private String nom_job;
#Column(name = "description", length = 100, nullable = false)
private String description;
#Column(name = "scriptFile", length = 100, nullable = false)
private String scriptFile;
#Column(name = "date_execution", length = 20,nullable = false)
private Date date_execution;
#Column(name = "temps_execution", length = 100, nullable = false)
private Date temps_execution;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getNom_job() {
return nom_job;
}
public void setNom_job(String nom_job) {
this.nom_job = nom_job;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getScriptFile() {
return script;
}
public void setScriptFile(String script) {
this.script = script;
}
public Date getDate_exécution() {
return date_execution;
}
public void setDate_exécution(Date date_execution) {
this.date_execution = date_execution;
}
public Date getTemps_exécution() {
return temps_execution;
}
public void setTemps_exécution(Date temps_execution) {
this.temps_execution = temps_execution;
}
public Task(Integer id, String nom_job, String description, String scriptFile, Date
date_execution, Date temps_execution ) {
super();
this.id=id;
this.nom_job = nom_job;
this.description = description;
this.scriptFile = scriptFile;
this.date_execution = date_execution;
this.temps_execution = temps_execution;
}
}
Related
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [com.websystique.springmvc.model.AssetMakeMaster#0]
I have two entities are as follows:
1. AssetMaster
2. AssetMakeMaster
Above entities are mapped with tables. I want to use left join for above two entities and get the all the data from AssetMaster. Inner query is working fine for above entities but i want get the non matched values also. I have tried but not getting solution yet. Please anyone will give the solution for my problem.
I have tried the below query in mysql it gives me proper result but i want to get result from hibernate entities. Please give me solution for below query:
SELECT * FROM fscassets.asset_master a left join
fscassets.asset_make_master b on a.make=b.id;
/* * To change this license header, choose License Headers in Project
Properties. * To change this template file, choose Tools | Templates
* and open the template in the editor. */ package > >
/** * * #author Amol */
#Entity #Table(name = "asset_master")
public class AssetMaster implements Serializable {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
#Column(name = "make", nullable = false)
private int make;
#Column(name = "serialno", nullable = false)
private String serialno;
#Column(name = "specs", nullable = false)
private String specs;
#Column(name = "model", nullable = false)
private String model;
#Column(name = "quantity", nullable = false)
private int quantity;
#Column(name = "purchasedate", nullable = false)
private String purchasedate;
#Column(name = "created_on", nullable = false)
private String createdOnDate;
#Column(name = "remark", nullable = false)
private String remark;
#Column(name = "ipaddress", nullable = false)
private String ipAddress;
#ManyToOne(cascade = CascadeType.ALL)
#Fetch(FetchMode.SELECT)
#JoinColumn(name = "make", updatable = false, insertable = false)
private AssetMakeMaster assetMakeMasterdata;
public AssetMakeMaster getAssetMakeMasterdata() {
return assetMakeMasterdata;
}
public void setAssetMakeMasterdata(AssetMakeMaster assetMakeMasterdata) {
this.assetMakeMasterdata = assetMakeMasterdata;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getCreatedOnDate() {
return createdOnDate;
}
public void setCreatedOnDate(String createdOnDate) {
this.createdOnDate = createdOnDate;
}
public String getIpAddress() {
return ipAddress;
}
public void setIpAddress(String ipAddress) {
this.ipAddress = ipAddress;
}
public int getMake() {
return make;
}
public void setMake(int make) {
this.make = make;
}
public String getSerialno() {
return serialno;
}
public void setSerialno(String serialno) {
this.serialno = serialno;
}
public String getSpecs() {
return specs;
}
public void setSpecs(String specs) {
this.specs = specs;
}
public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
public int getQuantity() {
return quantity;
}
public void setQuantity(int quantity) {
this.quantity = quantity;
}
public String getPurchasedate() {
return purchasedate;
}
public void setPurchasedate(String purchasedate) {
this.purchasedate = purchasedate;
}
public String getRemark() {
return remark;
}
public void setRemark(String remark) {
this.remark = remark;
}
}
/* * To change this license header, choose License Headers in Project
Properties. * To change this template file, choose Tools | Templates
* and open the template in the editor. */ package > >
/** * * #author Amol */
#Entity
#Table(name = "asset_make_master")
public class AssetMakeMaster implements Serializable {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
#NotEmpty
#Column(name = "asset_make_name", unique = true, nullable = false)
private String assetmakename;
#Column(name = "assetgroup", nullable = false)
private int groupid;
#Column(name = "created_on", nullable = false)
private String createdOnDate;
#Column(name = "ipaddress", nullable = false)
private String ipAddress;
#ManyToMany(cascade = CascadeType.ALL, mappedBy = "assetMakeMasterdata")
private List<AssetMaster> assetMakeMasters = new ArrayList<AssetMaster>();
public List<AssetMaster> getAssetMakeMasters() {
return assetMakeMasters;
}
public void setAssetMakeMasters(List<AssetMaster> assetMakeMasters) {
this.assetMakeMasters = assetMakeMasters;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getAssetmakename() {
return assetmakename;
}
public void setAssetmakename(String assetmakename) {
this.assetmakename = assetmakename;
}
public int getGroupid() {
return groupid;
}
public void setGroupid(int groupid) {
this.groupid = groupid;
}
public String getCreatedOnDate() {
return createdOnDate;
}
public void setCreatedOnDate(String createdOnDate) {
this.createdOnDate = createdOnDate;
}
public String getIpAddress() {
return ipAddress;
}
public void setIpAddress(String ipAddress) {
this.ipAddress = ipAddress;
}
}
You can't use (*) in HQL query. If you want non matched values also then select that columns individually you will get values.
the problem is a that you are fetching a AssetMaster that has the AssetMakeMaster id setted, but the AssetMakeMaster with the setted id is not in database anymore.
good day everyone,
i have this project where i use the ModelMapper to mat my entities to DTOs and vise-versa, and also have a class with #ElementCollection relation.
the mapper seems to work fine for all other methods and it just output the entity as i want, however when it comes to delete mapping i get the following error printed along with a 500 http status. here's the error:
"ModelMapper mapping errors:\r\n\r\n1) Converter org.modelmapper.internal.converter.CollectionConverter#ddb7bc7 failed to convert java.util.List to java.util.List.\r\n\r\n1 error"
here is code:
the entity class:
#Entity
#Table(name = "quiz_engines")
#EntityListeners(AuditingEntityListener.class)
#JsonIgnoreProperties(
value = {"lastModified"},
allowGetters = true
)
public class Engine implements Model {
#Id
#Column(name = "engine_id", unique = true, nullable = false)
#GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
#ManyToOne(fetch = FetchType.LAZY,optional = false, targetEntity = com.QCMGenerator.QCMGenerator.Model.Test.class)
#JoinColumn(name = "test_id", referencedColumnName = "test_id", nullable = false, updatable = false)
#OnDelete(action = OnDeleteAction.NO_ACTION)
#JsonIgnore
private Test test;
#Column(name = "quiz_name", nullable = false)
#NotNull
private String name;
#Temporal(TemporalType.TIMESTAMP)
#Column(name = "last_modified", nullable = false)
#LastModifiedDate
private Date lastModified;
#ElementCollection
#CollectionTable(name = "engine_constraints", joinColumns = #JoinColumn(name = "engine_id"))
private List<EngineConstraint> constraints;
public Engine() {
}
public Engine(#NotNull String name, List<EngineConstraint> constraints) {
this.name = name;
this.constraints = constraints;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Test getTest() {
return test;
}
public void setTest(Test test) {
this.test = test;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Date getLastModified() {
return lastModified;
}
public void setLastModified(Date lastModified) {
this.lastModified = lastModified;
}
public List<EngineConstraint> getConstraints() {
return constraints;
}
public void setConstraints(List<EngineConstraint> constraints) {
this.constraints = constraints;
}
}
the DTO class:
public class EngineDTO implements ModelDTO {
private Long id;
#JsonIgnore
private TestDTO test;
private String name;
private Date lastModified;
private List<EngineConstraint> constraints;
public EngineDTO() {
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public TestDTO getTest() {
return test;
}
public void setTest(TestDTO test) {
this.test = test;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Date getLastModified() {
return lastModified;
}
public void setLastModified(Date lastModified) {
this.lastModified = lastModified;
}
public List<EngineConstraint> getConstraints() {
return constraints;
}
public void setConstraints(List<EngineConstraint> constraints) {
this.constraints = constraints;
}
}
the Delete Controller:
#DeleteMapping("/{engineID}")
public ResponseEntity<NonPaginatedResponse> deleteEngine(
#PathVariable(value = "testID") Long testID,
#PathVariable(value = "engineID") Long engineID
){
if(!testRepo.existsById(testID)){
throw new ResourceNotFoundException("No test with the ID '"+testID+"' was found...");
}
return engineRepo.findById(engineID).map(engineFound -> {
engineRepo.delete(engineFound);
return ResponseEntity.status(HttpStatus.OK).body(
ResponseBodyBuilder.getSingleResponse(
convertToDTO(engineFound),
new ModelDTO[]{ convertToDTO(testRepo.findById(testID).get()) },
"delete"
)
);
}
).orElseThrow(
() -> new ResourceNotFoundException("No Engine with the ID '"+engineID+"' was found...")
);
}
hope you guys can help with this one, thank for your time everyone and have a good day.
I have 2 model classes: Project and Task. They have a one-to-many relationship; that is, one Project can have many Tasks and one Task has only one Project.
Project class:
#Entity
#Table(name = "project")
public class Project implements Serializable{
private int project_id;
private int manager_id;
private String name;
private String description;
private Set<Task> Projects = new HashSet<Task>();
#Id
#Column(name = "project_id")
public int getProject_id() {
return project_id;
}
#Column(name = "manager_id")
public int getManager_id() {
return manager_id;
}
#Column(name = "name")
public String getName() {
return name;
}
#Column(name = "description")
public String getDescription() {
return description;
}
public void setProject_id(int project_id) {
this.project_id = project_id;
}
public void setManager_id(int manager_id) {
this.manager_id = manager_id;
}
public void setName(String name) {
this.name = name;
}
public void setDescription(String description) {
this.description = description;
}
#OneToMany(fetch = FetchType.EAGER, mappedBy = "project", cascade = CascadeType.ALL)
public Set<Task> getProjects() {
return Projects;
}
public void setProjects(Set<Task> Projects) {
this.Projects = Projects;
}
}
Task class:
#Entity
#Table(name = "task")
public class Task implements Serializable {
private int task_id;
private Project project;
private int developer_id;
private String date ;
private String hours;
private String description;
private String overtime;
#Id
#Column(name = "task_id")
public int getTask_id() {
return task_id;
}
#Column(name = "developer_id")
public int getDeveloper_id() {
return developer_id;
}
#Column(name = "date")
public String getDate() {
return date;
}
#Column(name = "hours")
public String getHours() {
return hours;
}
#Column(name = "description")
public String getDescription() {
return description;
}
#Column(name = "overtime")
public String getOvertime() {
return overtime;
}
public void setTask_id(int task_id) {
this.task_id = task_id;
}
public void setDeveloper_id(int developer_id) {
this.developer_id = developer_id;
}
public void setDate(String date) {
this.date = date;
}
public void setHours(String hours) {
this.hours = hours;
}
public void setDescription(String description) {
this.description = description;
}
public void setOvertime(String overtime) {
this.overtime = overtime;
}
#ManyToOne(fetch = FetchType.LAZY)
#JoinColumn(name = "project_id")
public Project getProject() {
return project;
}
public void setProject(Project project) {
this.project = project;
}
}
I have used a one-to-many relationship in Hibernate to get a JSON output, but I get the following error:
SyntaxError: JSON.parse: expected ':' after property name in object at line 1 column 81390 of the JSON data
Also there is a huge data set in raw data.
STAFF CLASS
#Entity
#Table(name = "staff", catalog = "nibblrdw_collections")
public class Staff implements java.io.Serializable {
private Integer id;
private StafRole stafRole;
private String stfId;
#NotEmpty(message="please enter staff name")
private String stfName;
#NotEmpty(message="please enter staff Username")
#Size(min = 6, max = 15, message = "Lenght must be between 6 to 15 characters")
private String stfUsrName;
#NotEmpty(message="please enter staff password")
#Size(min = 6, max = 10, message = "Lenght must be between 6 to 10 characters")
private String stfUsrPwd;
private boolean stfVisF;
private Date crtTs;
private Date updTs;
private String crtId;
private String updId;
#NotNull(message="please enter Staff Device ID")
private Integer deviceId;
#Id
#GeneratedValue(strategy = IDENTITY)
#Column(name = "id", unique = true, nullable = false)
public Integer getId() {
return this.id;
}
public void setId(Integer id) {
this.id = id;
}
#JsonBackReference
#ManyToOne(fetch = FetchType.EAGER)
#JoinColumn(name = "stf_role", nullable = false)
public StafRole getStafRole() {
return this.stafRole;
}
public void setStafRole(StafRole stafRole) {
this.stafRole = stafRole;
}
#Column(name = "stf_id", nullable = false)
public String getStfId() {
return this.stfId;
}
public void setStfId(String stfId) {
this.stfId = stfId;
}
#Column(name = "stf_name", nullable = false, length = 65535)
public String getStfName() {
return this.stfName;
}
public void setStfName(String stfName) {
this.stfName = stfName;
}
#Column(name = "stf_usr_name", length = 100)
public String getStfUsrName() {
return this.stfUsrName;
}
public void setStfUsrName(String stfUsrName) {
this.stfUsrName = stfUsrName;
}
#Column(name = "stf_usr_pwd", length = 100)
public String getStfUsrPwd() {
return this.stfUsrPwd;
}
public void setStfUsrPwd(String stfUsrPwd) {
this.stfUsrPwd = stfUsrPwd;
}
#Column(name = "stf_vis_f", nullable = false)
public boolean isStfVisF() {
return this.stfVisF;
}
public void setStfVisF(boolean stfVisF) {
this.stfVisF = stfVisF;
}
#Temporal(TemporalType.TIMESTAMP)
#Column(name = "crt_ts", nullable = false, length = 0)
public Date getCrtTs() {
return this.crtTs;
}
public void setCrtTs(Date crtTs) {
this.crtTs = crtTs;
}
#Temporal(TemporalType.TIMESTAMP)
#Column(name = "upd_ts", nullable = false, length = 0)
public Date getUpdTs() {
return this.updTs;
}
public void setUpdTs(Date updTs) {
this.updTs = updTs;
}
#Column(name = "crt_id", nullable = false, length = 100)
public String getCrtId() {
return this.crtId;
}
public void setCrtId(String crtId) {
this.crtId = crtId;
}
#Column(name = "upd_id", length = 100)
public String getUpdId() {
return this.updId;
}
public void setUpdId(String updId) {
this.updId = updId;
}
#Column(name = "device_id", nullable = false)
public Integer getDeviceId() {
return this.deviceId;
}
public void setDeviceId(Integer deviceId) {
this.deviceId = deviceId;
}
}
StafTyp class
#Entity
#Table(name = "staf_role", catalog = "nibblrdw_collections")
public class StafRole implements java.io.Serializable {
private Integer id;
private String roleDesc;
private String crtId;
private Date crtTs;
private String updId;
private Date updTs;
private Set<Staff> staffs = new HashSet<Staff>(0);
#Id
#GeneratedValue(strategy = IDENTITY)
#Column(name = "id", unique = true, nullable = false)
public Integer getId() {
return this.id;
}
public void setId(Integer id) {
this.id = id;
}
#Column(name = "role_desc", nullable = false, length = 45)
public String getRoleDesc() {
return this.roleDesc;
}
public void setRoleDesc(String roleDesc) {
this.roleDesc = roleDesc;
}
#Column(name = "crt_id", length = 45)
public String getCrtId() {
return this.crtId;
}
public void setCrtId(String crtId) {
this.crtId = crtId;
}
#Temporal(TemporalType.TIMESTAMP)
#Column(name = "crt_ts", nullable = false, length = 0)
public Date getCrtTs() {
return this.crtTs;
}
public void setCrtTs(Date crtTs) {
this.crtTs = crtTs;
}
#Column(name = "upd_id", length = 45)
public String getUpdId() {
return this.updId;
}
public void setUpdId(String updId) {
this.updId = updId;
}
#Temporal(TemporalType.TIMESTAMP)
#Column(name = "upd_ts", nullable = false, length = 0)
public Date getUpdTs() {
return this.updTs;
}
public void setUpdTs(Date updTs) {
this.updTs = updTs;
}
#JsonManagedReference
#OneToMany(fetch = FetchType.EAGER, mappedBy = "stafRole")
public Set<Staff> getStaffs() {
return this.staffs;
}
public void setStaffs(Set<Staff> staffs) {
this.staffs = staffs;
}
}
CONTROLLER
#RequestMapping(value="loginmob", method = RequestMethod.GET)
public #ResponseBody Object test() {
LoginModel login=new LoginModel();
login.setName("report");
login.setPassword("report123");
JSONObject obj = new JSONObject();
if(!login.getName().isEmpty() & !login.getPassword().isEmpty()){
Staff staff=((StaffHomeService) staffService).login(login.getName(), login.getPassword());
System.out.println(staff.getStfUsrName()+" "+staff.getStfUsrPwd());
//logs exception
if(staff.getStfUsrName()!=null){
StafRole sr=staff.getStafRole();
System.out.println(sr.getRoleDesc());
obj.put("id", staff.getId());
obj.put("stf_name", staff.getStfName());
return staff;
}
}
return obj;
}
JSON OBJECT IN URL
{"id":2,"stfId":"2","stfName":"Admin","stfUsrName":"report","stfUsrPwd":"report123","stfVisF":true,"crtTs":1421048214000,"updTs":1422471300000,"crtId":"admin","updId":"null","deviceId":1}
Here my problem is StafTyp is not serializing in to json object. What changes need to do to get StafTyp object to Json?
You switched JSON annotations on Staff and StaffRole.
Staff#getStafRole() should be annotated with #JsonManagedReference, and StafRole#getStaffs() should be annotated with #JsonBackReference. This way staff -> stafRole will be serialized to JSON, and staff -> staffRole -> staffs won't, which is what you need.
How to join newMap detals in custMap.
Map<String, Customer> custMap= new HashMap<String,Customer>();
Map<String, DoCustomer> newMap= new HashMap<String,DoCustomer>();
for (Map.Entry<String, DoCustomer> cust: newMap.entrySet()) {
custMap.put(cust.getKey(),cust.getValue());
}
public class DoCustomer {
private Long id;
private String custName;
private String description;
private String status;
private List<DoCustomerBranch> doCustomerBranch=new ArrayList<DoCustomerBranch>
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getCustName() {
return custName;
}
public void setCustName(String custName) {
this.custName = custName;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
getter/setters of doCustomerBranch
}
#Entity
#Table(name = "CUSTOMER")
public class Customer implements Serializable{
private static final long serialVersionUID = 1L;
private Long id;
private String custName;
private String description;
private String createdBy;
private Date createdOn;
private String updatedBy;
private Date updatedOn;
private Set<CustomerBranch> customerBranch=new HashSet<CustomerBranch>
#Id
#GeneratedValue(generator = "CUSTOMER_SEQ")
#SequenceGenerator(name = "CUSTOMER_SEQ", sequenceName = "CUSTOMERN_SEQ", allocationSize = 1)
#Column(name = "ID")
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
#Column(name = "CUST_NAME",nullable=false)
public String getCustName() {
return custName;
}
public void setCustName(String custName) {
this.custName = custName;
}
#Column(name = "DESCRIPTION")
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
#Column(name = "CREATED_BY", length = 50)
public String getCreatedBy() {
return createdBy;
}
public void setCreatedBy(String createdBy) {
this.createdBy = createdBy;
}
#Temporal(TemporalType.TIMESTAMP)
#Column(name = "CREATED_ON")
public Date getCreatedOn() {
return createdOn;
}
public void setCreatedOn(Date createdOn) {
this.createdOn = createdOn;
}
#Column(name = "UPDATED_BY", length = 50)
public String getUpdatedBy() {
return updatedBy;
}
public void setUpdatedBy(String updatedBy) {
this.updatedBy = updatedBy;
}
#Temporal(TemporalType.TIMESTAMP)
#Column(name = "UPDATED_ON")
public Date getUpdatedOn() {
return updatedOn;
}
public void setUpdatedOn(Date updatedOn) {
this.updatedOn = updatedOn;
}
#OneToMany(cascade = { CascadeType.PERSIST, CascadeType.REMOVE }, fetch = FetchType.LAZY, mappedBy = "customer")
public Set<CustomerBranch> getCustomerBranch() {
return customerBranch;
}
public void setCustomerBranch(Set<CustomerBranch> customerBranch) {
this.customerBranch = customerBranch;
}
}
CustomerBranch
#Entity
#Table(name = "CUSTOMER_BRANCH")
public class CustomerBranch implements Serializable{
#Id
#GeneratedValue(generator = "CUSTOMER_BRANCH_SEQ")
#SequenceGenerator(name = "CUSTOMER_BRANCH_SEQ", sequenceName = "CUSTOMER_BRANCH_SEQ", allocationSize = 1)
#Column(name = "ID")
private Long id;
private String branchName;
private String branchAddress;
private Customer customer;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
#Column(name = "BRANCH_NAME",nullable=false)
public String getBranchName() {
return branchName;
}
#ManyToOne(fetch = FetchType.LAZY)
#JoinColumn(name = "MOBEE_CUSTOMER")
public Customer getCustomer() {
return customer;
}
public void setCustomer(Customer customer) {
this.customer = customer;
}
}
The problem with your code is that you want to put a DoCustomer in a Customer container. It only works if DoCustomer is a subclass of Customer.
Edit 1: You could use BeanUtils to convert a DoCustomer into a Customer. Here is a good tutorial.
Do you mean:
custMap.putAll(newMap)
As everyone else has pointed out, we need to know what DoCustomer is to be able to help.
But, from what you have given us, I'd suggest casting each DoCustomer to a Customer or, more correctly, making a new Customer from the fields of each DoCustomer.
Something like:
custMap.put(cust.getKey(), new Customer(cust.getValue().getId(), cust.getValue().getCustName(), and so on..));
inside your for loop.
I can see the customer class defined you have provided doesn't have a constructor, so naturally you would have to add one to it