Not able to save child table data using hibernate - java

I am Developing Web service, in this there is scenario of parent child tables as below
**Parent Table**
#Entity
#Table(name = "INSTITUTE_LIST_MST")
#JsonIgnoreProperties(ignoreUnknown = true)
public class InstituteInfoMatster
{
#Id
#Column(name = "LIST_ID")
#GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer listId;
#Column(name = "LIST_DESC")
private String description;
#Column(name = "LIST_VALUE")
private String value;
#Column(name = "URL")
private String url;
#Column(name = "LOGO", unique = false, length = 100000)
private byte[] logo;
#OneToMany(fetch = FetchType.EAGER, mappedBy = "instituteInfotMaster", cascade = CascadeType.ALL)
private List<InstituteInfoDetails> instituteInfoDetails = new ArrayList<InstituteInfoDetails>();
#Column(name = "CREATED_DT")
#Temporal(TemporalType.TIMESTAMP)
private Date createdDate = new Date();
#Column(name = "CREATED_BY")
private String createdBy;
#Column(name = "UPDATED_DT")
#Temporal(TemporalType.TIMESTAMP)
private Date updatedDate;
#Column(name = "UPDATED_BY")
private String updatedBy;
#Column(name = "RECORD_STATUS")
private String recordStatus = "A";
public Integer getListId()
{
return listId;
}
public void setListId(Integer listId)
{
this.listId = listId;
}
public String getDescription()
{
return description;
}
public void setDescription(String description)
{
this.description = description;
}
public String getValue()
{
return value;
}
public void setValue(String value)
{
this.value = value;
}
public Date getCreatedDate()
{
return createdDate;
}
public void setCreatedDate(Date createdDate)
{
this.createdDate = createdDate;
}
public String getCreatedBy()
{
return createdBy;
}
public void setCreatedBy(String createdBy)
{
this.createdBy = createdBy;
}
public Date getUpdatedDate()
{
return updatedDate;
}
public void setUpdatedDate()
{
this.updatedDate = new Date();
}
public String getUpdatedBy()
{
return updatedBy;
}
public void setUpdatedBy(String updatedBy)
{
this.updatedBy = updatedBy;
}
public String getRecordStatus()
{
return recordStatus;
}
public void setActiveRecordStatus()
{
this.recordStatus = "A";
}
public void deleteRecord()
{
this.recordStatus = "D";
}
public List<InstituteInfoDetails> getInstituteInfoDetails()
{
return instituteInfoDetails;
}
public void setInstituteInfoDetails(List<InstituteInfoDetails> instituteInfoDetails)
{
this.instituteInfoDetails = instituteInfoDetails;
}
public byte[] getLogo()
{
return logo;
}
public void setLogo(byte[] logo)
{
this.logo = logo;
}
public String getUrl()
{
return url;
}
public void setUrl(String url)
{
this.url = url;
}
#Override
public String toString()
{
return "InstituteInfoMatster [listId=" + listId + ", description=" + description + ", value=" + value + ", url="
+ url + ", logo=" + Arrays.toString(logo) + ", instituteInfoDetails=" + instituteInfoDetails
+ ", createdDate=" + createdDate + ", createdBy=" + createdBy + ", updatedDate=" + updatedDate
+ ", updatedBy=" + updatedBy + ", recordStatus=" + recordStatus + "]";
}
}
Child Table
#Entity
#Table(name = "INSTITUTE_LIST_DETAILS")
public class InstituteInfoDetails
{
#Id
#Column(name = "LIST_DTL_ID")
#GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer listDtlId;
#ManyToOne
#JoinColumn(name = "LIST_ID", nullable = false)
#JsonProperty("instituteInfotMaster")
#JsonBackReference
private InstituteInfoMatster instituteInfotMaster;
#Column(name = "LIST_DTL_VALUE")
private String value;
#Column(name = "LIST_DTL_DESC", length = 5000)
private String description;
#Column(name = "STRING1", length = 5000)
private String string1;
#Column(name = "STRING2", length = 5000)
private String string2;
#Column(name = "STRING3", length = 5000)
private String string3;
#Column(name = "SEQUENCE_NO")
private int sequenceNo;
#Column(name = "NUMBER1")
private Double number1;
#Column(name = "NUMBER2")
private Double number2;
#Column(name = "NUMBER3")
private Double number3;
#Column(name = "DOCUMENT", unique = false, length = 100000)
private byte[] document;
#Column(name = "DOCUMENT_TYPE", length = 1)
private Integer documentType;
#Column(name = "DOCUMENT1", unique = false, length = 100000)
private byte[] document1;
#Column(name = "DOCUMENT1_TYPE", length = 1)
private Integer document1Type;
#Column(name = "DOCUMENT2", unique = false, length = 100000)
private byte[] document2;
#Column(name = "DOCUMENT2_TYPE", length = 1)
private Integer document2Type;
#Column(name = "CREATED_DT")
#Temporal(TemporalType.TIMESTAMP)
private Date createdDate = new Date();
#Column(name = "CREATED_BY")
private String createdBy;
#Column(name = "UPDATED_DT")
#Temporal(TemporalType.TIMESTAMP)
private Date updatedDate;
#Column(name = "UPDATED_BY")
private String updatedBy;
#Column(name = "RECORD_STATUS")
private String recordStatus = "A";
public Integer getListDtlId()
{
return listDtlId;
}
public void setListDtlId(Integer listDtlId)
{
this.listDtlId = listDtlId;
}
public String getValue()
{
return value;
}
public void setValue(String value)
{
this.value = value;
}
public String getDescription()
{
return description;
}
public void setDescription(String description)
{
this.description = description;
}
public InstituteInfoMatster getComListMaster()
{
return instituteInfotMaster;
}
public void setComListMaster(InstituteInfoMatster instituteInfotMaster)
{
this.instituteInfotMaster = instituteInfotMaster;
}
public Date getCreatedDate()
{
return createdDate;
}
public void setCreatedDate()
{
this.createdDate = new Date();
}
public String getCreatedBy()
{
return createdBy;
}
public void setCreatedBy(String createdBy)
{
this.createdBy = createdBy;
}
public Date getUpdatedDate()
{
return updatedDate;
}
public void setUpdatedDate(Date updatedDate)
{
this.updatedDate = updatedDate;
}
public String getUpdatedBy()
{
return updatedBy;
}
public void setUpdatedBy(String updatedBy)
{
this.updatedBy = updatedBy;
}
public String getRecordStatus()
{
return recordStatus;
}
public void setRecordStatus(String recordStatus)
{
this.recordStatus = recordStatus;
}
public InstituteInfoMatster getInstituteInfotMaster()
{
return instituteInfotMaster;
}
public void setInstituteInfotMaster(InstituteInfoMatster instituteInfotMaster)
{
this.instituteInfotMaster = instituteInfotMaster;
}
public String getString1()
{
return string1;
}
public void setString1(String string1)
{
this.string1 = string1;
}
public String getString2()
{
return string2;
}
public void setString2(String string2)
{
this.string2 = string2;
}
public String getString3()
{
return string3;
}
public void setString3(String string3)
{
this.string3 = string3;
}
public int getSequenceNo()
{
return sequenceNo;
}
public void setSequenceNo(int sequenceNo)
{
this.sequenceNo = sequenceNo;
}
public Double getNumber1()
{
return number1;
}
public void setNumber1(Double number1)
{
this.number1 = number1;
}
public Double getNumber2()
{
return number2;
}
public void setNumber2(Double number2)
{
this.number2 = number2;
}
public Double getNumber3()
{
return number3;
}
public void setNumber3(Double number3)
{
this.number3 = number3;
}
public byte[] getDocument()
{
return document;
}
public void setDocument(byte[] document)
{
this.document = document;
}
public Integer getDocumentType()
{
return documentType;
}
public void setDocumentType(Integer documentType)
{
this.documentType = documentType;
}
public byte[] getDocument1()
{
return document1;
}
public void setDocument1(byte[] document1)
{
this.document1 = document1;
}
public Integer getDocument1Type()
{
return document1Type;
}
public void setDocument1Type(Integer document1Type)
{
this.document1Type = document1Type;
}
public byte[] getDocument2()
{
return document2;
}
public void setDocument2(byte[] document2)
{
this.document2 = document2;
}
public Integer getDocument2Type()
{
return document2Type;
}
public void setDocument2Type(Integer document2Type)
{
this.document2Type = document2Type;
}
#Override
public String toString()
{
return "InstituteInfoDetails [listDtlId=" + listDtlId + ", instituteInfotMaster=" + instituteInfotMaster
+ ", value=" + value + ", description=" + description + ", string1=" + string1 + ", string2=" + string2
+ ", string3=" + string3 + ", sequenceNo=" + sequenceNo + ", number1=" + number1 + ", number2="
+ number2 + ", number3=" + number3 + ", document=" + Arrays.toString(document) + ", documentType="
+ documentType + ", document1=" + Arrays.toString(document1) + ", document1Type=" + document1Type
+ ", document2=" + Arrays.toString(document2) + ", document2Type=" + document2Type + ", createdDate="
+ createdDate + ", createdBy=" + createdBy + ", updatedDate=" + updatedDate + ", updatedBy=" + updatedBy
+ ", recordStatus=" + recordStatus + "]";
}
}
now i am using below rest service request to add master data with child
{"description":"Placements","value":"Placements","url":"/Placements","instituteInfoDetails":[{"value":"Test"}]}
Code to save data
#Override
public void addInstituteInfoMaster(com.zertones.model.common.InstituteInfoMatster instituteInfoMatster)
{
Session session = sessionFactory.getCurrentSession();
session.saveOrUpdate(instituteInfoMatster);
}
but while saving it gives me below error
org.hibernate.PropertyValueException: not-null property references a null or transient value : com.zertones.model.common.InstituteInfoDetails.instituteInfotMaster
I searched and did as per solutions i added the cascade type information, but it did not helped.

create bidirectional Setter method for set InstituteInfoMatster to instituteInfoDetails
change class InstituteInfoMatster
public void setInstituteInfoDetails(List<InstituteInfoDetails> instituteInfoDetails)
{
for(InstituteInfoDetails ins : instituteInfoDetails){
ins.setComListMaster(this);
}
this.instituteInfoDetails = instituteInfoDetails;
}

I think you have a typo in this code:
#ManyToOne
#JoinColumn(name = "LIST_ID", nullable = false)
#JsonProperty("instituteInfotMaster")
#JsonBackReference
private InstituteInfoMatster instituteInfotMaster;
Shouldn't it be instituteInfoMaster instead?
EDIT: or maybe not, I can se you have multiple typos there, such as InstituteInfoMatster etc. Still, I think it would worth to fix these typos while you still can (if you still can, of course).

Related

join two table using hibernate

I have two table entity channel and channel_stats.I want to save data in tables using session.save().
channel_stats can contain duplicate entry with duplicate channel ID.
Can you please tell me how to do so using secondary table annotation in hibernate. or is there any other way? i tried with embedded and embedded annotation bit looks like its for same table
#Entity
#Table(name="channel_list")
public class Channel {
#Id
#GeneratedValue(strategy=GenerationType.IDENTITY)
#Column(name="id")
private int id;
#Column(name="channel_youtubeID")
private String channelYoutubeID;
#Column(name="channel_title")
private String channelTitle;
#Column(name="thumbnail_url")
private String thumbnailUrl;
#Column(name="active_bit")
private int activeBit;
#Embedded
private ChannelStats channelStats;
public Channel() {
}
public Channel(String channelYoutubeID, String channelTitle, String thumbnailUrl, int activeBit,
ChannelStats channelStats) {
super();
this.channelYoutubeID = channelYoutubeID;
this.channelTitle = channelTitle;
this.thumbnailUrl = thumbnailUrl;
this.activeBit = activeBit;
this.channelStats = channelStats;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getChannelYoutubeID() {
return channelYoutubeID;
}
public void setChannelYoutubeID(String channelYoutubeID) {
this.channelYoutubeID = channelYoutubeID;
}
public String getChannelTitle() {
return channelTitle;
}
public void setChannelTitle(String channelTitle) {
this.channelTitle = channelTitle;
}
public String getThumbnailUrl() {
return thumbnailUrl;
}
public void setThumbnailUrl(String thumbnailUrl) {
this.thumbnailUrl = thumbnailUrl;
}
public int getActiveBit() {
return activeBit;
}
public void setActiveBit(int activeBit) {
this.activeBit = activeBit;
}
public ChannelStats getChannelStats() {
return channelStats;
}
public void setChannelStats(ChannelStats channelStats) {
this.channelStats = channelStats;
}
#Override
public String toString() {
return "Channel [id=" + id + ", channelYoutubeID=" + channelYoutubeID + ", channelTitle=" + channelTitle
+ ", thumbnailUrl=" + thumbnailUrl + ", activeBit=" + activeBit + ", channelStats=" + channelStats
+ "]";
}
}
#Embeddable
#Table(name="channel_stats")
public class ChannelStats {
#Column(name="channelID")
private String channelID;
#Column(name="viewCount")
private long viewCount;
#Column(name="commentCount")
private long commentCount;
#Column(name="subscriberCount")
private long subscriberCount;
#Column(name="hiddenSubscriberCount")
private boolean hiddenSubscriberCount;
#Column(name="videoCount")
private long videoCount;
public ChannelStats() {
}
public ChannelStats(String channelID, long viewCount, long commentCount, long subscriberCount,
boolean hiddenSubscriberCount, long videoCount) {
super();
this.channelID = channelID;
this.viewCount = viewCount;
this.commentCount = commentCount;
this.subscriberCount = subscriberCount;
this.hiddenSubscriberCount = hiddenSubscriberCount;
this.videoCount = videoCount;
}
public String getChannelID() {
return channelID;
}
public void setChannelID(String channelID) {
this.channelID = channelID;
}
public long getViewCount() {
return viewCount;
}
public void setViewCount(long viewCount) {
this.viewCount = viewCount;
}
public long getCommentCount() {
return commentCount;
}
public void setCommentCount(long commentCount) {
this.commentCount = commentCount;
}
public long getSubscriberCount() {
return subscriberCount;
}
public void setSubscriberCount(long subscriberCount) {
this.subscriberCount = subscriberCount;
}
public boolean isHiddenSubscriberCount() {
return hiddenSubscriberCount;
}
public void setHiddenSubscriberCount(boolean hiddenSubscriberCount) {
this.hiddenSubscriberCount = hiddenSubscriberCount;
}
public long getVideoCount() {
return videoCount;
}
public void setVideoCount(long videoCount) {
this.videoCount = videoCount;
}
#Override
public String toString() {
return "ChannelStats [channelID=" + channelID + ", viewCount=" + viewCount + ", commentCount=" + commentCount
+ ", subscriberCount=" + subscriberCount + ", hiddenSubscriberCount=" + hiddenSubscriberCount
+ ", videoCount=" + videoCount + "]";
}
}
As I understand the question, #Embeddable is not what you want in this case. #Embeddable and #Embedded is used when you don't want a separate second table. Since you want a separate table to have the ChannelStat data, it seems like you are trying to create a #OneToMany relationship where one Channel object can have multiple ChannelStat objects.
So your Channel class should have
#OneToMany( mappedBy = "channel", cascade = CascadeType.ALL )
private List<ChannelStat> channelStat;
Instead of
#Embedded
private ChannelStats channelStats;
And your ChannelStat class should have
public class ChannelStats {
// Other variables and their getters and setters
#ManyToOne( cascade = CascadeType.ALL )
#JoinColumn( name = "id" )
private Channel channel;
}
Read here for more information.

JPA 2.2: Using find method to retrieve data from mysqlDB

I´m using JPA 2.2(Openjpa) running on OpenLiberty and mysqlVer 15.1 Distrib 10.1.21-MariaDB.
I have an object call Account where I use the entityManager.find to retrieve a given record.
The record is indeed retrieved but only this column "status" returns null.
But when I do the manual select against the DB,the value is there.
My Entity class
Account
package br.com.rsm.model;
import java.io.Serializable;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import javax.persistence.Transient;
//#XmlRootElement
#Entity
#Table(name = "tb_account")
#NamedQueries({
#NamedQuery(name="Account.findByEmail", query="SELECT a FROM Account a where a.email = :email"),
#NamedQuery(name="Account.findByCpf", query="SELECT a FROM Account a where a.cpf = :cpf"),
#NamedQuery(name="Account.findByUserId", query="SELECT a FROM Account a where a.userId = :userId")
})
public class Account implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String userId;
private String fullname;
private String email;
private String birthdate;
private String cpf;
private String rg;
private String address;
private String addressNumber;
private String complement;
private String cep;
private String state;
private int city;
private String phone;
private String mobile;
private String carrier;
#Column(name = "status")
private String status;
private long leftSide;
private long rightSide;
private Timestamp created;
private String parentId;
private String parentSide;
private String networkSide;
private Timestamp activated;
private double points;
private String nickname;
private String nis;
private String whatsapp;
private long bank;
private String accountType;
private String branchNumber;
private String branchDigit;
private String accountNumber;
private String accountDigit;
private String accountOwner;
private String cpfAccountOwner;
private String facebookID;
private double career;
private double pb;
private int certID;
private String automaticRenovation;
private String emailPagamento;
#Transient
private Account rightSideAccount;
#Transient
private Account leftSideAccount;
#Transient
private boolean searchableBySignedInUser;
#Transient
private long totalCandidatosAgente;
#Transient
private long totalAgentes;
#Transient
private long totalAgentesBracoEsq;
#Transient
private long totalAgentesBracoDir;
#Transient
private long totalAnjos;
#Transient
private boolean cfaCompleto;
//#Transient
#OneToMany(cascade={CascadeType.ALL}, fetch = FetchType.LAZY, orphanRemoval = true)
#JoinColumn(name = "owner" )
List<Ticket> tickets = new ArrayList<Ticket>();
#OneToMany(cascade={CascadeType.ALL}, fetch = FetchType.LAZY, orphanRemoval = true)
#OrderBy("created DESC")
#JoinColumn(name = "accountId" )
private List<Score> scores = new ArrayList<Score>();
#OneToMany(cascade={CascadeType.ALL}, fetch = FetchType.LAZY, orphanRemoval = true)
#OrderBy("activated DESC")
#JoinColumn(name = "idAccount" )
private List<ProductAccount> productsAccount = new ArrayList<ProductAccount>();
#OneToMany(cascade={CascadeType.ALL}, fetch = FetchType.LAZY, orphanRemoval = true)
#JoinColumn(name = "origin" )
private List<Trade> trades = new ArrayList<Trade>();
/**
* Construtor
*/
public Account() {}
public List<Trade> getTrades() {
return trades;
}
public void setTrades(List<Trade> trades) {
this.trades = trades;
}
public List<ProductAccount> getProductsAccount() {
return productsAccount;
}
public void setProductsAccount(List<ProductAccount> productsAccount) {
this.productsAccount = productsAccount;
}
public List<Score> getScores() {
return scores;
}
public void setScores(List<Score> scores) {
this.scores = scores;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public String getFullname() {
return fullname;
}
public void setFullname(String fullname) {
this.fullname = fullname;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getBirthdate() {
return birthdate;
}
public void setBirthdate(String birthdate) {
this.birthdate = birthdate;
}
public String getCpf() {
return cpf;
}
public void setCpf(String cpf) {
this.cpf = cpf;
}
public String getRg() {
return rg;
}
public void setRg(String rg) {
this.rg = rg;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getAddressNumber() {
return addressNumber;
}
public void setAddressNumber(String addressNumber) {
this.addressNumber = addressNumber;
}
public String getComplement() {
return complement;
}
public void setComplement(String complement) {
this.complement = complement;
}
public String getCep() {
return cep;
}
public void setCep(String cep) {
this.cep = cep;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public int getCity() {
return city;
}
public void setCity(int city) {
this.city = city;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getMobile() {
return mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
public String getCarrier() {
return carrier;
}
public void setCarrier(String carrier) {
this.carrier = carrier;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public long getLeftSide() {
return leftSide;
}
public void setLeftSide(long leftSide) {
this.leftSide = leftSide;
}
public long getRightSide() {
return rightSide;
}
public void setRightSide(long rightSide) {
this.rightSide = rightSide;
}
public Timestamp getCreated() {
return created;
}
public void setCreated(Timestamp created) {
this.created = created;
}
public String getParentId() {
return parentId;
}
public void setParentId(String parentId) {
this.parentId = parentId;
}
public String getParentSide() {
return parentSide;
}
public void setParentSide(String parentSide) {
this.parentSide = parentSide;
}
public String getNetworkSide() {
return networkSide;
}
public void setNetworkSide(String networkSide) {
this.networkSide = networkSide;
}
public List<Ticket> getTickets() {
return tickets;
}
public void setTickets(List<Ticket> tickets) {
this.tickets = tickets;
}
public Timestamp getActivated() {
return activated;
}
public void setActivated(Timestamp activated) {
this.activated = activated;
}
public double getPoints() {
return points;
}
public void setPoints(double points) {
this.points = points;
}
#Transient
public String getShortName() {
if(fullname==null){
return "";
}
if (nickname == null || nickname.isEmpty() ) {
nickname = fullname;
}
if(nickname != null || !nickname.isEmpty()){
String[] arrTmp = fullname.replace("\n", " ").split(" ");
String shortName = "";
if(arrTmp.length >= 2){
shortName = arrTmp[0] + " " + arrTmp[1] ;
}else if(arrTmp.length >= 1){
shortName = arrTmp[0];
}
//Passo o limitador de tamanho para ambas situações.
if(shortName!=null){
if(shortName.length() > 20){
shortName = fullname.substring(0, 19) + "...";
}
}
return shortName;
}
return "";
}
public String getNickname() {
return nickname;
}
public void setNickname(String nickname) {
this.nickname = nickname;
}
public String getNis() {
return nis;
}
public void setNis(String nis) {
this.nis = nis;
}
public String getWhatsapp() {
return whatsapp;
}
public void setWhatsapp(String whatsapp) {
this.whatsapp = whatsapp;
}
public long getBank() {
return bank;
}
public void setBank(long bank) {
this.bank = bank;
}
public String getAccountType() {
return accountType;
}
public void setAccountType(String accountType) {
this.accountType = accountType;
}
public String getBranchNumber() {
return branchNumber;
}
public void setBranchNumber(String branchNumber) {
this.branchNumber = branchNumber;
}
public String getBranchDigit() {
return branchDigit;
}
public void setBranchDigit(String branchDigit) {
this.branchDigit = branchDigit;
}
public String getAccountNumber() {
return accountNumber;
}
public void setAccountNumber(String accountNumber) {
this.accountNumber = accountNumber;
}
public String getAccountDigit() {
return accountDigit;
}
public void setAccountDigit(String accountDigit) {
this.accountDigit = accountDigit;
}
public String getAccountOwner() {
return accountOwner;
}
public void setAccountOwner(String accountOwner) {
this.accountOwner = accountOwner;
}
public String getCpfAccountOwner() {
return cpfAccountOwner;
}
public void setCpfAccountOwner(String cpfAccountOwner) {
this.cpfAccountOwner = cpfAccountOwner;
}
public String getFacebookID() {
return facebookID;
}
public void setFacebookID(String facebookID) {
this.facebookID = facebookID;
}
public double getCareer() {
return career;
}
public void setCareer(double career) {
this.career = career;
}
public double getPb() {
return pb;
}
public void setPb(double pb) {
this.pb = pb;
}
public int getCertID() {
return certID;
}
public void setCertID(int certID) {
this.certID = certID;
}
public String getAutomaticRenovation() {
return automaticRenovation;
}
public void setAutomaticRenovation(String automaticRenovation) {
this.automaticRenovation = automaticRenovation;
}
public String getEmailPagamento() {
return emailPagamento;
}
public void setEmailPagamento(String emailPagamento) {
this.emailPagamento = emailPagamento;
}
public Account getRightSideAccount() {
return rightSideAccount;
}
public void setRightSideAccount(Account rightSideAccount) {
this.rightSideAccount = rightSideAccount;
}
public Account getLeftSideAccount() {
return leftSideAccount;
}
public void setLeftSideAccount(Account leftSideAccount) {
this.leftSideAccount = leftSideAccount;
}
public boolean isSearchableBySignedInUser() {
return searchableBySignedInUser;
}
public void setSearchableBySignedInUser(boolean searchableBySignedInUser) {
this.searchableBySignedInUser = searchableBySignedInUser;
}
public long getTotalCandidatosAgente() {
return totalCandidatosAgente;
}
public void setTotalCandidatosAgente(long totalCandidatosAgente) {
this.totalCandidatosAgente = totalCandidatosAgente;
}
public long getTotalAgentes() {
return totalAgentes;
}
public void setTotalAgentes(long totalAgentes) {
this.totalAgentes = totalAgentes;
}
public long getTotalAgentesBracoEsq() {
return totalAgentesBracoEsq;
}
public void setTotalAgentesBracoEsq(long totalAgentesBracoEsq) {
this.totalAgentesBracoEsq = totalAgentesBracoEsq;
}
public long getTotalAgentesBracoDir() {
return totalAgentesBracoDir;
}
public void setTotalAgentesBracoDir(long totalAgentesBracoDir) {
this.totalAgentesBracoDir = totalAgentesBracoDir;
}
public long getTotalAnjos() {
return totalAnjos;
}
public void setTotalAnjos(long totalAnjos) {
this.totalAnjos = totalAnjos;
}
public boolean isCfaCompleto() {
return cfaCompleto;
}
public void setCfaCompleto(boolean cfaCompleto) {
this.cfaCompleto = cfaCompleto;
}
/**
* Adiciona uma nova classe Score
* #param score Score
*/
public void addScore(Score score) {
getScores().add(score);
}
public void addProductAccount(ProductAccount productAccount) {
getProductsAccount().add(productAccount);
}
public void addTrade(Trade trade) {
getTrades().add(trade);
}
#Override
public String toString() {
return "Account [id=" + id + ", userId=" + userId + ", fullname=" + fullname + ", email=" + email
+ ", birthdate=" + birthdate + ", cpf=" + cpf + ", rg=" + rg + ", address=" + address
+ ", addressNumber=" + addressNumber + ", complement=" + complement + ", cep=" + cep + ", state="
+ state + ", city=" + city + ", phone=" + phone + ", mobile=" + mobile + ", carrier=" + carrier
+ ", status=" + status + ", leftSide=" + leftSide + ", rightSide=" + rightSide + ", created=" + created
+ ", parentId=" + parentId + ", parentSide=" + parentSide + ", networkSide=" + networkSide
+ ", activated=" + activated + ", points=" + points + ", nickname=" + nickname + ", nis=" + nis
+ ", whatsapp=" + whatsapp + ", bank=" + bank + ", accountType=" + accountType + ", branchNumber="
+ branchNumber + ", branchDigit=" + branchDigit + ", accountNumber=" + accountNumber + ", accountDigit="
+ accountDigit + ", accountOwner=" + accountOwner + ", cpfAccountOwner=" + cpfAccountOwner
+ ", facebookID=" + facebookID + ", career=" + career + ", pb=" + pb + ", certID=" + certID
+ ", automaticRenovation=" + automaticRenovation + ", emailPagamento=" + emailPagamento
+ ", rightSideAccount=" + rightSideAccount + ", leftSideAccount=" + leftSideAccount
+ ", searchableBySignedInUser=" + searchableBySignedInUser + ", totalCandidatosAgente="
+ totalCandidatosAgente + ", totalAgentes=" + totalAgentes + ", totalAgentesBracoEsq="
+ totalAgentesBracoEsq + ", totalAgentesBracoDir=" + totalAgentesBracoDir + ", totalAnjos=" + totalAnjos
+ ", cfaCompleto=" + cfaCompleto + ", tickets=" + tickets + ", scores=" + scores + ", productsAccount="
+ productsAccount + ", trades=" + trades + "]";
}
}
And this is my select result( snapshot table is to big )
[
id=2111,
userId=99YWK,
fullname=PatrickRibeiroBraz,
email=null,
birthdate=null,
cpf=null,
rg=null,
address=null,
addressNumber=null,
complement=null,
cep=null,
state=null,
city=0,
phone=null,
mobile=null,
carrier=null,
status=null,
leftSide=0,
rightSide=0,
created=2018-06-1212: 09: 29.0,
parentId=999I2,
parentSide=null,
networkSide=null,
activated=null,
points=0.0,
nickname=null,
nis=null,
whatsapp=null,
bank=0,
accountType=null,
branchNumber=null,
branchDigit=null,
accountNumber=null,
accountDigit=null,
accountOwner=null,
cpfAccountOwner=null,
facebookID=null,
career=0.0,
pb=0.0,
certID=0,
automaticRenovation=null,
emailPagamento=null,
rightSideAccount=null,
leftSideAccount=null,
searchableBySignedInUser=false,
totalCandidatosAgente=0,
totalAgentes=0,
totalAgentesBracoEsq=0,
totalAgentesBracoDir=0,
totalAnjos=0,
cfaCompleto=false,
tickets={
IndirectList: notinstantiated
},
scores={
IndirectList: notinstantiated
},
productsAccount={
IndirectList: notinstantiated
},
trades={
IndirectList: notinstantiated
}
]
ID fullname status
2111 Patrick Ribeiro Braz C
Has anyone went through this before?

java error: inconsistent datatypes: expected NUMBER got BINARY

I got this error in my java project. Can you help me, please? Db is an oracle. I think i set correct values, but moreover, I am getting this error again and again. Which row has a problem I didn't understand. I changed the values many times and tried but unfortunately it doesn't say which row is wrong?
2019-10-04 11:05:23.903 WARN 15556 --- [ main] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 932, SQLState: 42000
2019-10-04 11:05:23.907 ERROR 15556 --- [ main] o.h.engine.jdbc.spi.SqlExceptionHelper : ORA-00932: inconsistent datatypes: expected NUMBER got BINARY
create method:
#Test
public void create() throws ParseException {
String dateInString = "31-08-1982";
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
Date date7 = sdf.parse(dateInString);
SemesterBeginningOperations data = new SemesterBeginningOperations();
data.setDtId(6494);
data.setAsonId(114);
data.setCrte(date7);
data.setStae(date7);
data.setEnte(date7);
data.setEage(9);
data.setClatage(9);
data.setPan(9);
data.setPadealGre(9);
data.setRessade(9);
data.setDation(9);
data.setDal(9);
data.setDaa(9);
data.setDtionta2(9);
data.setHal(9);
data.setHoota(9);
data.setHoQta2(9);
data.setDaiour(9);
data.setDaiuota(9);
data.setDaiAuota2(9);
data.setPrevId(183);
data.setPticctage(2);
data.setPatlaed(2);
data.setAntge(1);
data.setFalPge(1);
data.setMinit(2);
data.setStee(1);
data.setMinPa2(3);
data.setMinit2(5);
data.setMo(4);
data.setMinPasTp(3);
data.setPared(6);
semesterBeginningOperationsRepository.create(data);
}
my table:
COLUMN_NAME DATA_TYPE NULLABLE
HID NUMBER(10,0) No
BID NUMBER(10,0) No
AID NUMBER(10,0) No
YTARIHI DATE No
BTARIHI DATE Yes
BITARIHI DATE Yes
SE NUMBER(3,0) No
SDE NUMBER(3,0) No
GU NUMBER(3,0) No
GR NUMBER(3,0) No
BER NUMBER(3,0) No
GN NUMBER(4,0) No
GBER NUMBER(10,0) No
GMBER NUMBER(10,0) No
GUMBER NUMBER(10,0) No
SMBER NUMBER(10,0) No
SAR NUMBER(10,0) No
SAAR NUMBER(10,0) No
GUAT NUMBER(3,0) No
GUJAN NUMBER(3,0) No
GU2 NUMBER(3,0) No
ONCMID NUMBER(10,0) Yes
PARTIE NUMBER(3,0) No
BUTTU NUMBER(3,0) No
DEE NUMBER(3,0) No
FDE NUMBER(3,0) No
BUU NUMBER(3,0) No
OGRIN NUMBER(3,0) No
BUU NUMBER(3,0) Yes
BUGU NUMBER(3,0) Yes
MER NUMBER(3,0) Yes
BUP_TP NUMBER(1,0) No
PARUN NUMBER(1,0) No
SemesterBeginningOperations class:
package prep.core.semester.definition.domain.model.semester;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
#Entity
#Table(name = "HAZ_DONEM", catalog = "", schema = "DBO")
public class SemesterBeginningOperations {
#Id
#Basic(optional = false)
#GeneratedValue(strategy = GenerationType.IDENTITY)
#Column(name = "HAZDONEMID")
private Integer semesterId;
#Basic(optional = false)
#Column(name = "BOLUMID")
private Integer departmentId;
#Column(name = "AKADEMIKSEZONID")
private Integer academicSeasonId;
#Temporal(TemporalType.DATE)
#Column(name = "YARATILISTARIHI")
private Date createDate;
#Column(name = "BASLAMATARIHI")
private Date startDate;
#Column(name = "BITISTARIHI")
private Date endDate;
#Column(name = "SINAV_YUZDE")
private Integer examPercentage;
#Column(name = "SINIFCALISMASI_YUZDE")
private Integer classStudyPercentage;
#Column(name = "GECME_MIN_BASARINOTU")
private Integer passGradeMin;
#Column(name = "GECME_MIN_FINALNOTU")
private Integer passGradeMinFinalGrade;
#Column(name = "BUT_MIN_BASARINOTU")
private Integer resitMinPassGrade;
#Column(name = "GUNLUK_PARTICIPATION")
private Integer dailyParticipation;
#Column(name = "GUN_TOPLAM")
private Integer dayTotal;
#Column(name = "GUN_TOPLAM_EKKONTENJAN")
private Integer dayTotalAdditionalQuota;
#Column(name = "GUN_TOPLAM_EKKONTENJAN2")
private Integer dayTotalAdditionalQuota2;
#Column(name = "SAAT_TOPLAM")
private Integer hourTotal;
#Column(name = "SAAT_TOPLAM_EKKONTENJAN")
private Integer hourTotalAdditionalQuota;
#Column(name = "SAAT_TOPLAM_EKKONTENJAN2")
private Integer hourTotalAdditionalQuota2;
#Column(name = "GUNLUK_SAAT")
private Integer dailyHour;
#Column(name = "GUNLUK_SAAT_EKKONTENJAN")
private Integer dailyHourAdditionalQuota;
#Column(name = "GUNLUK_SAAT_EKKONTENJAN2")
private Integer dailyHourAdditionalQuota2;
#Column(name = "ONCEKI_HAZDONEMID")
private Integer previousSemesterId;
#Column(name = "PARTICIPATION_YUZDE")
private Integer participationPercentage;
#Column(name = "BUT_GECMENOTU")
private Integer passGradeForResit;
#Column(name = "DEVAMSIZLIK_YUZDE")
private Integer absensePercentage;
#Column(name = "FINAL_YUZDE")
private Integer finalPercentage;
#Column(name = "BUT_MIN_FINALNOTU")
private Integer minFinalGradeForResit;
#Column(name = "OGRENCIGOREBILSIN")
private Integer studentCanSee;
#Column(name = "BUT2_MIN_BASARINOTU")
private Integer minPassGradeForResit2;
#Column(name = "BUT2_MIN_FINALNOTU")
private Integer minFinalGradeForResit2;
#Column(name = "MODUL")
private Integer module;
#Column(name = "BUT_GECMENOTU_HSP_TP")
private Integer minPassGradeForResitHspTp;
#Column(name = "PARTICIPATION_GORUNSUN")
private Integer participationTotalDisplayed;
public SemesterBeginningOperations() {
}
public SemesterBeginningOperations(Integer semesterId, Integer departmentId, Integer academicSeasonId, Date createDate,
Date startDate, Date endDate, Integer examPercentage, Integer classStudyPercentage, Integer passGradeMin,
Integer passGradeMinFinalGrade, Integer resitMinPassGrade, Integer dailyParticipation, Integer dayTotal,
Integer dayTotalAdditionalQuota, Integer dayTotalAdditionalQuota2, Integer hourTotal, Integer hourTotalAdditionalQuota,
Integer hourTotalAdditionalQuota2, Integer dailyHour, Integer dailyHourAdditionalQuota, Integer dailyHourAdditionalQuota2,
Integer previousSemesterId, Integer participationPercentage, Integer passGradeForResit, Integer absensePercentage,
Integer finalPercentage, Integer minFinalGradeForResit, Integer studentCanSee, Integer minPassGradeForResit2,
Integer minFinalGradeForResit2, Integer module, Integer minPassGradeForResitHspTp, Integer participationTotalDisplayed) {
super();
this.semesterId = semesterId;
this.departmentId = departmentId;
this.academicSeasonId = academicSeasonId;
this.createDate = createDate;
this.startDate = startDate;
this.endDate = endDate;
this.examPercentage = examPercentage;
this.classStudyPercentage = classStudyPercentage;
this.passGradeMin = passGradeMin;
this.passGradeMinFinalGrade = passGradeMinFinalGrade;
this.resitMinPassGrade = resitMinPassGrade;
this.dailyParticipation = dailyParticipation;
this.dayTotal = dayTotal;
this.dayTotalAdditionalQuota = dayTotalAdditionalQuota;
this.dayTotalAdditionalQuota2 = dayTotalAdditionalQuota2;
this.hourTotal = hourTotal;
this.hourTotalAdditionalQuota = hourTotalAdditionalQuota;
this.hourTotalAdditionalQuota2 = hourTotalAdditionalQuota2;
this.dailyHour = dailyHour;
this.dailyHourAdditionalQuota = dailyHourAdditionalQuota;
this.dailyHourAdditionalQuota2 = dailyHourAdditionalQuota2;
this.previousSemesterId = previousSemesterId;
this.participationPercentage = participationPercentage;
this.passGradeForResit = passGradeForResit;
this.absensePercentage = absensePercentage;
this.finalPercentage = finalPercentage;
this.minFinalGradeForResit = minFinalGradeForResit;
this.studentCanSee = studentCanSee;
this.minPassGradeForResit2 = minPassGradeForResit2;
this.minFinalGradeForResit2 = minFinalGradeForResit2;
this.module = module;
this.minPassGradeForResitHspTp = minPassGradeForResitHspTp;
this.participationTotalDisplayed = participationTotalDisplayed;
}
public Integer getSemesterId() {
return semesterId;
}
public void setSemesterId(Integer semesterId) {
this.semesterId = semesterId;
}
public Integer getDepartmentId() {
return departmentId;
}
public void setDepartmentId(Integer departmentId) {
this.departmentId = departmentId;
}
public Integer getAcademicSeasonId() {
return academicSeasonId;
}
public void setAcademicSeasonId(Integer academicSeasonId) {
this.academicSeasonId = academicSeasonId;
}
public Date getCreateDate() {
return createDate;
}
public void setCreateDate(Date createDate) {
this.createDate = createDate;
}
public Date getStartDate() {
return startDate;
}
public void setStartDate(Date startDate) {
this.startDate = startDate;
}
public Date getEndDate() {
return endDate;
}
public void setEndDate(Date endDate) {
this.endDate = endDate;
}
public Integer getExamPercentage() {
return examPercentage;
}
public void setExamPercentage(Integer examPercentage) {
this.examPercentage = examPercentage;
}
public Integer getClassStudyPercentage() {
return classStudyPercentage;
}
public void setClassStudyPercentage(Integer classStudyPercentage) {
this.classStudyPercentage = classStudyPercentage;
}
public Integer getPassGradeMin() {
return passGradeMin;
}
public void setPassGradeMin(Integer passGradeMin) {
this.passGradeMin = passGradeMin;
}
public Integer getPassGradeMinFinalGrade() {
return passGradeMinFinalGrade;
}
public void setPassGradeMinFinalGrade(Integer passGradeMinFinalGrade) {
this.passGradeMinFinalGrade = passGradeMinFinalGrade;
}
public Integer getResitMinPassGrade() {
return resitMinPassGrade;
}
public void setResitMinPassGrade(Integer resitMinPassGrade) {
this.resitMinPassGrade = resitMinPassGrade;
}
public Integer getDailyParticipation() {
return dailyParticipation;
}
public void setDailyParticipation(Integer dailyParticipation) {
this.dailyParticipation = dailyParticipation;
}
public Integer getDayTotal() {
return dayTotal;
}
public void setDayTotal(Integer dayTotal) {
this.dayTotal = dayTotal;
}
public Integer getDayTotalAdditionalQuota() {
return dayTotalAdditionalQuota;
}
public void setDayTotalAdditionalQuota(Integer dayTotalAdditionalQuota) {
this.dayTotalAdditionalQuota = dayTotalAdditionalQuota;
}
public Integer getDayTotalAdditionalQuota2() {
return dayTotalAdditionalQuota2;
}
public void setDayTotalAdditionalQuota2(Integer dayTotalAdditionalQuota2) {
this.dayTotalAdditionalQuota2 = dayTotalAdditionalQuota2;
}
public Integer getHourTotal() {
return hourTotal;
}
public void setHourTotal(Integer hourTotal) {
this.hourTotal = hourTotal;
}
public Integer getHourTotalAdditionalQuota() {
return hourTotalAdditionalQuota;
}
public void setHourTotalAdditionalQuota(Integer hourTotalAdditionalQuota) {
this.hourTotalAdditionalQuota = hourTotalAdditionalQuota;
}
public Integer getHourTotalAdditionalQuota2() {
return hourTotalAdditionalQuota2;
}
public void setHourTotalAdditionalQuota2(Integer hourTotalAdditionalQuota2) {
this.hourTotalAdditionalQuota2 = hourTotalAdditionalQuota2;
}
public Integer getDailyHour() {
return dailyHour;
}
public void setDailyHour(Integer dailyHour) {
this.dailyHour = dailyHour;
}
public Integer getDailyHourAdditionalQuota() {
return dailyHourAdditionalQuota;
}
public void setDailyHourAdditionalQuota(Integer dailyHourAdditionalQuota) {
this.dailyHourAdditionalQuota = dailyHourAdditionalQuota;
}
public Integer getDailyHourAdditionalQuota2() {
return dailyHourAdditionalQuota2;
}
public void setDailyHourAdditionalQuota2(Integer dailyHourAdditionalQuota2) {
this.dailyHourAdditionalQuota2 = dailyHourAdditionalQuota2;
}
public Integer getPreviousSemesterId() {
return previousSemesterId;
}
public void setPreviousSemesterId(Integer previousSemesterId) {
this.previousSemesterId = previousSemesterId;
}
public Integer getParticipationPercentage() {
return participationPercentage;
}
public void setParticipationPercentage(Integer participationPercentage) {
this.participationPercentage = participationPercentage;
}
public Integer getPassGradeForResit() {
return passGradeForResit;
}
public void setPassGradeForResit(Integer passGradeForResit) {
this.passGradeForResit = passGradeForResit;
}
public Integer getAbsensePercentage() {
return absensePercentage;
}
public void setAbsensePercentage(Integer absensePercentage) {
this.absensePercentage = absensePercentage;
}
public Integer getFinalPercentage() {
return finalPercentage;
}
public void setFinalPercentage(Integer finalPercentage) {
this.finalPercentage = finalPercentage;
}
public Integer getMinFinalGradeForResit() {
return minFinalGradeForResit;
}
public void setMinFinalGradeForResit(Integer minFinalGradeForResit) {
this.minFinalGradeForResit = minFinalGradeForResit;
}
public Integer getStudentCanSee() {
return studentCanSee;
}
public void setStudentCanSee(Integer studentCanSee) {
this.studentCanSee = studentCanSee;
}
public Integer getMinPassGradeForResit2() {
return minPassGradeForResit2;
}
public void setMinPassGradeForResit2(Integer minPassGradeForResit2) {
this.minPassGradeForResit2 = minPassGradeForResit2;
}
public Integer getMinFinalGradeForResit2() {
return minFinalGradeForResit2;
}
public void setMinFinalGradeForResit2(Integer minFinalGradeForResit2) {
this.minFinalGradeForResit2 = minFinalGradeForResit2;
}
public Integer getModule() {
return module;
}
public void setModule(Integer module) {
this.module = module;
}
public Integer getMinPassGradeForResitHspTp() {
return minPassGradeForResitHspTp;
}
public void setMinPassGradeForResitHspTp(Integer minPassGradeForResitHspTp) {
this.minPassGradeForResitHspTp = minPassGradeForResitHspTp;
}
public Integer getParticipationTotalDisplayed() {
return participationTotalDisplayed;
}
public void setParticipationTotalDisplayed(Integer participationTotalDisplayed) {
this.participationTotalDisplayed = participationTotalDisplayed;
}
#Override
public String toString() {
return "SemesterBeginningOperations [semesterId=" + semesterId + ", departmentId=" + departmentId
+ ", academicSeasonId=" + academicSeasonId + ", createDate=" + createDate + ", startDate=" + startDate
+ ", endDate=" + endDate + ", examPercentage=" + examPercentage + ", classStudyPercentage="
+ classStudyPercentage + ", passGradeMin=" + passGradeMin + ", passGradeMinFinalGrade="
+ passGradeMinFinalGrade + ", resitMinPassGrade=" + resitMinPassGrade + ", dailyParticipation="
+ dailyParticipation + ", dayTotal=" + dayTotal + ", dayTotalAdditionalQuota=" + dayTotalAdditionalQuota
+ ", dayTotalAdditionalQuota2=" + dayTotalAdditionalQuota2 + ", hourTotal=" + hourTotal
+ ", hourTotalAdditionalQuota=" + hourTotalAdditionalQuota + ", hourTotalAdditionalQuota2="
+ hourTotalAdditionalQuota2 + ", dailyHour=" + dailyHour + ", dailyHourAdditionalQuota="
+ dailyHourAdditionalQuota + ", dailyHourAdditionalQuota2=" + dailyHourAdditionalQuota2
+ ", previousSemesterId=" + previousSemesterId + ", participationPercentage=" + participationPercentage
+ ", passGradeForResit=" + passGradeForResit + ", absensePercentage=" + absensePercentage
+ ", finalPercentage=" + finalPercentage + ", minFinalGradeForResit=" + minFinalGradeForResit
+ ", studentCanSee=" + studentCanSee + ", minPassGradeForResit2=" + minPassGradeForResit2
+ ", minFinalGradeForResit2=" + minFinalGradeForResit2 + ", module=" + module
+ ", minPassGradeForResitHspTp=" + minPassGradeForResitHspTp + ", participationTotalDisplayed="
+ participationTotalDisplayed + "]";
}
}
This is usually caused by a known issue where a database column is defined as a NUMBER but an attempt is made to insert null into it. If you are using Integer values make sure they are initialised to an actual value and that they are not null.
That may be the problem here but it is difficult to tell as the names of methods and the names of database columns do not match, and it is difficult to cross check that all values have been initialised.

Limit Results from One to Many Relationship

/*
* 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 com.sanu.siri.entity;
import javax.persistence.*;
import java.sql.Blob;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
* #author Sanu AK
*/
#Entity
#Table(name = "Parts")
public class Parts implements SuperEntity {
#Id
#GeneratedValue(strategy = GenerationType.TABLE, generator = "map")
#TableGenerator(name = "map", table = "Id_Gen", pkColumnName = "Tables_Names", valueColumnName = "Gen_keys", pkColumnValue = "PartsDTO", initialValue = 1, allocationSize = 1)
private int id;
private String partName;
private String partNumber;
private String barCode;
private String brand;
private String partType;
private String country;
private String vehicleModel;
private String packSize;
private String location;
private String rackNo;
private String roq;
private String rql;
#Column(name = "imageUrl1")
private String imageUrl1;
#Column(name = "imageUrl2")
private String imageUrl2;
#Column(name = "imageUrl3")
private String imageUrl3;
#Column(name = "imageUrl4")
private String imageUrl4;
private Blob image;
private Blob image1;
private Blob image2;
private Blob image3;
private String warranty;
private Date adedDate;
#Enumerated(value = EnumType.STRING)
private Catogary catogary;
#ManyToMany(cascade = CascadeType.DETACH, fetch = FetchType.LAZY)
#JoinTable(name = "Parts_FuelType",
joinColumns = {#JoinColumn(name = "part_ID", referencedColumnName = "id")},
inverseJoinColumns = {#JoinColumn(name = "fuel_Type", referencedColumnName = "id")})
private List<FuelType> fuelTypes = new ArrayList<>();
#OneToMany(mappedBy = "parts", cascade = CascadeType.DETACH, fetch = FetchType.LAZY)
private List<OrderDetails> orderDetail = new ArrayList<>();
#OneToMany(mappedBy = "parts", cascade = CascadeType.DETACH, fetch = FetchType.LAZY)
#OrderBy("date DESC")
private List<Bulk> bulks = new ArrayList<>();
public Parts() {
}
public Parts(String partName, String partNumber, String barCode, String brand, String partType, String country, String vehicleModel, String packSize, String location, String rackNo, String roq, String rql, Blob image, Blob image1, Blob image2, Blob image3, String warranty, Date adedDate, Catogary catogary, List<FuelType> fuelTypes, List<OrderDetails> orderDetail, List<Bulk> bulks) {
this.partName = partName;
this.partNumber = partNumber;
this.barCode = barCode;
this.brand = brand;
this.partType = partType;
this.country = country;
this.vehicleModel = vehicleModel;
this.packSize = packSize;
this.location = location;
this.rackNo = rackNo;
this.roq = roq;
this.rql = rql;
this.image = image;
this.image1 = image1;
this.image2 = image2;
this.image3 = image3;
this.warranty = warranty;
this.adedDate = adedDate;
this.catogary = catogary;
this.fuelTypes = fuelTypes;
this.orderDetail = orderDetail;
this.bulks = bulks;
}
public Parts(int id, String partName, String partNumber, String barCode, String brand, String partType, String country, String vehicleModel, String packSize, String location, String rackNo, String roq, String rql, String imageUrl1, String imageUrl2, String imageUrl3, String imageUrl4, Blob image, Blob image1, Blob image2, Blob image3, String warranty, Date adedDate, Catogary catogary, List<FuelType> fuelTypes, List<OrderDetails> orderDetail, List<Bulk> bulks) {
this.setId(id);
this.partName = partName;
this.partNumber = partNumber;
this.barCode = barCode;
this.brand = brand;
this.partType = partType;
this.country = country;
this.vehicleModel = vehicleModel;
this.packSize = packSize;
this.location = location;
this.rackNo = rackNo;
this.roq = roq;
this.rql = rql;
this.imageUrl1 = imageUrl1;
this.imageUrl2 = imageUrl2;
this.imageUrl3 = imageUrl3;
this.imageUrl4 = imageUrl4;
this.image = image;
this.image1 = image1;
this.image2 = image2;
this.image3 = image3;
this.warranty = warranty;
this.adedDate = adedDate;
this.catogary = catogary;
this.fuelTypes = fuelTypes;
this.orderDetail = orderDetail;
this.bulks = bulks;
}
public String getImageUrl1() {
return imageUrl1;
}
public void setImageUrl1(String imageUrl1) {
this.imageUrl1 = imageUrl1;
}
public String getImageUrl2() {
return imageUrl2;
}
public void setImageUrl2(String imageUrl2) {
this.imageUrl2 = imageUrl2;
}
public String getImageUrl3() {
return imageUrl3;
}
public void setImageUrl3(String imageUrl3) {
this.imageUrl3 = imageUrl3;
}
public String getImageUrl4() {
return imageUrl4;
}
public void setImageUrl4(String imageUrl4) {
this.imageUrl4 = imageUrl4;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getPartName() {
return partName;
}
public void setPartName(String partName) {
this.partName = partName;
}
public String getPartNumber() {
return partNumber;
}
public void setPartNumber(String partNumber) {
this.partNumber = partNumber;
}
public String getBarCode() {
return barCode;
}
public void setBarCode(String barCode) {
this.barCode = barCode;
}
public String getBrand() {
return brand;
}
public void setBrand(String brand) {
this.brand = brand;
}
public String getPartType() {
return partType;
}
public void setPartType(String partType) {
this.partType = partType;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public String getVehicleModel() {
return vehicleModel;
}
public void setVehicleModel(String vehicleModel) {
this.vehicleModel = vehicleModel;
}
public String getPackSize() {
return packSize;
}
public void setPackSize(String packSize) {
this.packSize = packSize;
}
public String getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location;
}
public String getRackNo() {
return rackNo;
}
public void setRackNo(String rackNo) {
this.rackNo = rackNo;
}
public String getRoq() {
return roq;
}
public void setRoq(String roq) {
this.roq = roq;
}
public String getRql() {
return rql;
}
public void setRql(String rql) {
this.rql = rql;
}
public Blob getImage() {
return image;
}
public void setImage(Blob image) {
this.image = image;
}
public Blob getImage1() {
return image1;
}
public void setImage1(Blob image1) {
this.image1 = image1;
}
public Blob getImage2() {
return image2;
}
public void setImage2(Blob image2) {
this.image2 = image2;
}
public Blob getImage3() {
return image3;
}
public void setImage3(Blob image3) {
this.image3 = image3;
}
public String getWarranty() {
return warranty;
}
public void setWarranty(String warranty) {
this.warranty = warranty;
}
public Date getAdedDate() {
return adedDate;
}
public void setAdedDate(Date adedDate) {
this.adedDate = adedDate;
}
public Catogary getCatogary() {
return catogary;
}
public void setCatogary(Catogary catogary) {
this.catogary = catogary;
}
public List<FuelType> getFuelTypes() {
return fuelTypes;
}
public void setFuelTypes(List<FuelType> fuelTypes) {
this.fuelTypes = fuelTypes;
}
public List<OrderDetails> getOrderDetail() {
return orderDetail;
}
public void setOrderDetail(List<OrderDetails> orderDetail) {
this.orderDetail = orderDetail;
}
public List<Bulk> getBulks() {
return bulks;
}
public void setBulks(List<Bulk> bulks) {
this.bulks = bulks;
}
#Override
public String toString() {
return "Parts{" +
"id=" + id +
", partName='" + partName + '\'' +
", partNumber='" + partNumber + '\'' +
", barCode='" + barCode + '\'' +
", brand='" + brand + '\'' +
", partType='" + partType + '\'' +
", country='" + country + '\'' +
", vehicleModel='" + vehicleModel + '\'' +
", packSize='" + packSize + '\'' +
", location='" + location + '\'' +
", rackNo='" + rackNo + '\'' +
", roq='" + roq + '\'' +
", rql='" + rql + '\'' +
", image=" + image +
", image1=" + image1 +
", image2=" + image2 +
", image3=" + image3 +
", warranty='" + warranty + '\'' +
", adedDate=" + adedDate +
", catogary=" + catogary +
", fuelTypes=" + fuelTypes +
", orderDetail=" + orderDetail +
", bulks=" + bulks +
'}';
}
}
I have a problem about this row. Is there any way to limit those BulkList when we call this BulkList from Part.
#OrderBy("date DESC")
private List<Bulk> bulks = new ArrayList<>();
I mean like this
This is My Repo
public interface PartsRepo extends CrudRepository<Parts, Integer> {
Parts findPartsByBarCode(String barCode) throws Exception;
List<Parts> findPartsByPartNameContaining(String partName) throws Exception;
List<Parts> findPartsByPartNumberContaining(String partNumber) throws Exception;
Parts findPartsByPartNumber(String partNumber) throws Exception;
}
This is my Controller
#GetMapping(value = "/search")
public void searchParts(HttpServletRequest req) {
try {
return
Parts
p=partsService.searchParts(Integer.parseInt(req.getParameter("id")));
List<Bulk> bulkList=p.getBulks();
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
I want to limit the bulkList results from the entity.. is there any way to do that..?
List<Bulk> bulkList=p.getBulks();
limit above list from the
#OrderBy("date DESC")
private List<Bulk> bulks = new ArrayList<>();
review
I have a problem about this row is there any way to limit those BulkList when we call this BulkList from Part.
I want to limit the bulkList results from the entity. Is there any way to do that?
#OneToMany(mappedBy = "bulk", cascade=CascadeType.PERSIST, fetch=LAZY)
#BatchSize(size=5)
private List<Bulk> bulks = new ArrayList<>();
You can do this way

facing 415: Unsupported Media Type error in spring rest

I have created rest api to save academic master using spring rest as below
#Secured("ROLE_ADMIN")
#RequestMapping(value = RestURIConstants.SAVE_ACADEMIC_YEAR, method = RequestMethod.POST)
public #ResponseBody AcademicYear saveAcademicYear(#RequestBody AcademicYear academicYear)
{
logger.info("saving academic year master");
academicYear = commonService.saveAcademicYear(academicYear);
return academicYear;
}
Entity AcademicYear is as below
#Entity
#Table(name = "COM_ACADEMIC_YEAR_MST")
#JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "yearId")
public class AcademicYear implements java.io.Serializable
{
private static final long serialVersionUID = -8195008327271076910L;
#Id
#Column(name = "YEAR_ID")
#GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer yearId;
#Column(name = "YEAR_START_DT")
#Temporal(TemporalType.TIMESTAMP)
#JsonSerialize(using = DateSerializer.class)
#JsonDeserialize(using = DateDeserializer.class)
private Date yearStartDate;
#Column(name = "YEAR_END_DT")
#Temporal(TemporalType.TIMESTAMP)
#JsonSerialize(using = DateSerializer.class)
#JsonDeserialize(using = DateDeserializer.class)
private Date yearEndDate;
#OneToMany(fetch = FetchType.LAZY, mappedBy = "academicYear", cascade = CascadeType.ALL)
List<CourseMaster> courseMaster;
#Column(name = "YEAR_STATUS")
Integer yearStatus;
#Column(name = "CREATED_DT")
#Temporal(TemporalType.TIMESTAMP)
private Date createdDate;
#Column(name = "CREATED_BY")
private String createdBy;
#Column(name = "UPDATED_DT")
#Temporal(TemporalType.TIMESTAMP)
private Date updatedDate;
#Column(name = "UPDATED_BY")
private String updatedBy;
#Column(name = "RECORD_STATUS")
private String recordStatus = "A";
public Integer getYearId()
{
return yearId;
}
public void setYearId(Integer yearId)
{
this.yearId = yearId;
}
public Date getYearStartDate()
{
return yearStartDate;
}
public void setYearStartDate(Date yearStartDate)
{
this.yearStartDate = yearStartDate;
}
public Date getYearEndDate()
{
return yearEndDate;
}
public void setYearEndDate(Date yearEndDate)
{
this.yearEndDate = yearEndDate;
}
public Integer getYearStatus()
{
return yearStatus;
}
public void setYearStatus(Integer yearStatus)
{
this.yearStatus = yearStatus;
}
public Date getCreatedDate()
{
return createdDate;
}
public void setCreatedDate(Date createdDate)
{
this.createdDate = createdDate;
}
public String getCreatedBy()
{
return createdBy;
}
public void setCreatedBy(String createdBy)
{
this.createdBy = createdBy;
}
public Date getUpdatedDate()
{
return updatedDate;
}
public void setUpdatedDate(Date updatedDate)
{
this.updatedDate = updatedDate;
}
public String getUpdatedBy()
{
return updatedBy;
}
public void setUpdatedBy(String updatedBy)
{
this.updatedBy = updatedBy;
}
public String getRecordStatus()
{
return recordStatus;
}
public void setRecordStatus(String recordStatus)
{
this.recordStatus = recordStatus;
}
public static long getSerialversionuid()
{
return serialVersionUID;
}
#Override
public String toString()
{
return "AcademicYear [yearId=" + yearId + ", yearStartDate=" + yearStartDate + ", yearEndDate=" + yearEndDate
+ ", yearStatus=" + yearStatus + ", createdDate=" + createdDate + ", createdBy=" + createdBy
+ ", updatedDate=" + updatedDate + ", updatedBy=" + updatedBy + ", recordStatus=" + recordStatus + "]";
}
public List<CourseMaster> getCourseMaster()
{
return courseMaster;
}
public void setCourseMaster(List<CourseMaster> courseMaster)
{
this.courseMaster = courseMaster;
}
}
but when i try to execute the api as below
{"yearStartDate":"01-01-2015"} ,i am sending header as Content-Type: application/json
i am facing the 415: Unsupported Media Type error
i got the root cause of the issue it is at below line
OneToMany(fetch = FetchType.LAZY, mappedBy = "academicYear", cascade = CascadeType.ALL) List<CourseMaster> courseMaster;
if i removes this line it works.

Categories

Resources