How to use detailed SQL query on Srpingboot using #Query? - java

I'm having some trouble to find out how to use an specific query on Springboot
SELECT tb_excursao.fk_cliente, tb_cliente.nome, tb_cliente.documento, tb_cliente.org_emissor, tb_cliente.data_nascimento, tb_excursao.fk_viagem, tb_viagens.destino, tb_viagens.data_viagem
FROM ((tb_excursao
INNER JOIN tb_cliente ON fk_cliente = tb_cliente.id_cliente)
INNER JOIN tb_viagens ON fk_viagem = tb_viagens.id_viagem))
This works fine on MySQL, but the examples that I saw it's always something like "SELECT u FROM User u", and as a beginner I can't relate using columns from different tables using #Query.
The models are below:
Cliente.java
#Entity
#Table(name = "tb_cliente")
public class Cliente {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private long idCliente;
#NotBlank
#Size(min = 3)
private String nome;
#NotNull
private String documento;
#NotNull
private String orgEmissor;
#NotBlank
#JsonFormat(pattern = "dd/MM/yyyy")
private Date dataNascimento;
#Temporal(TemporalType.TIMESTAMP)
private Date dataCadastro = new java.sql.Date(System.currentTimeMillis());
#OneToMany(mappedBy = "fkCliente")
Set<Excursao> excursao;
public long getIdCliente() {
return idCliente;
}
public void setIdCliente(long idCliente) {
this.idCliente = idCliente;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getDocumento() {
return documento;
}
public void setDocumento(String documento) {
this.documento = documento;
}
public String getOrgEmissor() {
return orgEmissor;
}
public void setOrgEmissor(String orgEmissor) {
this.orgEmissor = orgEmissor;
}
public Date getDataNascimento() {
return dataNascimento;
}
public void setDataNascimento(Date dataNascimento) {
this.dataNascimento = dataNascimento;
}
public Date getDataCadastro() {
return dataCadastro;
}
public void setDataCadastro(Date dataCadastro) {
this.dataCadastro = dataCadastro;
}
}
Viagem.java
#Entity
#Table(name = "tb_viagens")
public class Viagem {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private long idViagem;
#NotBlank
private String destino;
#NotBlank
#JsonFormat(pattern = "dd/MM/yyyy")
private Date dataViagem;
#NotBlank
private int quantidadeMaxPessoas;
#OneToMany(mappedBy = "fkViagem")
private Set<Excursao> excursao;
public long getIdViagem() {
return idViagem;
}
public void setIdViagem(long idViagem) {
this.idViagem = idViagem;
}
public String getDestino() {
return destino;
}
public void setDestino(String destino) {
this.destino = destino;
}
public Date getDataViagem() {
return dataViagem;
}
public void setDataViagem(Date dataViagem) {
this.dataViagem = dataViagem;
}
public int getQuantidadeMaxPessoas() {
return quantidadeMaxPessoas;
}
public void setQuantidadeMaxPessoas(int quantidadeMaxPessoas) {
this.quantidadeMaxPessoas = quantidadeMaxPessoas;
}
}
ExcursaoEmbeddable.java
#Embeddable
public class ExcursaoEmb implements Serializable {
#Column(name = "fkCliente")
private Long fkCliente;
#Column(name = "fkViagem")
private Long fkViagem;
public Long getFkCliente() {
return this.fkCliente;
}
public void setFkCliente(Long fkCliente) {
this.fkCliente = fkCliente;
}
public Long getFkViagem() {
return this.fkViagem;
}
public void setFkViagem(Long fkViagem) {
this.fkViagem = fkViagem;
}
}
Excursao.java This is the table that the query in the beginning of the post goes
#Entity
#Table(name = "tb_excursao")
public class Excursao {
#EmbeddedId
ExcursaoEmb idExcursao;
#ManyToOne
#JoinColumn(name = "id_cliente")
private Cliente fkCliente;
#ManyToOne
#JoinColumn(name = "id_viagem")
private Viagem fkViagem;
#NotNull
private boolean primeiraParcela;
#NotNull
private boolean segundaParcela;
private boolean terceiraParcela;
public ExcursaoEmb getIdExcursao() {
return this.idExcursao;
}
public void setIdExcursao(ExcursaoEmb idExcursao) {
this.idExcursao = idExcursao;
}
public Cliente getFkCliente() {
return this.fkCliente;
}
public void setFkCliente(Cliente fkCliente) {
this.fkCliente = fkCliente;
}
public Viagem getFkViagem() {
return this.fkViagem;
}
public void setFkViagem(Viagem fkViagem) {
this.fkViagem = fkViagem;
}
public boolean isPrimeiraParcela() {
return this.primeiraParcela;
}
public boolean getPrimeiraParcela() {
return this.primeiraParcela;
}
public void setPrimeiraParcela(boolean primeiraParcela) {
this.primeiraParcela = primeiraParcela;
}
public boolean isSegundaParcela() {
return this.segundaParcela;
}
public boolean getSegundaParcela() {
return this.segundaParcela;
}
public void setSegundaParcela(boolean segundaParcela) {
this.segundaParcela = segundaParcela;
}
public boolean isTerceiraParcela() {
return this.terceiraParcela;
}
public boolean getTerceiraParcela() {
return this.terceiraParcela;
}
public void setTerceiraParcela(boolean terceiraParcela) {
this.terceiraParcela = terceiraParcela;
}
}

Related

Hibernate ResultTransformer returning map with all null values

I am trying to prepate a list of maps, where each map represents a row of table data having keys as column names and values are column values i.e., Map. I could able to prepare the list of maps, but except Id column all other column values are returning as null. could you please help on this. Whats wrong with my code. There are no NullPointer exception for sessionfactory access with below code
Criteria crt = session.createCriteria(SampleCsv.class)
.add( Restrictions.between("Id", 3, 6) )
.setResultTransformer(new BasicTransformerAdapter() {
#SuppressWarnings("deprecation")
#Override
public Object transformTuple(Object[] tuple, String[] aliases) {
PassThroughResultTransformer rt = PassThroughResultTransformer.INSTANCE;
final Object o = rt.transformTuple(tuple, aliases);
ClassMetadata cm = getSessionFactory().getClassMetadata(o.getClass());
List<String> pns = new ArrayList<String>(Arrays.asList(cm.getPropertyNames()));
Map<String, Object> m = new HashMap<String, Object>();
for(String pn : pns) {
m.put(pn, cm.getPropertyValue(o, pn));
}
m.put(cm.getIdentifierPropertyName(), cm.getIdentifier(o));
return m;
}
});
List<Map<String,Object>> aliasToValueMap = (List<Map<String, Object>>)crt.list();
and my pojo class is
#Entity
#Table(name="SAMPLE_CSV")
public class SampleCsv {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
#Column(name="ID", nullable = false)
private int Id;
#Column(name = "Type", nullable = true)
private String Type;
#Column(name = "NomMedia")
private String NomMedia;
#Column(name = "sRep")
private String sRep;
#Column(name = "UrlMedia")
private String UrlMedia;
#Column(name = "Indice")
private String Indice;
#Column(name = "CodeFourSAP")
private String CodeFourSAP;
#Column(name = "NomDepositaire")
private String NomDepositaire;
#Column(name = "PrenomDepositaire")
private String PrenomDepositaire;
#Column(name = "EMailDepositaire")
private String EMailDepositaire;
#Column(name = "DateDepot")
private String DateDepot;
#Column(name = "PhotoPrincipale")
private String PhotoPrincipale;
#Column(name = "NomPhotographe")
private String NomPhotographe;
#Column(name = "PrenomPhotographe")
private String PrenomPhotographe;
#Column(name = "SocieteProprietaireDesDroits")
private String SocieteProprietaireDesDroits;
#Column(name = "DateCreationOuModificationMediaH")
private String DateCreationOuModificationMediaH;
#Column(name = "Commentaire")
private String Commentaire;
#Column(name = "WEB_Valide")
private String WEB_Valide;
#Column(name = "WEB_DateValidation")
private String WEB_DateValidation;
#Column(name = "WEB_ValidePar")
private String WEB_ValidePar;
#Column(name = "WEB_Classement")
private String WEB_Classement;
#Column(name = "CreditPhoto")
private String CreditPhoto;
#Column(name = "WEB_Commentaire")
private String WEB_Commentaire;
#Column(name = "NB_IMAGES")
private String NB_IMAGES;
#Column(name = "Watermark")
private String Watermark;
#Column(name = "Zoom")
private String Zoom;
#Column(name = "Traite")
private String Traite;
#Column(name = "TailleX")
private String TailleX;
#Column(name = "TailleY")
private String TailleY;
#Column(name = "MediaH_CodeArtSAP")
private String MediaH_CodeArtSAP;
#Column(name = "RefLoueur")
private String RefLoueur;
#Column(name = "Extension")
private String Extension;
#Column(name = "MediaP_CodeArtSAP")
private String MediaP_CodeArtSAP;
#Column(name = "DateDebutDroit")
private String DateDebutDroit;
#Column(name = "DateFinDroit")
private String DateFinDroit;
#Column(name = "DateCreationOuModificationCopyright")
private String DateCreationOuModificationCopyright;
public int getId() {
return Id;
}
public void setId(int id) {
this.Id = id;
}
public String getType() {
return Type;
}
public void setType(String type) {
Type = type;
}
public String getNomMedia() {
return NomMedia;
}
public void setNomMedia(String nomMedia) {
NomMedia = nomMedia;
}
public String getsRep() {
return sRep;
}
public void setsRep(String sRep) {
this.sRep = sRep;
}
public String getUrlMedia() {
return UrlMedia;
}
public void setUrlMedia(String urlMedia) {
UrlMedia = urlMedia;
}
public String getIndice() {
return Indice;
}
public void setIndice(String indice) {
Indice = indice;
}
public String getCodeFourSAP() {
return CodeFourSAP;
}
public void setCodeFourSAP(String codeFourSAP) {
CodeFourSAP = codeFourSAP;
}
public String getNomDepositaire() {
return NomDepositaire;
}
public void setNomDepositaire(String nomDepositaire) {
NomDepositaire = nomDepositaire;
}
public String getPrenomDepositaire() {
return PrenomDepositaire;
}
public void setPrenomDepositaire(String prenomDepositaire) {
PrenomDepositaire = prenomDepositaire;
}
public String getEMailDepositaire() {
return EMailDepositaire;
}
public void setEMailDepositaire(String eMailDepositaire) {
EMailDepositaire = eMailDepositaire;
}
public String getDateDepot() {
return DateDepot;
}
public void setDateDepot(String dateDepot) {
DateDepot = dateDepot;
}
public String getPhotoPrincipale() {
return PhotoPrincipale;
}
public void setPhotoPrincipale(String photoPrincipale) {
PhotoPrincipale = photoPrincipale;
}
public String getNomPhotographe() {
return NomPhotographe;
}
public void setNomPhotographe(String nomPhotographe) {
NomPhotographe = nomPhotographe;
}
public String getPrenomPhotographe() {
return PrenomPhotographe;
}
public void setPrenomPhotographe(String prenomPhotographe) {
PrenomPhotographe = prenomPhotographe;
}
public String getSocieteProprietaireDesDroits() {
return SocieteProprietaireDesDroits;
}
public void setSocieteProprietaireDesDroits(String societeProprietaireDesDroits) {
SocieteProprietaireDesDroits = societeProprietaireDesDroits;
}
public String getDateCreationOuModificationMediaH() {
return DateCreationOuModificationMediaH;
}
public void setDateCreationOuModificationMediaH(
String dateCreationOuModificationMediaH) {
DateCreationOuModificationMediaH = dateCreationOuModificationMediaH;
}
public String getCommentaire() {
return Commentaire;
}
public void setCommentaire(String commentaire) {
Commentaire = commentaire;
}
public String getWEB_Valide() {
return WEB_Valide;
}
public void setWEB_Valide(String wEB_Valide) {
WEB_Valide = wEB_Valide;
}
public String getWEB_DateValidation() {
return WEB_DateValidation;
}
public void setWEB_DateValidation(String wEB_DateValidation) {
WEB_DateValidation = wEB_DateValidation;
}
public String getWEB_ValidePar() {
return WEB_ValidePar;
}
public void setWEB_ValidePar(String wEB_ValidePar) {
WEB_ValidePar = wEB_ValidePar;
}
public String getWEB_Classement() {
return WEB_Classement;
}
public void setWEB_Classement(String wEB_Classement) {
WEB_Classement = wEB_Classement;
}
public String getCreditPhoto() {
return CreditPhoto;
}
public void setCreditPhoto(String creditPhoto) {
CreditPhoto = creditPhoto;
}
public String getWEB_Commentaire() {
return WEB_Commentaire;
}
public void setWEB_Commentaire(String wEB_Commentaire) {
WEB_Commentaire = wEB_Commentaire;
}
public String getNB_IMAGES() {
return NB_IMAGES;
}
public void setNB_IMAGES(String nB_IMAGES) {
NB_IMAGES = nB_IMAGES;
}
public String getWatermark() {
return Watermark;
}
public void setWatermark(String watermark) {
Watermark = watermark;
}
public String getZoom() {
return Zoom;
}
public void setZoom(String zoom) {
Zoom = zoom;
}
public String getTraite() {
return Traite;
}
public void setTraite(String traite) {
Traite = traite;
}
public String getTailleX() {
return TailleX;
}
public void setTailleX(String tailleX) {
TailleX = tailleX;
}
public String getTailleY() {
return TailleY;
}
public void setTailleY(String tailleY) {
TailleY = tailleY;
}
public String getMediaH_CodeArtSAP() {
return MediaH_CodeArtSAP;
}
public void setMediaH_CodeArtSAP(String mediaH_CodeArtSAP) {
MediaH_CodeArtSAP = mediaH_CodeArtSAP;
}
public String getRefLoueur() {
return RefLoueur;
}
public void setRefLoueur(String refLoueur) {
RefLoueur = refLoueur;
}
public String getExtension() {
return Extension;
}
public void setExtension(String extension) {
Extension = extension;
}
public String getMediaP_CodeArtSAP() {
return MediaP_CodeArtSAP;
}
public void setMediaP_CodeArtSAP(String mediaP_CodeArtSAP) {
MediaP_CodeArtSAP = mediaP_CodeArtSAP;
}
public String getDateDebutDroit() {
return DateDebutDroit;
}
public void setDateDebutDroit(String dateDebutDroit) {
DateDebutDroit = dateDebutDroit;
}
public String getDateFinDroit() {
return DateFinDroit;
}
public void setDateFinDroit(String dateFinDroit) {
DateFinDroit = dateFinDroit;
}
public String getDateCreationOuModificationCopyright() {
return DateCreationOuModificationCopyright;
}
public void setDateCreationOuModificationCopyright(
String dateCreationOuModificationCopyright) {
DateCreationOuModificationCopyright = dateCreationOuModificationCopyright;
}
}
I am posting the out put of final list with two maps as below
[{Id=3,PrenomDepositaire=null, RefLoueur=null, DateCreationOuModificationCopyright=null, EMailDepositaire=null, SocieteProprietaireDesDroits=null, NomMedia=null, TailleX=null, CodeFourSAP=null, PrenomPhotographe=null, Commentaire=null, MediaP_CodeArtSAP=null, NomDepositaire=null, WEB_Commentaire=null, UrlMedia=null, Zoom=null, TailleY=null, WEB_Valide=null, DateDepot=null, sRep=null, WEB_ValidePar=null, Indice=null, CreditPhoto=null, DateCreationOuModificationMediaH=null, MediaH_CodeArtSAP=null, DateDebutDroit=null, WEB_Classement=null, DateFinDroit=null, NB_IMAGES=null, NomPhotographe=null, PhotoPrincipale=null, Extension=null, Type=null, WEB_DateValidation=null, Traite=null, Watermark=null},
{ Id=4,PrenomDepositaire=null, RefLoueur=null, DateCreationOuModificationCopyright=null, EMailDepositaire=null, SocieteProprietaireDesDroits=null, NomMedia=null, TailleX=null, CodeFourSAP=null, PrenomPhotographe=null, Commentaire=null, MediaP_CodeArtSAP=null, NomDepositaire=null, WEB_Commentaire=null, UrlMedia=null, Zoom=null, TailleY=null, WEB_Valide=null, DateDepot=null, sRep=null, WEB_ValidePar=null, Indice=null, CreditPhoto=null, DateCreationOuModificationMediaH=null, MediaH_CodeArtSAP=null, DateDebutDroit=null, WEB_Classement=null, DateFinDroit=null, NB_IMAGES=null, NomPhotographe=null, PhotoPrincipale=null, Extension=null, Type=null, WEB_DateValidation=null, Traite=null, Watermark=null}
]
But table data having non null data as well..

How to call native query for spring repository(Join three tables and tables haven't any relationship)

I have three tables which called SLSNotification,SLSWorkflow and Importer These tables are not any relationships... I want to get three tables for jasper report.. So I create a native query for it.. It works fine on MySQL... But when i add it to the SLSWorkflowRepository retrieve only workflow class only.. I want to get other classes also from this repository... I think it retrieves only because i write this like this
#Query(value = "select * from slsnotification a join sls_wrkflw b on a.snumber = b.snumber join importers c on c.importer_vat_number = a.importervat where a.importervat = :importerVatNumber and a.snumber = :snumber", nativeQuery = true)
Object getForPrint(#Param("snumber") Long snumber,#Param("importerVatNumber") String importerVatNumber);
can i get other classes for SLSIWorkflow getForPrint() methord...
If i wrong please give some onother way...
This is my models
SLSNotification Model
#Entity
#Table(name = "slsnotification")
public class SLSNotification {
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
#Column(length = 16)
private Long snumber;
#Column(length = 100)
private String serialCord;
private String date;
// #JsonFormat(pattern = "yyyy-MM-dd")
// private Date appPostdate = new Date();
#Column(nullable = false)
private String appPostdate;
#Column(length = 8)
private String cusOffice;
#Column(length = 1)
private String cusSerial;
#Column(length = 50)
private String cusDecNo;
#JsonFormat(pattern = "yyyy-MM-dd")
private Date cusDate;
#Column(length = 300)
private String manufacturer;
#Column(length = 300)
private String exporterAddress;
#Column(length = 20, nullable = false)
private String importerVAT;
#NotEmpty
#Column(length = 20, nullable = false)
private String declarantVAT;
private String declarantDetails;
private String vessel;
private String blNo;
private String loadingPort;
private String tradingCountry;
private String countryOrigin;
private String invoiceNo;
#JsonFormat(pattern = "yyyy-MM-dd")
private Date invoiceDate;
private Double invoiceValue;
public Long getSnumber() {
return snumber;
}
public void setSnumber(Long snumber) {
this.snumber = snumber;
}
public String getSerialCord() {
return serialCord;
}
public void setSerialCord(String serialCord) {
this.serialCord = serialCord;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public String getCusOffice() {
return cusOffice;
}
public void setCusOffice(String cusOffice) {
this.cusOffice = cusOffice;
}
public String getCusSerial() {
return cusSerial;
}
public void setCusSerial(String cusSerial) {
this.cusSerial = cusSerial;
}
public String getCusDecNo() {
return cusDecNo;
}
public void setCusDecNo(String cusDecNo) {
this.cusDecNo = cusDecNo;
}
public Date getCusDate() {
return cusDate;
}
public void setCusDate(Date cusDate) {
this.cusDate = cusDate;
}
public String getManufacturer() {
return manufacturer;
}
public void setManufacturer(String manufacturer) {
this.manufacturer = manufacturer;
}
public String getExporterAddress() {
return exporterAddress;
}
public void setExporterAddress(String exporterAddress) {
this.exporterAddress = exporterAddress;
}
public String getImporterVAT() {
return importerVAT;
}
public void setImporterVAT(String importerVAT) {
this.importerVAT = importerVAT;
}
public String getDeclarantVAT() {
return declarantVAT;
}
public void setDeclarantVAT(String declarantVAT) {
this.declarantVAT = declarantVAT;
}
public String getVessel() {
return vessel;
}
public void setVessel(String vessel) {
this.vessel = vessel;
}
public String getBlNo() {
return blNo;
}
public void setBlNo(String blNo) {
this.blNo = blNo;
}
public String getLoadingPort() {
return loadingPort;
}
public void setLoadingPort(String loadingPort) {
this.loadingPort = loadingPort;
}
public String getTradingCountry() {
return tradingCountry;
}
public void setTradingCountry(String tradingCountry) {
this.tradingCountry = tradingCountry;
}
public String getCountryOrigin() {
return countryOrigin;
}
public void setCountryOrigin(String countryOrigin) {
this.countryOrigin = countryOrigin;
}
public String getInvoiceNo() {
return invoiceNo;
}
public void setInvoiceNo(String invoiceNo) {
this.invoiceNo = invoiceNo;
}
public Date getInvoiceDate() {
return invoiceDate;
}
public void setInvoiceDate(Date invoiceDate) {
this.invoiceDate = invoiceDate;
}
public Double getInvoiceValue() {
return invoiceValue;
}
public void setInvoiceValue(Double invoiceValue) {
this.invoiceValue = invoiceValue;
}
SLSWorkflow Model
#Entity
#Table(name = "sls_wrkflw")
public class SLSIWorkflow {
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
private Long SNumber;
private String qc;
private String inv;
private String manuTr;
private String packList;
private String blAttached;
private String otherDoc;
private String otherDocName;
private String ad;
private String MAUsername;
private String appMan;
private String accptdQc;
private String accptTR;
private String manufacturer;
private String validMark;
private String otherDocBoolean;
private String cnfrmtyTest;
private String dtSampling;
private String otherDocDet;
private String adUsername;
private String recom;
private String reaRec;
private String tests;
private String wfStatus;
public Long getSNumber() {
return SNumber;
}
public void setSNumber(Long SNumber) {
this.SNumber = SNumber;
}
public String getQc() {
return qc;
}
public void setQc(String qc) {
this.qc = qc;
}
public String getInv() {
return inv;
}
public void setInv(String inv) {
this.inv = inv;
}
public String getManuTr() {
return manuTr;
}
public void setManuTr(String manuTr) {
this.manuTr = manuTr;
}
public String getPackList() {
return packList;
}
public void setPackList(String packList) {
this.packList = packList;
}
public String getBlAttached() {
return blAttached;
}
public void setBlAttached(String blAttached) {
this.blAttached = blAttached;
}
public String getMaattachUser() {
return maattachUser;
}
public void setMaattachUser(String maattachUser) {
this.maattachUser = maattachUser;
}
public String getMauser() {
return mauser;
}
public void setMauser(String mauser) {
this.mauser = mauser;
}
public String getMareattachUser() {
return mareattachUser;
}
public void setMareattachUser(String mareattachUser) {
this.mareattachUser = mareattachUser;
}
public String getOtherDoc() {
return otherDoc;
}
public void setOtherDoc(String otherDoc) {
this.otherDoc = otherDoc;
}
public String getOtherDocName() {
return otherDocName;
}
public void setOtherDocName(String otherDocName) {
this.otherDocName = otherDocName;
}
}
Importer Model
#Entity
#Table(name = "importers")
public class Importer {
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
#Column(name = "importer_id")
private long importerId;
private String importerBrc;
#NotEmpty
#Column(unique = true, nullable = false)
private String importerVatNumber;
#Column(nullable = false)
private String category;
private String importerSVatNumber;
#NotEmpty
private String importerName;
private String importerAddress1;
#NotEmpty
private String officePhoneNumber;
#NotEmpty
private String mobilePhoneNumber;
#Email
#NotEmpty
private String email;
#Email
private String optemail1;
#Email
private String optemail2;
#NotEmpty
private String userIDandTime;
#NotEmpty
private String recentUpdateBy;
public String getOptemail1() {
return optemail1;
}
public void setOptemail1(String optemail1) {
this.optemail1 = optemail1;
}
public String getOptemail2() {
return optemail2;
}
public void setOptemail2(String optemail2) {
this.optemail2 = optemail2;
}
#ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
#JoinTable(name = "importer_agents",
joinColumns = {
#JoinColumn(name = "importerId")},
inverseJoinColumns = {
#JoinColumn(name = "agentId")})
private List<Agent> agentList;
public String getImporterBrc() {
return importerBrc;
}
public void setImporterBrc(String importerBrc) {
this.importerBrc = importerBrc;
}
public String getImporterVatNumber() {
return importerVatNumber;
}
public void setImporterVatNumber(String importerVatNumber) {
this.importerVatNumber = importerVatNumber;
}
public String getCategory() {
return category;
}
public void setCategory(String category) {
this.category = category;
}
public String getImporterSVatNumber() {
return importerSVatNumber;
}
public void setImporterSVatNumber(String importerSVatNumber) {
this.importerSVatNumber = importerSVatNumber;
}
public String getImporterName() {
return importerName;
}
public void setImporterName(String importerName) {
this.importerName = importerName;
}
public String getImporterAddress1() {
return importerAddress1;
}
public void setImporterAddress1(String importerAddress1) {
this.importerAddress1 = importerAddress1;
}
}
SLSIWorkflowRepository
public interface SLSIWorkflowRepository extends CrudRepository<SLSIWorkflow,Long> {
#Override
SLSIWorkflow save(SLSIWorkflow slsiWorkflow);
#Override
SLSIWorkflow findOne(Long Long);
#Override
boolean exists(Long Long);
#Override
Iterable<SLSIWorkflow> findAll();
#Override
long count();
#Override
void delete(SLSIWorkflow entity);
#Query(value = "select * from slsnotification a join sls_wrkflw b on a.snumber = b.snumber join importers c on c.importer_vat_number = a.importervat where a.importervat = :importerVatNumber and a.snumber = :snumber", nativeQuery = true)
Object getForPrint(#Param("snumber") Long snumber,#Param("importerVatNumber") String importerVatNumber);
WorkflowServices
public class WorkflowServices {
private static final Logger serviceLogger = LogManager.getLogger(WorkflowServices.class);
private static final String INIT_WORKFLOW_STATUS = "INIT";
#Autowired
private SLSIWorkflowRepository workflowRepository;
#Autowired
private FileSystemStorageService storageService;
#Autowired
private SLSNotificationRepository slsNotificationRepository;
public void initWorkflow(Long slsNumber) {
SLSIWorkflow workflow = new SLSIWorkflow();
workflow.setSNumber(slsNumber);
workflow.setWfStatus(INIT_WORKFLOW_STATUS);
workflowRepository.save(workflow);
}
public SLSIWorkflow getApplicationForPrint(Long SNumber, String importerVatNumber) {
return workflowRepository.getForPrint(SNumber, importerVatNumber);
}
}
Workflow Controller //this is large and i gives my cord only
#RequestMapping(path = "/viewTAXInvoice/{snumber}/{importerVatNumber}", method = RequestMethod.POST)
public ModelAndView getPDFReport(#PathVariable("snumber") String snumber, #PathVariable("importerVatNumber") String importerVatNumber) {
File reportsDir = Paths.get(servletContext.getRealPath(reportDataLocation)).toFile();
if (!reportsDir.exists()) {
throw ProductWithSameSerialExistsException.getInstance();
}
JRDataSource dataSource = new JRBeanCollectionDataSource(Arrays.asList(workflowServices.getApplicationForPrint(Long.parseLong(snumber), importerVatNumber)));
Map<String, Object> parameterMap = new HashMap<>();
parameterMap.put("datasource", dataSource);
parameterMap.put("JasperCustomSubReportDatasource", dataSource);
parameterMap.put(JRParameter.REPORT_FILE_RESOLVER, new SimpleFileResolver(reportsDir));
System.out.println("Dt Source1 "+dataSource);
return new ModelAndView("pdfReportforVAT", parameterMap);
}
How to connect three tables... Please help me someone...
You are getting a SLSIWorkflow only because you are returning that Entity only in the following code in WorkflowServices.
public SLSIWorkflow getApplicationForPrint(Long SNumber, String importerVatNumber) {
return workflowRepository.getForPrint(SNumber, importerVatNumber);
}
If you return an Object it will have all the fields from tables slsnotification, sls_wrkflw, importers as a Object[].
Plus using a Plain JOIN it will result in an INNER JOIN by default. This will not return anything if one joined table doesn't satisfy the ON criteria. It is good if you use LEFT JOIN so that the null will be returned.

com.fasterxml.jackson.databind.JsonMappingException: Infinite recursion (StackOverflowError)

I'm trying implement a rest service. I have created my entitys and daos, and when use this everthyng works fine.
But when I trye expose the information in rest json, the infinite recursion error occur.
I have read many topic about this error, but not is so clear for me.
I'm have tried so many alternatives that is hard talk about each.
When I debug my code, I see that the data from dao is correctly, the problem occur when I trie use json. Whe I use jsf page works fine.
I have tried use Gson and return String in my rest method, but stackoverflow error occur to.
Bellow I post my implememtation (all), because a dont have idea about the problem.
I using wildfly server...
Thanks in advance
Model's
#Entity
#Table(name="usertable")
#NamedQuery(name="UserModel.findAll", query="SELECT u FROM UserModel u")
#XmlRootElement
public class UserModel implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy=GenerationType.AUTO)
#Column(unique=true, nullable=false)
private String USId;
#Temporal(TemporalType.DATE)
#Column(nullable=false)
private Date userNascimento;
#Column(nullable=false, length=45)
private String USMail;
#Column(nullable=false, length=150)
private String USName;
#Column(nullable=false, length=45)
private String USNick;
#Column(nullable=false, length=45)
private String USPassword;
//bi-directional many-to-one association to UserAddressModel
#OneToMany(fetch = FetchType.EAGER, mappedBy="usertable")
private List<UserAddressModel> listAddressModel;
//bi-directional many-to-one association to UserFoneModel
#OneToMany(fetch = FetchType.EAGER, mappedBy="usertable")
private List<UserFoneModel> listFoneModel;
public UserModel() {
}
public String getUSId() {
return this.USId;
}
public void setUSId(String USId) {
this.USId = USId;
}
public Date getUserNascimento() {
return this.userNascimento;
}
public void setUserNascimento(Date userNascimento) {
this.userNascimento = userNascimento;
}
public String getUSMail() {
return this.USMail;
}
public void setUSMail(String USMail) {
this.USMail = USMail;
}
public String getUSName() {
return this.USName;
}
public void setUSName(String USName) {
this.USName = USName;
}
public String getUSNick() {
return this.USNick;
}
public void setUSNick(String USNick) {
this.USNick = USNick;
}
public String getUSPassword() {
return this.USPassword;
}
public void setUSPassword(String USPassword) {
this.USPassword = USPassword;
}
public List<UserAddressModel> getUseraddresstables() {
return this.listAddressModel;
}
public void setUseraddresstables(List<UserAddressModel> useraddresstables) {
this.listAddressModel = useraddresstables;
}
public UserAddressModel addUseraddresstable(UserAddressModel useraddresstable) {
getUseraddresstables().add(useraddresstable);
useraddresstable.setUsertable(this);
return useraddresstable;
}
public UserAddressModel removeUseraddresstable(UserAddressModel useraddresstable) {
getUseraddresstables().remove(useraddresstable);
useraddresstable.setUsertable(null);
return useraddresstable;
}
public List<UserFoneModel> getUserfonetables() {
return this.listFoneModel;
}
public void setUserfonetables(List<UserFoneModel> userfonetables) {
this.listFoneModel = userfonetables;
}
public UserFoneModel addUserfonetable(UserFoneModel userfonetable) {
getUserfonetables().add(userfonetable);
userfonetable.setUsertable(this);
return userfonetable;
}
public UserFoneModel removeUserfonetable(UserFoneModel userfonetable) {
getUserfonetables().remove(userfonetable);
userfonetable.setUsertable(null);
return userfonetable;
}
}
#Entity
#Table(name="userfonetable")
#NamedQuery(name="UserFoneModel.findAll", query="SELECT u FROM UserFoneModel u")
public class UserFoneModel implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy=GenerationType.AUTO)
#Column(unique=true, nullable=false)
private String UFId;
#Column(nullable=false)
private short UFDdd;
#Column(nullable=false)
private int UFFone;
//bi-directional many-to-one association to UserModel
#ManyToOne
#JoinColumn(name="UFUserID", nullable=false)
private UserModel usertable;
//bi-directional many-to-one association to OperadorasModel
#ManyToOne
#JoinColumn(name="UFOperadoraID", nullable=false)
private OperadorasModel operadorastable;
//bi-directional many-to-one association to TiposFoneModel
#ManyToOne
#JoinColumn(name="UFTipoTelefone", nullable=false)
private TiposFoneModel tbTipostelefone;
public UserFoneModel() {
}
public String getUFId() {
return this.UFId;
}
public void setUFId(String UFId) {
this.UFId = UFId;
}
public short getUFDdd() {
return this.UFDdd;
}
public void setUFDdd(short UFDdd) {
this.UFDdd = UFDdd;
}
public int getUFFone() {
return this.UFFone;
}
public void setUFFone(int UFFone) {
this.UFFone = UFFone;
}
public UserModel getUsertable() {
return this.usertable;
}
public void setUsertable(UserModel usertable) {
this.usertable = usertable;
}
public OperadorasModel getOperadorastable() {
return this.operadorastable;
}
public void setOperadorastable(OperadorasModel operadorastable) {
this.operadorastable = operadorastable;
}
public TiposFoneModel getTbTipostelefone() {
return this.tbTipostelefone;
}
public void setTbTipostelefone(TiposFoneModel tbTipostelefone) {
this.tbTipostelefone = tbTipostelefone;
}
}
#Entity
#Table(name="useraddresstable")
#NamedQuery(name="UserAddressModel.findAll", query="SELECT u FROM UserAddressModel u")
public class UserAddressModel implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy=GenerationType.AUTO)
#Column(unique=true, nullable=false)
private String UAId;
#Column(nullable=false, length=100)
private String UABairro;
#Column(nullable=false, length=100)
private String UACidade;
#Column(length=45)
private String UAComplemento;
#Column(nullable=false, length=2)
private String UAEstado;
#Column(nullable=false)
private int UANumero;
#Column(length=100)
private String UARua;
//bi-directional many-to-one association to UserModel
#ManyToOne
#JoinColumn(name="UAUserID", nullable=false)
private UserModel usertable;
public UserAddressModel() {
}
public String getUAId() {
return this.UAId;
}
public void setUAId(String UAId) {
this.UAId = UAId;
}
public String getUABairro() {
return this.UABairro;
}
public void setUABairro(String UABairro) {
this.UABairro = UABairro;
}
public String getUACidade() {
return this.UACidade;
}
public void setUACidade(String UACidade) {
this.UACidade = UACidade;
}
public String getUAComplemento() {
return this.UAComplemento;
}
public void setUAComplemento(String UAComplemento) {
this.UAComplemento = UAComplemento;
}
public String getUAEstado() {
return this.UAEstado;
}
public void setUAEstado(String UAEstado) {
this.UAEstado = UAEstado;
}
public int getUANumero() {
return this.UANumero;
}
public void setUANumero(int UANumero) {
this.UANumero = UANumero;
}
public String getUARua() {
return this.UARua;
}
public void setUARua(String UARua) {
this.UARua = UARua;
}
public UserModel getUsertable() {
return this.usertable;
}
public void setUsertable(UserModel usertable) {
this.usertable = usertable;
}
}
#Entity
#Table(name="tb_tipostelefone")
#NamedQuery(name="TiposFoneModel.findAll", query="SELECT t FROM TiposFoneModel t")
public class TiposFoneModel implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy=GenerationType.AUTO)
#Column(unique=true, nullable=false)
private short TFId;
#Column(nullable=false, length=45)
private String TFDescricao;
//bi-directional many-to-one association to UserFoneModel
#OneToMany(fetch = FetchType.EAGER, mappedBy="tbTipostelefone")
private List<UserFoneModel> listFoneModel;
public TiposFoneModel() {
}
public short getTFId() {
return this.TFId;
}
public void setTFId(short TFId) {
this.TFId = TFId;
}
public String getTFDescricao() {
return this.TFDescricao;
}
public void setTFDescricao(String TFDescricao) {
this.TFDescricao = TFDescricao;
}
public List<UserFoneModel> getUserfonetables() {
return this.listFoneModel;
}
public void setUserfonetables(List<UserFoneModel> userfonetables) {
this.listFoneModel = userfonetables;
}
public UserFoneModel addUserfonetable(UserFoneModel userfonetable) {
getUserfonetables().add(userfonetable);
userfonetable.setTbTipostelefone(this);
return userfonetable;
}
public UserFoneModel removeUserfonetable(UserFoneModel userfonetable) {
getUserfonetables().remove(userfonetable);
userfonetable.setTbTipostelefone(null);
return userfonetable;
}
}
#Entity
#Table(name="operadorastable")
#NamedQuery(name="OperadorasModel.findAll", query="SELECT o FROM OperadorasModel o")
public class OperadorasModel implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy=GenerationType.AUTO)
#Column(unique=true, nullable=false)
private short OPCodigo;
#Column(nullable=false, length=100)
private String opNome;
//bi-directional many-to-one association to UserFoneModel
#OneToMany(fetch = FetchType.EAGER, mappedBy="operadorastable")
private List<UserFoneModel> listFoneModel;
public OperadorasModel() {
}
public short getOPCodigo() {
return this.OPCodigo;
}
public void setOPCodigo(short OPCodigo) {
this.OPCodigo = OPCodigo;
}
public String getOpNome() {
return this.opNome;
}
public void setOpNome(String opNome) {
this.opNome = opNome;
}
public List<UserFoneModel> getUserfonetables() {
return this.listFoneModel;
}
public void setUserfonetables(List<UserFoneModel> userfonetables) {
this.listFoneModel = userfonetables;
}
public UserFoneModel addUserfonetable(UserFoneModel userfonetable) {
getUserfonetables().add(userfonetable);
userfonetable.setOperadorastable(this);
return userfonetable;
}
public UserFoneModel removeUserfonetable(UserFoneModel userfonetable) {
getUserfonetables().remove(userfonetable);
userfonetable.setOperadorastable(null);
return userfonetable;
}
}
DAO
#Stateless
#LocalBean
public class UserDao {
/**
* Default constructor.
*/
#PersistenceContext
EntityManager em;
public UserDao() {
// TODO Auto-generated constructor stub
}
public List<UserModel> listAll()
{
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<UserModel> cq = cb.createQuery(UserModel.class);
Root<UserModel> rootEntry = cq.from(UserModel.class);
CriteriaQuery<UserModel> all = cq.select(rootEntry);
TypedQuery<UserModel> allQuery = em.createQuery(all);
List<UserModel> listU = allQuery.getResultList();
return listU;
/*
Query query = em.createQuery("SELECT u FROM UserModel u");
return query.getResultList();
*/
}
}
My Rest
import java.util.List;
import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import br.com.avera.dao.UserDao;
import br.com.avera.model.UserAddressModel;
import br.com.avera.model.UserFoneModel;
import br.com.avera.model.UserModel;
#Path("/users")
public class UserRest {
#Inject
UserDao userDao;
#GET
#Produces(MediaType.APPLICATION_JSON)
public UserModel getUser()
{
List<UserModel> userModelList = userDao.listAll();
UserModel userModel = userModelList.get(0);
List<UserFoneModel> lFone = userModel.getUserfonetables();
for (UserFoneModel userFoneModel : lFone) {
System.out.println(userFoneModel.getUFDdd());
System.out.println(userFoneModel.getUFFone());
}
System.out.println("OOOOOO");
List<UserAddressModel> lAddressModels = userModel.getUseraddresstables();
for (UserAddressModel userAddressModel : lAddressModels) {
System.out.println(userAddressModel.getUACidade());
System.out.println(userAddressModel.getUAEstado());
}
return userModel;
}
}

Retrieve objects of sub-relation Cassandra with Kundera (Pelops - JPA)

We are getting a null object while retrieving data from Cassandra using JPA annotation OneToOne/OneToMany (see example below, where "item" is null).
[
{
"idProduct":"095102f1-a987-4f7c-88c3-153d80b6977f",
"item":{
"idItem":"b75acb06-eab6-48c1-99e9-fc7d48cf930b",
"shortDescription":"Item 71",
"longDescription":"An another item 71",
"name":"Item Named 71",
"image":"Image 71"
},
"options":[
{
"idProductOption":"0fa701dc-5394-47ea-86f6-e3dbf6c263da",
"idProduct":"095102f1-a987-4f7c-88c3-153d80b6977f",
"productOptionValue":[
{
"idProductOptionValue":"1b594b56-7767-4909-9d16-add51903c0f2",
"idProductOption":"0fa701dc-5394-47ea-86f6-e3dbf6c263da",
"item":null
}
]
}
]
}
]
If we access "ProductOptionValue" directly it loads perfectly.
See it loading correctly (so, we think that's a level limitation to load).
[
{
"idProductOptionValue":"1b594b56-7767-4909-9d16-add51903c0f2",
"idProductOption":"0fa701dc-5394-47ea-86f6-e3dbf6c263da",
"item":{
"idItem":"17803826-0be6-4b94-813d-76abf969fa97",
"shortDescription":"Item 41",
"longDescription":"An item 41",
"name":"Item Named 41",
"image":"Image 41"
}
}
]
We are using the following annotations to relate the objects.
#Entity
#Table(name = "Product", schema = "kunderaexamples#cassandra_pu")
public class Product {
#Id
#Column(name = "idProduct")
private String idProduct;
#OneToMany(cascade = { CascadeType.ALL }, fetch = FetchType.EAGER)
private List<ProductOption> productOption;
#OneToOne(cascade = { CascadeType.ALL }, fetch = FetchType.EAGER)
#JoinColumn(name = "idItem", table = "Item")
private Item item;
public String getIdProduct() {
return idProduct;
}
public void setIdProduct(String idProduct) {
this.idProduct = idProduct;
}
public List<ProductOption> getOptions() {
return productOption;
}
public void setOptions(List<ProductOption> options) {
this.productOption = options;
}
public Item getItem() {
return item;
}
public void setItem(Item item) {
this.item = item;
}
public Product() {
}
}
#Entity
#Table(name = "ProductOption", schema = "kunderaexamples#cassandra_pu")
public class ProductOption {
#Id
#Column(name = "idProductOption")
private String idProductOption;
#Column(name = "idProduct")
private String idProduct;
#OneToMany(cascade = { CascadeType.ALL }, fetch = FetchType.EAGER)
private List<ProductOptionValue> productOptionValue;
public String getIdProductOption() {
return idProductOption;
}
public void setIdProductOption(String idProductOption) {
this.idProductOption = idProductOption;
}
public List<ProductOptionValue> getProductOptionValue() {
return productOptionValue;
}
public void setProductOptionValue(List<ProductOptionValue> productOptionValues) {
this.productOptionValue = productOptionValues;
}
public String getIdProduct() {
return idProduct;
}
public void setIdProduct(String idProduct) {
this.idProduct = idProduct;
}
public ProductOption() {
}
}
#Entity
#Table(name = "ProductOptionValue", schema = "kunderaexamples#cassandra_pu")
public class ProductOptionValue {
#Id
#Column(name = "idProductOptionValue")
private String idProductOptionValue;
#Column(name = "idProductOption")
private String idProductOption;
#OneToOne(cascade = { CascadeType.ALL }, fetch = FetchType.EAGER)
#JoinColumn(name = "idItem", table = "Item")
private Item item;
public String getIdProductOptionValue() {
return idProductOptionValue;
}
public void setIdProductOptionValue(String idProductOptionValue) {
this.idProductOptionValue = idProductOptionValue;
}
public Item getItem() {
return item;
}
public void setItem(Item item) {
this.item = item;
}
public String getIdProductOption() {
return idProductOption;
}
public void setIdProductOption(String idProductOption) {
this.idProductOption = idProductOption;
}
public ProductOptionValue() {
}
}
#Entity
#Table(name = "Item", schema = "kunderaexamples#cassandra_pu")
public class Item {
#Id
#Column(name = "idItem")
private String idItem;
#Column(name = "short_description")
private String shortDescription;
#Column(name = "long_description")
private String longDescription;
#Column(name = "name")
private String name;
#Column(name = "image")
private String image;
// #Column(name = "context")
// private Context context;
//
// #Column(name = "inventory")
// private Inventory inventory;
//
// #Column(name = "price")
// private ItemPrice price;
/*
* GETTERS AND SETTERS
* */
public String getIdItem() {
return idItem;
}
public void setIdItem(String idItem) {
this.idItem = idItem;
}
public String getShortDescription() {
return shortDescription;
}
public void setShortDescription(String shortDescription) {
this.shortDescription = shortDescription;
}
public String getLongDescription() {
return longDescription;
}
public void setLongDescription(String longDescription) {
this.longDescription = longDescription;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
// public Context getContext() {
// return context;
// }
//
// public void setContext(Context context) {
// this.context = context;
// }
//
// public Inventory getInventory() {
// return inventory;
// }
//
// public void setInventory(Inventory inventory) {
// this.inventory = inventory;
// }
//
// public ItemPrice getPrice() {
// return price;
// }
//
// public void setPrice(ItemPrice price) {
// this.price = price;
// }
public Item() {
}
}
Looks like there is some problem related with name of the atributes.
Check this link https://github.com/impetus-opensource/Kundera/issues/158

Hibernate Update Parent Table and its Child Table , but not working porp?

Here i have two JPA Classes: TimeSheet and TimeSheetDetails
In this case i have a trouble with updation of timesheet, while updation the timesheet (master table) updated smoothly, but timesheet details (child table) generate new rows instead of updation and the link table also updated with the new values.....
Here what is the re
1)TimeSheet.java
#Entity
#Table(name = AMAM_Constants.tb_name.TIMESHEET, schema = AMAM_Constants.db_name)
public class TimeSheet implements Serializable {
private long ts_Id;
private String ts_Candidate;
private Date ts_Sdate;
private Date ts_Edate;
private String active;
private String ts_Type;
private String ts_Status;
private List<TimeSheetDetails> timesheetDetails = new ArrayList<TimeSheetDetails>();
#ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
#JoinTable(name = AMAM_Constants.tb_name.TIMESHEET_LINK_DETAILS, joinColumns = {
#JoinColumn(name = "TS_ID")}, inverseJoinColumns = {
#JoinColumn(name = "TSD_ID")
})
public List<TimeSheetDetails> getTimesheetDetails() {
return timesheetDetails;
}
public void setTimesheetDetails(List<TimeSheetDetails> timesheetDetails) {
this.timesheetDetails = timesheetDetails;
}
#Column(name = "ACTIVE", length = 1)
public String getActive() {
return active;
}
public void setActive(String active) {
this.active = active;
}
#Column(name = "TS_CANDIDATE", length = 25)
public String getTs_Candidate() {
return ts_Candidate;
}
public void setTs_Candidate(String ts_Candidate) {
this.ts_Candidate = ts_Candidate;
}
#Column(name = "TS_EDATE")
public Date getTs_Edate() {
return ts_Edate;
}
public void setTs_Edate(Date ts_Edate) {
this.ts_Edate = ts_Edate;
}
#Id
#GeneratedValue
#Column(name = "TS_ID")
public long getTs_Id() {
return ts_Id;
}
public void setTs_Id(long ts_Id) {
this.ts_Id = ts_Id;
}
#Column(name = "TS_SDATE")
public Date getTs_Sdate() {
return ts_Sdate;
}
public void setTs_Sdate(Date ts_Sdate) {
this.ts_Sdate = ts_Sdate;
}
#Column(name = "TS_STATUS", length = 25)
public String getTs_Status() {
return ts_Status;
}
public void setTs_Status(String ts_Status) {
this.ts_Status = ts_Status;
}
#Column(name = "TS_TYPE", length = 10)
public String getTs_Type() {
return ts_Type;
}
public void setTs_Type(String ts_Type) {
this.ts_Type = ts_Type;
}
}
#Entity
#Table(name = AMAM_Constants.tb_name.TIMESHEET_DETAILS, schema = AMAM_Constants.db_name)
public class TimeSheetDetails implements Serializable {
private long tsd_Id;
private String tsd_Po;
private Date tsd_Date;
private String tsd_DayName;
private int tsd_Hours;
private String tsd_HourType;
private String tsd_DayType;
#Column(name = "TSD_DATE")
public Date getTsd_Date() {
return tsd_Date;
}
public void setTsd_Date(Date tsd_Date) {
this.tsd_Date = tsd_Date;
}
#Column(name = "TSD_DAYNAME", length = 25)
public String getTsd_DayName() {
return tsd_DayName;
}
public void setTsd_DayName(String tsd_DayName) {
this.tsd_DayName = tsd_DayName;
}
#Column(name = "TSD_DAYTYPE", length = 25)
public String getTsd_DayType() {
return tsd_DayType;
}
public void setTsd_DayType(String tsd_DayType) {
this.tsd_DayType = tsd_DayType;
}
#Column(name = "TSD_HOURTYPE", length = 25)
public String getTsd_HourType() {
return tsd_HourType;
}
public void setTsd_HourType(String tsd_HourType) {
this.tsd_HourType = tsd_HourType;
}
#Column(name = "TSD_HOURS")
public int getTsd_Hours() {
return tsd_Hours;
}
public void setTsd_Hours(int tsd_Hours) {
this.tsd_Hours = tsd_Hours;
}
#Id
#GeneratedValue
#Column(name = "TSD_ID")
public long getTsd_Id() {
return tsd_Id;
}
public void setTsd_Id(long tsd_Id) {
this.tsd_Id = tsd_Id;
}
#Column(name = "TSD_PO", length = 25)
public String getTsd_Po() {
return tsd_Po;
}
public void setTsd_Po(String tsd_Po) {
this.tsd_Po = tsd_Po;
}
}
public class TimeSheetDao extends HibDao {
public void insertTimeSheet(TimeSheet objTimeSheet) throws Exception {
try {
begin();
getSession().save(objTimeSheet);
commit();
} catch (Exception ex) {
rollback();
throw new Exception(ex.getMessage());
} finally {
flush();
close();
}
}
public void updateTimeSheet(TimeSheet objTimeSheet) throws Exception {
try {
begin();
TimeSheet obj =(TimeSheet)getSession().get(TimeSheet.class,objTimeSheet.getTs_Id());
obj.setActive("Y");
obj.setTimesheetDetails(objTimeSheet.getTimesheetDetails());
obj.setTs_Candidate(objTimeSheet.getTs_Candidate());
obj.setTs_Edate(objTimeSheet.getTs_Edate());
obj.setTs_Sdate(objTimeSheet.getTs_Sdate());
obj.setTs_Status(objTimeSheet.getTs_Status());
obj.setTs_Type(objTimeSheet.getTs_Type());
getSession().update(obj);
commit();
} catch (Exception ex) {
rollback();
throw new Exception(ex.getMessage());
} finally {
flush();
close();
}
}
}
The problem is in this line:
obj.setTimesheetDetails(objTimeSheet.getTimesheetDetails());
You should do the same to update the child to what you are doing to update the parent. I.e:
obj.getTimesheetDetails().setTsd_Date(objTimeSheet.getTimesheetDetails().getTsd_Date);
...

Categories

Resources