EL1008E: Property or field 'isAvailable' cannot be found on object of type 'com.inventory.domain.Item' - maybe not public or not valid? - spring-boot

I have one boolean field in item bean all other fields are populating but only isAvailable is not populating in ui using thymeleaf I am getting error as property can't not found I am not getting the root cause
Is there any specific way to read the boolean field in thymeleaf. because in .html page when i tried to read boolean value st.isAvailable its throwing error in backend property not found hence not populating value
Item Bean
package com.inventory.domain;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;
#Entity
#Table(name = "item")
public class Item {
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
private int item_id;
#ManyToOne
#JoinColumn(name = "category_id")
private Category categoryId;
#Column(name = "item_name",unique = true)
private String itemName;
#Column(name = "current_stock_quantity")
private double currentStockQuantity;
public double getCurrentStockQuantity() {
return currentStockQuantity;
}
#Column(name = "unit")
#Enumerated(EnumType.STRING)
private ItemWeightUnit unit;
#Column(name = "current_purchase_price")
private double currentPurchasePrice;
#Column(name = "is_available")
private boolean isAvailable;
#Column(name = "is_active")
private boolean isActive;
#Column(name = "item_description")
#Lob
private String itemDescription;
#OneToMany(mappedBy = "item",cascade = CascadeType.ALL)
private List<Vendor> vendor = new ArrayList<Vendor>();
#OneToMany(mappedBy = "item",cascade = CascadeType.ALL)
#OrderBy("transaction_date ASC")
private SortedSet<ItemTransaction> itemTransaction=new TreeSet<ItemTransaction>();
#OneToMany(mappedBy = "item",cascade = CascadeType.ALL)
#OrderBy("date ASC")
private SortedSet<PricingHistory> priceHistory=new TreeSet<PricingHistory>();
public SortedSet<ItemTransaction> getItemTransaction() {
return itemTransaction;
}
public void setItemTransaction(SortedSet<ItemTransaction> itemTransaction) {
this.itemTransaction = itemTransaction;
}
public void setCurrentStockQuantity(double currentStockQuantity) {
this.currentStockQuantity = currentStockQuantity;
}
public List<Vendor> getVendor() {
return vendor;
}
public void setVendor(List<Vendor> vendor) {
this.vendor = vendor;
}
public int getItem_id() {
return item_id;
}
public void setItem_id(int item_id) {
this.item_id = item_id;
}
public Category getCategoryId() {
return categoryId;
}
public void setCategoryId(Category categoryId) {
this.categoryId = categoryId;
}
public String getItemName() {
return itemName;
}
public void setItemName(String itemName) {
this.itemName = itemName;
}
public String getItemDescription() {
return itemDescription;
}
public void setItemDescription(String itemDescription) {
this.itemDescription = itemDescription;
}
public boolean isAvailable() {
return isAvailable;
}
public void setAvailable(boolean isAvailable) {
this.isAvailable = isAvailable;
}
public boolean isActive() {
return isActive;
}
public void setActive(boolean isActive) {
this.isActive = isActive;
}
public ItemWeightUnit getUnit() {
return unit;
}
public void setUnit(ItemWeightUnit unit) {
this.unit = unit;
}
public double getCurrentPurchasePrice() {
return currentPurchasePrice;
}
public void setCurrentPurchasePrice(double currentPurchasePrice) {
this.currentPurchasePrice = currentPurchasePrice;
}
public SortedSet<PricingHistory> getPriceHistory() {
return priceHistory;
}
public void setPriceHistory(SortedSet<PricingHistory> priceHistory) {
this.priceHistory = priceHistory;
}
}
<tbody>
<tr th:each="st,iter : ${items}">
<td th:text="${iter.count}"></td>
<td th:text="${st.itemName}"></td>
<td th:text="${st.currentStockQuantity}"></td>
<td th:text="${st.unit}"></td>
<td th:text="${st.currentPurchasePrice}"></td>
<div th:if="${st.isAvailable} == true">
<td>Yes</td>
</div>
<div th:unless="${st.isAvailable} == false">
<td>No</td>
</div>
<td>
<a href="#" class="btn btn-default" th:href="#{/karyawan/form(id=${st.id})}"
title="Edit Data"><span class="glyphicon glyphicon-edit"></span></a>
<a href="#" class="btn btn-default" th:href="#{/karyawan/delete(id=${st.id})}"
title="Delete Data"><span class="glyphicon glyphicon-trash"></span></a>
</td>
</tr>
<tr th:if="${#lists.isEmpty(items.content)}">
<td colspan="13" class="text-center">Data Not Found</td>
</tr>
</tbody>

Getter and Setter for isAvailable method is not correct, when deserializing and serializing then you need to update them.
public boolean getIsAvailable() {
return isAvailable;
}
public void setIsAvailable(boolean isAvailable) {
this.isAvailable = isAvailable;
}

Related

Calling a one to many list in a saved entity returns null

When I check an entities contents right after saving it, everything appears normal, but any other time and the mapped entities in it are all null. Both checks are done by getting it through its repository.
Ad
package com.stevan.madsapp.entities;
import com.fasterxml.jackson.annotation.JsonIgnore;
import javax.jws.soap.SOAPBinding;
import javax.persistence.*;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
#Entity(name = "ad")
#NamedStoredProcedureQuery(
name = "ad.getAds",
procedureName = "get_ads",
parameters = { #StoredProcedureParameter(mode = ParameterMode.IN, name = "param1", type = String.class) }
)
public class Ad {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
#Column(name = "name", nullable = false)
private String name;
#OneToMany(mappedBy = "ad")
private List<Question> questions = new ArrayList<>();
#ManyToOne
#JoinColumn(name = "author")
private UserDetails author;
#ManyToMany
#JoinTable(
name = "user_details_ad",
joinColumns = #JoinColumn(name = "user_details_id"),
inverseJoinColumns = #JoinColumn(name = "ad_id")
)
private Set<UserDetails> usersFinished = new HashSet<>();
#ManyToOne
#JoinColumn(name = "country")
private Country country;
#ManyToOne
#JoinColumn(name = "job")
private Job job;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public List<Question> getQuestions() {
return questions;
}
public void setQuestions(List<Question> questions) {
this.questions = questions;
}
public UserDetails getAuthor() {
return author;
}
public void setAuthor(UserDetails author) {
this.author = author;
}
public Set<UserDetails> getUsersFinished() {
return usersFinished;
}
public void setUsersFinished(Set<UserDetails> usersFinished) {
this.usersFinished = usersFinished;
}
public Country getCountry() {
return country;
}
public void setCountry(Country country) {
this.country = country;
}
public Job getJob() {
return job;
}
public void setJob(Job job) {
this.job = job;
}
}
Question
package com.stevan.madsapp.entities;
import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;
#Entity(name = "question")
public class Question {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
#Column(nullable = false)
private String type;
#Column(nullable = false)
private String question;
#OneToMany(mappedBy = "question")
private List<McOption> radioOptions = new ArrayList<>();
#OneToMany(mappedBy = "question")
private List<McOption> checkboxOptions = new ArrayList<>();
#ManyToOne
#JoinColumn(name = "ad_id")
private Ad ad;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getQuestion() {
return question;
}
public void setQuestion(String question) {
this.question = question;
}
public List<McOption> getRadioOptions() {
return radioOptions;
}
public void setRadioOptions(List<McOption> radioOptions) {
this.radioOptions = radioOptions;
}
public List<McOption> getCheckboxOptions() {
return checkboxOptions;
}
public void setCheckboxOptions(List<McOption> checkboxOptions) {
this.checkboxOptions = checkboxOptions;
}
}
AdService
package com.stevan.madsapp.services;
import com.stevan.madsapp.entities.*;
import com.stevan.madsapp.repositories.AdRepository;
import com.stevan.madsapp.security.components.TokenIdCheck;
import com.stevan.madsapp.web.dto.AdDTO;
import com.stevan.madsapp.web.dto.QuestionDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.persistence.criteria.CriteriaBuilder;
import java.util.*;
#Service
public class AdService {
#Autowired
private AdRepository adRepository;
#Autowired
private QuestionService questionService;
#Autowired
private JobService jobService;
#Autowired
private CountryService countryService;
#Autowired
private UserDetailsService userDetailsService;
public List<AdDTO> getAds(Integer id)
{
UserDetails user = userDetailsService.getUserDetails(id);
Job job = user.getJob();
Country country = user.getCountry();
List<Ad> jobAds = job.getAds();
List<Ad> countryAds = country.getAds();
List<Ad> commonAds = new ArrayList<Ad>(jobAds);
commonAds.retainAll(countryAds);
return convertListToDTO(commonAds);
}
public Ad store(AdDTO ad, Integer id) {
Ad newAd = new Ad();
newAd.setName(ad.getName());
List<Question> newQuestions = new ArrayList<>();
for(Question question : ad.getQuestions())
{
Question newQuestion = questionService.store(question);
newQuestions.add(newQuestion);
}
newAd.setQuestions(newQuestions);
newAd.setAuthor(userDetailsService.getUserDetails(id));
newAd.setJob(jobService.getJob(ad.getJobId()));
newAd.setCountry(countryService.getCountry(ad.getCountryId()));
adRepository.save(newAd);
System.out.println(adRepository.getById(newAd.getId()).getQuestions());
return newAd;
}
public Ad getAd(Integer id)
{
return adRepository.getById(id);
}
public AdDTO requestAd(Integer adId, Integer userId)
{
Ad ad = getAd(adId);
UserDetails user = userDetailsService.getUserDetails(userId);
if(ad.getJob() != user.getJob() || ad.getCountry() != user.getCountry())
{
return null;
}
return convertToDTO(ad);
}
public List<AdDTO> convertListToDTO(List<Ad> ads)
{
List<AdDTO> adDTOS = new ArrayList<>();
for(Ad ad: ads)
{
AdDTO newAdDTO = convertToDTO(ad);
adDTOS.add(newAdDTO);
}
return adDTOS;
}
public AdDTO convertToDTO(Ad ad)
{
AdDTO newAdDTO = new AdDTO();
newAdDTO.setId(ad.getId());
newAdDTO.setName(ad.getName());
newAdDTO.setQuestions(ad.getQuestions());
newAdDTO.setJobId(ad.getJob().getId());
newAdDTO.setCountryId(ad.getCountry().getId());
return newAdDTO;
}
}
QuestionService
package com.stevan.madsapp.services;
import com.stevan.madsapp.entities.Ad;
import com.stevan.madsapp.entities.McOption;
import com.stevan.madsapp.entities.Question;
import com.stevan.madsapp.repositories.QuestionRepository;
import com.stevan.madsapp.web.dto.McOptionDTO;
import com.stevan.madsapp.web.dto.QuestionDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
#Service
public class QuestionService {
#Autowired
private QuestionRepository questionRepository;
#Autowired
private McOptionService mcOptionService;
public Question store(Question question)
{
Question newQuestion = new Question();
newQuestion.setQuestion(question.getQuestion());
newQuestion.setType(question.getType());
if (newQuestion.getType().equals("radio"))
{
List<McOption> newMcOptions = new ArrayList<>();
for (McOption mcOption : question.getRadioOptions())
{
McOption newMcOption = mcOptionService.store(mcOption);
newMcOptions.add(newMcOption);
}
newQuestion.setRadioOptions(newMcOptions);
}
else if(newQuestion.getType().equals("checkbox"))
{
List<McOption> newMcOptions = new ArrayList<McOption>();
for (McOption mcOption : question.getCheckboxOptions())
{
McOption newMcOption = mcOptionService.store(mcOption);
newMcOptions.add(newMcOption);
}
newQuestion.setCheckboxOptions(newMcOptions);
}
questionRepository.save(newQuestion);
return newQuestion;
}
}
(This one just in case I missed something)
AdController
package com.stevan.madsapp.web.controllers;
import com.stevan.madsapp.entities.Ad;
import com.stevan.madsapp.exceptions.ValidationException;
import com.stevan.madsapp.security.components.TokenIdCheck;
import com.stevan.madsapp.services.AdService;
import com.stevan.madsapp.validators.AdValidator;
import com.stevan.madsapp.web.dto.AdDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.BeanPropertyBindingResult;
import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.web.bind.annotation.*;
import java.util.List;
#RestController
#RequestMapping(value = "/api/forms", produces = MediaType.APPLICATION_JSON_VALUE)
#CrossOrigin(origins = "http://localhost:4200")
public class AdController {
#Autowired
private AdService adService;
#Autowired
private AdValidator adValidator;
#Autowired
private TokenIdCheck tokenIdCheck;
#GetMapping(value = "/statuscheck")
private ResponseEntity<Object> check()
{
return new ResponseEntity<>(HttpStatus.OK);
}
#GetMapping
private ResponseEntity<List<AdDTO>> getAllAds(#RequestHeader("id") Integer id)
{
List<AdDTO> adList = adService.getAds(id);
return new ResponseEntity<>(adList, HttpStatus.OK);
}
#GetMapping(value = "/request")
private ResponseEntity<AdDTO> getAd(#RequestHeader("adId") Integer adId,
#RequestHeader("Authorization") String token,
#RequestHeader("id") Integer id)
{
if(tokenIdCheck.check(id, token))
{
AdDTO adDTO = adService.requestAd(adId, id);
if(adDTO != null)
{
return new ResponseEntity<>(adDTO, HttpStatus.OK);
}
}
return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
}
#PostMapping
private ResponseEntity<AdDTO> uploadAd(#RequestBody AdDTO adDTO,
#RequestHeader("id") Integer id) throws ValidationException
{
Errors optionalErrors = new BeanPropertyBindingResult(adDTO, "adDTO");
ValidationUtils.invokeValidator(adValidator, adDTO, optionalErrors);
if(optionalErrors.hasErrors())
{
throw new ValidationException(optionalErrors);
}
Ad newAd = adService.store(adDTO, id);
return newAd != null
? new ResponseEntity<>(adService.convertToDTO(newAd), HttpStatus.OK)
: new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
}
To clarify more thouroughly now, when I sysout an Ads questions, right after I store it, it shows that it has some questions, but when I do it when requesting an Ad later, it shows an empty list. In mysql they have their apropriate foreign keys.
I had to save the ad_id in the Question entity before I added that question to the questions_id list in the Ad entity. The only problem I had with that is that in order to set the parent Ad as the ad_id in every question, I needed to save the Ad itself first.
Here are the changes:
In AdService:
public Ad store(AdDTO ad, Integer id) {
Ad newAd = new Ad();
newAd.setName(ad.getName());
newAd.setAuthor(userDetailsService.getUserDetails(id));
newAd.setJob(jobService.getJob(ad.getJobId()));
newAd.setCountry(countryService.getCountry(ad.getCountryId()));
adRepository.save(newAd);
Set<Question> newQuestions = newAd.getQuestions();
for(Question question : ad.getQuestions())
{
Question newQuestion = questionService.store(question, newAd);
newQuestions.add(newQuestion);
}
adRepository.save(newAd);
System.out.println(adRepository.getById(newAd.getId()).getQuestions());
return newAd;
}
I just added another adRepository.save(newAd) before cycling through questions, and changed the store Question method to take in an Ad, which I used to set the ad_id in questions.
and in QuestionService:
public Question store(Question question, Ad newAd)
{
Question newQuestion = new Question();
newQuestion.setQuestion(question.getQuestion());
newQuestion.setType(question.getType());
newQuestion.setAd(newAd);
if (newQuestion.getType().equals("radio"))
{
List<McOption> newMcOptions = new ArrayList<>();
for (McOption mcOption : question.getRadioOptions())
{
McOption newMcOption = mcOptionService.store(mcOption);
newMcOptions.add(newMcOption);
}
newQuestion.setRadioOptions(newMcOptions);
}
else if(newQuestion.getType().equals("checkbox"))
{
List<McOption> newMcOptions = new ArrayList<McOption>();
for (McOption mcOption : question.getCheckboxOptions())
{
McOption newMcOption = mcOptionService.store(mcOption);
newMcOptions.add(newMcOption);
}
newQuestion.setCheckboxOptions(newMcOptions);
}
questionRepository.save(newQuestion);
return newQuestion;
}

unable to display data on broswer using spring hibernate.below is my code and output

Unable to display data on broswer using spring hibernate.below is my code and output..
Class: CustomerController
package com.luv2code.springdemo.controller;
import com.luv2code.springdemo.DAO.CustomerDAO;
import com.luv2code.springdemo.entity.Customer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import java.util.List;
#Controller
#RequestMapping("/customer")
public class CustomerController {
#Autowired
private CustomerDAO customerDAO;
#RequestMapping("/list")
public String listCustomer(Model theModel){
List<Customer> theCustomers = customerDAO.getCustomers();
theModel.addAttribute("customers", theCustomers);
System.out.println(theCustomers);
return "list-customer";
}
}
Class: CustomerDAO Implementation
package com.luv2code.springdemo.DAO;
import com.luv2code.springdemo.entity.Customer;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.query.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
#Repository
public class CustomerDAOImpl implements CustomerDAO {
#Autowired
private SessionFactory sessionFactory;
#Override
#Transactional
public List<Customer> getCustomers() {
Session getSession = sessionFactory.getCurrentSession();
Query<Customer> theCustomers = getSession.createQuery("from Customer", Customer.class);
List<Customer> customers = theCustomers.getResultList();
return customers;
}
}
Class: Customer mapping to database
package com.luv2code.springdemo.entity;
import javax.persistence.*;
#Entity
#Table(name="customer")
public class Customer {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
#Column(name = "id")
private int id;
#Column(name = "first_name")
private String firstName;
#Column(name="last_name")
private String lastName;
#Column(name = "email")
private String email;
public Customer() {
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
#Override
public String toString() {
return "Customer{" +
"id=" + id +
", firstName='" + firstName + '\'' +
", lastName='" + lastName + '\'' +
", email='" + email + '\'' +
'}';
}
}
jsp page..
<table>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Email</th>
</tr>
<!-- loop over and print our customers -->
<c:forEach var="tempCustomer" items="${customers}">
<tr>
<td> ${tempCustomer.firstName} </td>
<td> ${tempCustomer.lastName} </td>
<td> ${tempCustomer.email} </td>
</tr>
</c:forEach>
</table>
Output
You're probably using an old version of jstl where expressions must be called witch <c:out/> tag.
Try the following in your jsp
<td><c:out value="${tempCustomer.firstName}" /></td>
<td><c:out value="${tempCustomer.lastName}" /></td>
<td><c:out value="${tempCustomer.email}" /></td>

404 Error in Associate Mapping

I am developing shopping cart web app which have completed up to display product to add cart. I am trying to map every customer (One To One) to cart Entity, cart entity (one to one) to cart item Entity, and cart item entity (Many to One) to Product entity. But I got a 404 error.
Please check my code below.
Mapping plan:
Customer-----one to one------>Cart----one to one---->Cart Item----Many to one--->Product
Customer Entity
package com.model;
import javax.persistence.CascadeType;
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.OneToOne;
import javax.validation.constraints.NotNull;
import org.hibernate.validator.constraints.NotEmpty;
#Entity
public class Customer {
#Id #GeneratedValue(strategy=GenerationType.AUTO)
#Column(name="Cid")
private int customerId;
#Column(name="password")
#NotEmpty(message="Name is mandatory")
private String password;
#Column(name="Email")
#NotEmpty(message="Name is mandatory")
private String email;
#NotEmpty(message="First Name is mandatory")
#Column(name="firstname")
private String firstName;
#NotEmpty(message="Last Name is mandatory")
#Column(name="lastname")
private String lastName;
#Column(name="Mobile")
#NotEmpty(message="Mobile is mandatory")
private String mobile;
#ManyToOne(cascade=CascadeType.ALL)
#JoinColumn(name="address_id")
private Address delAdderss;
private boolean enabled;
private String role;
#OneToOne(cascade=CascadeType.ALL)
#JoinColumn(name="cart_id")
private Cart cart;
public Cart getCart() {
return cart;
}
public void setCart(Cart cart) {
this.cart = cart;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getMobile() {
return mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
public int getCustomerId() {
return customerId;
}
public void setCustomerId(int name) {
this.customerId = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public boolean isEnabled() {
return enabled;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
public String getRole() {
return role;
}
public void setRole(String role) {
this.role = role;
}
public Address getDelAdderss() {
return delAdderss;
}
public void setDelAdderss(Address delAdderss) {
this.delAdderss = delAdderss;
}
}
Cart Entity
package com.model;
import javax.persistence.CascadeType;
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.OneToOne;
#Entity
public class Cart {
#Id
#GeneratedValue(strategy=GenerationType.AUTO)
private int cart_id;
#Column
private double total;
#Column
#OneToOne(cascade=CascadeType.ALL)
#JoinColumn(name="item_id")
private CartItem cartItem;
public int getCart_id() {
return cart_id;
}
public void setCart_id(int cart_id) {
this.cart_id = cart_id;
}
public double getTotal() {
return total;
}
public void setTotal(double total) {
this.total = total;
}
public CartItem getCartItem() {
return cartItem;
}
public void setCartItem(CartItem cartItem) {
this.cartItem = cartItem;
}
}
Cart Item Entity
package com.model;
import java.util.List;
import javax.persistence.CascadeType;
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.OneToMany;
import javax.persistence.OneToOne;
#Entity
public class CartItem {
#Id
#GeneratedValue(strategy=GenerationType.AUTO)
private int item_id;
#ManyToOne(cascade=CascadeType.ALL)
#JoinColumn(name="id")
private List<Product> product;
public int getItem_id() {
return item_id;
}
public void setItem_id(int item_id) {
this.item_id = item_id;
}
public List<Product> getProduct() {
return product;
}
public void setProduct(List<Product> product) {
this.product = product;
}
}
Product Entity
package com.model;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Transient;
import org.springframework.web.multipart.MultipartFile;
#Entity
public class Product {
#Id #GeneratedValue(strategy=GenerationType.AUTO)
private int id;
#Column
private String product_Name;
#Column
private String descripction;
#Column
private int price;
#Column
private Date mfg_Date;
#Transient
private MultipartFile image;
public MultipartFile getImage() {
return image;
}
public void setImage(MultipartFile image) {
this.image = image;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getProduct_Name() {
return product_Name;
}
public void setProduct_Name(String product_Name) {
this.product_Name = product_Name;
}
public String getDescripction() {
return descripction;
}
public void setDescripction(String descripction) {
this.descripction = descripction;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
public Date getMfg_Date() {
return mfg_Date;
}
public void setMfg_Date(Date mfg_Date) {
this.mfg_Date = mfg_Date;
}
}
Why are you using cart item entity, According to me it should be Customer one on one with Cart, And a Cart as one to many with Products. I think there is no need for cart items table/entity.

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.

I want to fetch my product details in database but it throws excepion org.hibernate.hql.internal.ast.QuerySyntaxException: Product is not mapped

I'm keep getting an exception. I've tried to solve this problem for a few days now...
Please help me...
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.hibernate.hql.internal.ast.QuerySyntaxException: Product is not mapped [from Product]
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:981)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:860)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:845)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
This is my ProductController
package com.controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
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.servlet.ModelAndView;
import com.model.Categories;
import com.model.Product;
import com.service.ProductService;
#Controller
public class ProductController {
#Autowired
private ProductService productService;
// Getters and Setters
public ProductService getProductService() {
return productService;
}
public void setProductService(ProductService productService) {
this.productService = productService;
}
// Request Mapping
#RequestMapping("/getAllProducts")
public ModelAndView getAllProducts() {
List<Product> products = productService.getAllProducts();
return new ModelAndView("productList", "products", products);
}
#RequestMapping("getProductById/{productId}")
public ModelAndView getProductById(#PathVariable(value = "productId") String productId) {
Product product = productService.getProductById(productId);
return new ModelAndView("productPage", "productObj", product);
}
#RequestMapping("/delete/{productId}")
public String deleteProduct(#PathVariable(value = "productId") String productId) {
productService.deleteProduct(productId);
return "redirect:/getAllProducts";
}
#RequestMapping(value = "/admin/product/addProduct", method = RequestMethod.GET)
public String getProductForm(Model model) {
Product product = new Product();
Categories category = new Categories();
category.setCategoryId("1");
product.setProductCategory(category);
model.addAttribute("productFormObj", product);
return "productForm";
}
#RequestMapping(value = "/admin/product/addProduct", method = RequestMethod.POST)
public String addProduct(#ModelAttribute(value = "productFormObj") Product product) {
productService.addProduct(product);
return "redirect:/getAllProducts";
}
}
This is my ProductClass
package com.model;
import java.util.Locale.Category;
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 = "product")
public class Product {
#Id
#Column
#GeneratedValue(strategy = GenerationType.AUTO)
private String productId;
#Column
private String productDescription;
#Column
private String productManufacturer;
#Column
private String productName;
#Column
private double productPrice;
#Column(name="stockunit")
private String unitStock;
#ManyToOne
#JoinColumn(name="categoryId")
private Categories productCategory;
// Getters and Setter
public String getProductId() {
return productId;
}
public Categories getProductCategory() {
return productCategory;
}
public String getProductDescription() {
return productDescription;
}
public String getProductManufacturer() {
return productManufacturer;
}
public String getProductName() {
return productName;
}
public double getProductPrice() {
return productPrice;
}
public String getUnitStock() {
return unitStock;
}
public void setProductId(String productId) {
this.productId = productId;
}
public void setProductCategory(Categories category) {
this.productCategory = category;
}
public void setProductDescription(String productDescription) {
this.productDescription = productDescription;
}
public void setProductManufacturer(String productManufacturer) {
this.productManufacturer = productManufacturer;
}
public void setProductName(String productName) {
this.productName = productName;
}
public void setProductPrice(double productPrice) {
this.productPrice = productPrice;
}
public void setUnitStock(String unitStock) {
this.unitStock = unitStock;
}
//Constructors
public Product(String productId, Categories productCategory, String productDescription, String productManufacturer,
String productName, double productPrice, String unitStock) {
super();
this.productId = productId;
this.productCategory = productCategory;
this.productDescription = productDescription;
this.productManufacturer = productManufacturer;
this.productName = productName;
this.productPrice = productPrice;
this.unitStock = unitStock;
}
public Product(){
}
}
This is my application Context
<!-- for Entity Classes annotated Classes package -->
<property name="packagesToScan">
<list>
<value>com.model.Product</value>
<value>com.model.Categories</value>
</list>
</property>
</bean>
My Category Class
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
#Entity
#Table(name = "categories")
public class Categories {
#Id
private String categoryId;
#Column
private String Categories;
#OneToMany(mappedBy = "categories")
private List<Product> product;
//And Respective Getters and Setters
ProductList page
<tbody>
<c:forEach items="${products}" var="prod">
<tr>
<td>${prod.productId}</td>
<td>${prod.productCategory}</td>
<td>${prod.productName}</td>
<td>${prod.productPrice}</td>
<td>${prod.unitStock}</td>
<td>${prod.productDescription}</td>
<td>${prod.productManufacturer}</td>
<td>
<span class="glyphicon glyphicon-info"></span>
<span class="glyphicon glyphicon-trash"></span>
</td>
</tr>
</c:forEach>
After a long analyse i have found the solution for this problem
I have modified some code in my daoImpl.
this is older code.
List<Product> products = session.createQuery("from Product").list();
I have changed this to
List<Product> products = session.createCriteria(Product.class).list();
And some changes in appication Context as #v.ladynev said :
<property name="packagesToScan">
<list>
<value>com.model</value>
</list>
</property>
You should specify a package here, not classes
<property name="packagesToScan">
<list>
<value>com.model</value>
</list>
</property>

Resources