Table not getting created using Hibernate Automatic Query Generation - java

Getting Below Error
Caused by: org.apache.derby.client.am.SqlException: Table/View 'SO_ITEM_DTLS' does not exist.
at org.apache.derby.client.am.Statement.completeSqlca(Unknown Source)
at org.apache.derby.client.net.NetStatementReply.parsePrepareError(Unknown Source)
at org.apache.derby.client.net.NetStatementReply.parsePRPSQLSTTreply(Unknown Source)
at org.apache.derby.client.net.NetStatementReply.readPrepareDescribeOutput(Unknown Source)
at org.apache.derby.client.net.StatementReply.readPrepareDescribeOutput(Unknown Source)
at org.apache.derby.client.net.NetStatement.readPrepareDescribeOutput_(Unknown Source)
at org.apache.derby.client.am.Statement.readPrepareDescribeOutput(Unknown Source)
at org.apache.derby.client.am.PreparedStatement.readPrepareDescribeInputOutput(Unknown Source)
at org.apache.derby.client.am.PreparedStatement.flowPrepareDescribeInputOutput(Unknown Source)
at org.apache.derby.client.am.PreparedStatement.prepare(Unknown Source)
at org.apache.derby.client.am.Connection.prepareStatementX(Unknown Source)
... 100 more
I am using derby database and hibernate for automatic schema generation.
But Table is not getting created into the database while the SQL is getting generated for all the Entities. Code is having #OneToMany Relationship among two Entity Classes and Parent table also contains EmbeddedID. Hibernate Configuration file and Entities classes are as below.
hibernate.cfg.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">org.apache.derby.jdbc.ClientDriver</property>
<property name="hibernate.connection.url">jdbc:derby://localhost:1527/mcodb;create=true;user=mco;password=mco</property>
<property name="hibernate.connection.username">mco</property>
<property name="hibernate.connection.password">mco</property>
<property name="hibernate.hbm2ddl.auto">create</property>
<property name="hibernate.dialect">org.hibernate.dialect.DerbyDialect</property>
<property name="show_sql">true</property>
<mapping class="mco.com.billing.app.model.AdminReportingPanel" />
<mapping class="mco.com.billing.app.model.SODetails" />
<mapping class="mco.com.billing.app.model.SOItemDetails" />
<mapping class="mco.com.billing.app.model.BillCategories" />
<mapping class="mco.com.billing.app.model.BillHeads" />
<mapping class="mco.com.billing.app.model.Dealers" />
<mapping class="mco.com.billing.app.model.FinancialYears" />
</session-factory>
</hibernate-configuration>
SODetails Class
package mco.com.billing.app.model;
import java.util.Date;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.OneToMany;
import javax.persistence.Table;
#Entity
#Table(name="SO_DTLS")
public class SODetails {
#EmbeddedId
SODetailsEmbeddable soDetailsEmbeddable;
#Column(name = "LPR_NO", nullable = false, length = 400)
String lprNo;
#Column(name = "DEALER_NAME", nullable = false, length = 200)
String dealerName;
#Column(name = "SO_DATE")
Date soDate;
#Column(name = "VAT", length = 200)
String vat;
#Column(name="NO_OF_QUOTATIONS", nullable = false, length=100)
String noOfQuotations;
#Column(name="LINKED_SO", nullable = false, length=100)
String linkedSO;
#Column(name="BILL_HEAD", nullable = false, length=100)
String billHead;
#Column(name="BILL_CATEGORY", nullable = false, length=100)
String billCategory;
#Column(name="NO_OF_CSTS", nullable = false, length=100)
String noOfCSTs;
#Column(name="NO_OF_CRVS", nullable = false, length=100)
String noOFCRVs;
#Column(name = "SO_GRAND_TOTAL_AMOUNT", nullable = false, length = 100)
String sOGrandTotalAmount;
#Column(name = "SO_GRAND_TOTAL_ROUND_OFF_AMOUNT", nullable = false, length = 100)
String sOGrandTotalRoundOfAmount;
#Column(name = "BILL_GRAND_TOTAL_AMOUNT", length = 100)
String billGrandTotalAmount;
#Column(name = "BILL_GRAND_TOTAL_ROUND_OFF_AMOUNT", length = 100)
String billGrandTotalRoundOffAmount;
#Column(name="IS_BILL_GENERATED", length = 100)
boolean isBillGenerated;
#Column(name="IS_SHORT_CLOSED_SO", length = 100)
boolean isShortClosedSO;
#Column(name="IS_SHORT_CLOSED_GENERATED", length = 100)
boolean isShortClosedGenerated;
#Column(name="IS_LD_ATTACHED", length = 100)
boolean isLDAttached;
#Column(name="LD_AMOUNT", length = 100)
String lDAmount;
#Column(name="ITEM_DUE_DATE", length = 100)
Date itemDueDate;
#Column(name="NO_OF_DELAY_WEEKS", length = 100)
String noOfWeeksDelay;
#Column(name="LD_PERCENTAGE", length = 100)
String ldPercentage;
#Column(name="FINAL_AMOUNT_AFTER_LD", length = 100)
String finalAmountAfterLD;
#Column(name="AMOUNT_ON_WHICH_LD_CALCULATED", length = 100)
String amountOnWhichLDCalculated;
public String getAmountOnWhichLDCalculated() {
return amountOnWhichLDCalculated;
}
public void setAmountOnWhichLDCalculated(String amountOnWhichLDCalculated) {
this.amountOnWhichLDCalculated = amountOnWhichLDCalculated;
}
public String getLdPercentage() {
return ldPercentage;
}
public void setLdPercentage(String ldPercentage) {
this.ldPercentage = ldPercentage;
}
public String getFinalAmountAfterLD() {
return finalAmountAfterLD;
}
public void setFinalAmountAfterLD(String finalAmountAfterLD) {
this.finalAmountAfterLD = finalAmountAfterLD;
}
public Date getItemDueDate() {
return itemDueDate;
}
public void setItemDueDate(Date itemDueDate) {
this.itemDueDate = itemDueDate;
}
public String getNoOfWeeksDelay() {
return noOfWeeksDelay;
}
public void setNoOfWeeksDelay(String noOfWeeksDelay) {
this.noOfWeeksDelay = noOfWeeksDelay;
}
#OneToMany(fetch=FetchType.LAZY, mappedBy="sODetails", cascade = CascadeType.ALL)
Set<SOItemDetails> setSOItemDetails;
public String getVat() {
return vat;
}
public void setVat(String vat) {
this.vat = vat;
}
public String getNoOfQuotations() {
return noOfQuotations;
}
public void setNoOfQuotations(String noOfQuotations) {
this.noOfQuotations = noOfQuotations;
}
public String getLinkedSO() {
return linkedSO;
}
public void setLinkedSO(String linkedSO) {
this.linkedSO = linkedSO;
}
public String getBillHead() {
return billHead;
}
public void setBillHead(String billHead) {
this.billHead = billHead;
}
public String getBillCategory() {
return billCategory;
}
public void setBillCategory(String billCategory) {
this.billCategory = billCategory;
}
public String getNoOfCSTs() {
return noOfCSTs;
}
public void setNoOfCSTs(String noOfCSTs) {
this.noOfCSTs = noOfCSTs;
}
public String getNoOFCRVs() {
return noOFCRVs;
}
public void setNoOFCRVs(String noOFCRVs) {
this.noOFCRVs = noOFCRVs;
}
public boolean isShortClosedSO() {
return isShortClosedSO;
}
public void setShortClosedSO(boolean isShortClosedSO) {
this.isShortClosedSO = isShortClosedSO;
}
public boolean isShortClosedGenerated() {
return isShortClosedGenerated;
}
public void setShortClosedGenerated(boolean isShortClosedGenerated) {
this.isShortClosedGenerated = isShortClosedGenerated;
}
public String getlDAmount() {
return lDAmount;
}
public void setlDAmount(String lDAmount) {
this.lDAmount = lDAmount;
}
public String getLprNo() {
return lprNo;
}
public void setLprNo(String lprNo) {
this.lprNo = lprNo;
}
public String getsOGrandTotalAmount() {
return sOGrandTotalAmount;
}
public void setsOGrandTotalAmount(String sOGrandTotalAmount) {
this.sOGrandTotalAmount = sOGrandTotalAmount;
}
public String getsOGrandTotalRoundOfAmount() {
return sOGrandTotalRoundOfAmount;
}
public void setsOGrandTotalRoundOfAmount(String sOGrandTotalRoundOfAmount) {
this.sOGrandTotalRoundOfAmount = sOGrandTotalRoundOfAmount;
}
public String getBillGrandTotalAmount() {
return billGrandTotalAmount;
}
public void setBillGrandTotalAmount(String billGrandTotalAmount) {
this.billGrandTotalAmount = billGrandTotalAmount;
}
public String getBillGrandTotalRoundOffAmount() {
return billGrandTotalRoundOffAmount;
}
public void setBillGrandTotalRoundOffAmount(String billGrandTotalRoundOffAmount) {
this.billGrandTotalRoundOffAmount = billGrandTotalRoundOffAmount;
}
public String getDealerName() {
return dealerName;
}
public void setDealerName(String dealerName) {
this.dealerName = dealerName;
}
public SODetailsEmbeddable getSoDetailsEmbeddable() {
return soDetailsEmbeddable;
}
public void setSoDetailsEmbeddable(SODetailsEmbeddable soDetailsEmbeddable) {
this.soDetailsEmbeddable = soDetailsEmbeddable;
}
public Date getSoDate() {
return soDate;
}
public void setSoDate(Date soDate) {
this.soDate = soDate;
}
public boolean isBillGenerated() {
return isBillGenerated;
}
public void setBillGenerated(boolean isBillGenerated) {
this.isBillGenerated = isBillGenerated;
}
public boolean isLDAttached() {
return isLDAttached;
}
public void setLDAttached(boolean isLDAttached) {
this.isLDAttached = isLDAttached;
}
public Set<SOItemDetails> getSetSOItemDetails() {
return setSOItemDetails;
}
public void setSetSOItemDetails(Set<SOItemDetails> setSOItemDetails) {
this.setSOItemDetails = setSOItemDetails;
}
#Override
public String toString() {
return "SODetails [soDetailsEmbeddable=" + soDetailsEmbeddable + ", lprNo=" + lprNo + ", dealerName="
+ dealerName + ", soDate=" + soDate + ", vat=" + vat + ", noOfQuotations=" + noOfQuotations
+ ", linkedSO=" + linkedSO + ", billHead=" + billHead + ", billCategory=" + billCategory + ", noOfCSTs="
+ noOfCSTs + ", noOFCRVs=" + noOFCRVs + ", sOGrandTotalAmount=" + sOGrandTotalAmount
+ ", sOGrandTotalRoundOfAmount=" + sOGrandTotalRoundOfAmount + ", billGrandTotalAmount="
+ billGrandTotalAmount + ", billGrandTotalRoundOffAmount=" + billGrandTotalRoundOffAmount
+ ", isBillGenerated=" + isBillGenerated + ", isShortClosedSO=" + isShortClosedSO
+ ", isShortClosedGenerated=" + isShortClosedGenerated + ", isLDAttached=" + isLDAttached
+ ", lDAmount=" + lDAmount + ", itemDueDate=" + itemDueDate + ", noOfWeeksDelay=" + noOfWeeksDelay
+ ", ldPercentage=" + ldPercentage + ", finalAmountAfterLD=" + finalAmountAfterLD
+ ", amountOnWhichLDCalculated=" + amountOnWhichLDCalculated + ", setSOItemDetails=" + setSOItemDetails
+ "]";
}
}
SOItemDetails Class
package mco.com.billing.app.model;
import java.util.Date;
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.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.MapsId;
import javax.persistence.Table;
#Entity
#Table(name="SO_ITEM_DTLS")
public class SOItemDetails {
#Id
#GeneratedValue(strategy=GenerationType.IDENTITY)
#Column(name = "SO_ITEM_DTLS_ID", unique = true, nullable = false, length = 100)
String soItemDtlsRecordNo;
#Column(name = "S_NO", nullable = false, length = 100)
String itemSNo;
#Column(name = "ITEM_UNIT_TYPE", nullable = false, length = 100)
String itemUnitType;
#Column(name = "ITEM_NOMENCLATURE", nullable = false, length = 400)
String itemNomenclature;
#Column(name = "FOR_QUANTITY", nullable = false, length = 100)
String forQuantity;
#Column(name = "READ_QUANTITY", length = 100)
String readQuantity;
#Column(name = "FOR_AMOUNT", nullable = false, length = 100)
String forAmount;
#Column(name = "READ_AMOUNT", length = 100)
String readAmount;
#Column(name = "SUPPLY_DATE", length = 100)
Date supplyDate;
#Column(name = "PRICE", nullable = false, length = 100)
String price;
#Column(name = "IS_LD_ITEM")
boolean isLDItem;
#MapsId("soDetailsEmbeddable")
#JoinColumns({#JoinColumn(name="SO_NO_FK", referencedColumnName="SO_NO"),
#JoinColumn(name="FIN_YEAR_FK", referencedColumnName="FINANCIAL_YEAR")
})
#ManyToOne(fetch=FetchType.LAZY)
private SODetails sODetails;
public String getSoItemDtlsRecordNo() {
return soItemDtlsRecordNo;
}
public boolean isLDItem() {
return isLDItem;
}
public void setLDItem(boolean isLDItem) {
this.isLDItem = isLDItem;
}
public void setSoItemDtlsRecordNo(String soItemDtlsRecordNo) {
this.soItemDtlsRecordNo = soItemDtlsRecordNo;
}
public String getItemSNo() {
return itemSNo;
}
public void setItemSNo(String itemSNo) {
this.itemSNo = itemSNo;
}
public String getItemUnitType() {
return itemUnitType;
}
public void setItemUnitType(String itemUnitType) {
this.itemUnitType = itemUnitType;
}
public String getItemNomenclature() {
return itemNomenclature;
}
public void setItemNomenclature(String itemNomenclature) {
this.itemNomenclature = itemNomenclature;
}
public String getForQuantity() {
return forQuantity;
}
public void setForQuantity(String forQuantity) {
this.forQuantity = forQuantity;
}
public String getReadQuantity() {
return readQuantity;
}
public void setReadQuantity(String readQuantity) {
this.readQuantity = readQuantity;
}
public String getForAmount() {
return forAmount;
}
public void setForAmount(String forAmount) {
this.forAmount = forAmount;
}
public String getReadAmount() {
return readAmount;
}
public void setReadAmount(String readAmount) {
this.readAmount = readAmount;
}
public Date getSupplyDate() {
return supplyDate;
}
public void setSupplyDate(Date supplyDate) {
this.supplyDate = supplyDate;
}
public String getPrice() {
return price;
}
public void setPrice(String price) {
this.price = price;
}
public SODetails getsODetails() {
return sODetails;
}
public void setsODetails(SODetails sODetails) {
this.sODetails = sODetails;
}
#Override
public String toString() {
return "SOItemDetails [soItemDtlsRecordNo=" + soItemDtlsRecordNo + ", itemSNo=" + itemSNo + ", itemUnitType="
+ itemUnitType + ", itemNomenclature=" + itemNomenclature + ", forQuantity=" + forQuantity
+ ", readQuantity=" + readQuantity + ", forAmount=" + forAmount + ", readAmount=" + readAmount
+ ", supplyDate=" + supplyDate + ", price=" + price + ", isLDItem=" + isLDItem + ", sODetails="
+ sODetails + "]";
}
}
SODetailsEmbeddable Class
package mco.com.billing.app.model;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Embeddable;
#Embeddable
public class SODetailsEmbeddable implements Serializable{
private static final long serialVersionUID = 1L;
#Column(name = "SO_NO", nullable = false, length = 100)
String soNo;
#Column(name="FINANCIAL_YEAR", length=100)
String financialYear;
public String getSoNo() {
return soNo;
}
public void setSoNo(String soNo) {
this.soNo = soNo;
}
public String getFinancialYear() {
return financialYear;
}
public void setFinancialYear(String financialYear) {
this.financialYear = financialYear;
}
#Override
public String toString() {
return "SODetailsEmbeddable [soNo=" + soNo + ", financialYear=" + financialYear + "]";
}
}
Transactional Logic function
public void saveSOWithBillingData(SODetails soDetails) {
Session session=null;
Transaction tx=null;
try{
SessionFactory sessionFactory=HibernateUtil.getSessionFactory();
session=sessionFactory.openSession();
tx=session.beginTransaction();
session.save(soDetails);
tx.commit();
}catch(HibernateException ex){
try{
if(null!=tx)
tx.rollback();
}catch(RuntimeException e){
e.printStackTrace();
}
throw ex;
}catch(RuntimeException ex){
throw ex;
}finally{
if(null!=session)
session.close();
}
}

My bad, it was just a silly mistake. SOItemDetails table was not getting created because #GeneratedValue is not applicable for String type, it should be of int type. Now need to do below change in SOItemDetails Entity Class.
#Id
#GeneratedValue(strategy=GenerationType.IDENTITY)
#Column(name = "SO_ITEM_DTLS_ID", unique = true, nullable = false, length = 100)
int soItemDtlsRecordNo;

Related

Why is my application failing to create a bean?

I have the following files:
UnitController.java
package com.fidolease.fidolease.controllers;
import com.fidolease.fidolease.exceptions.ResourceNotFoundException;
import com.fidolease.fidolease.models.Unit;
import com.fidolease.fidolease.repository.UnitRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
#RestController
#RequestMapping("/api/v1")
public class UnitController {
#Autowired
private UnitRepository unitRepository;
#GetMapping("/units")
public List<Unit> getAllUnits(){
return unitRepository.findAll();
}
#GetMapping("/units/{id}")
public ResponseEntity<Unit> getUnitById(#PathVariable(value = "id") Long unitId)
throws ResourceNotFoundException {
Unit unit = unitRepository.findById(unitId)
.orElseThrow(() -> new ResourceNotFoundException("Unit not found for this id :: " + unitId));
return ResponseEntity.ok().body(unit);
}
}
ErrorDetails.java
package com.fidolease.fidolease.exceptions;
import java.util.Date;
public class ErrorDetails {
private Date timestamp;
private String message;
private String details;
public ErrorDetails(Date timestamp, String message, String details) {
super();
this.timestamp = timestamp;
this.message = message;
this.details = details;
}
public Date getTimestamp() {
return timestamp;
}
public String getMessage() {
return message;
}
public String getDetails() {
return details;
}
}
GlobalExceptionHandler.java
package com.fidolease.fidolease.exceptions;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.context.request.WebRequest;
import java.util.Date;
#ControllerAdvice
public class GlobalExceptionHandler {
#ExceptionHandler(ResourceNotFoundException.class)
public ResponseEntity<?> resourceNotFoundException(ResourceNotFoundException ex, WebRequest request) {
ErrorDetails errorDetails = new ErrorDetails(new Date(), ex.getMessage(), request.getDescription(false));
return new ResponseEntity<>(errorDetails, HttpStatus.NOT_FOUND);
}
#ExceptionHandler(Exception.class)
public ResponseEntity<?> globalExceptionHandler(Exception ex, WebRequest request) {
ErrorDetails errorDetails = new ErrorDetails(new Date(), ex.getMessage(), request.getDescription(false));
return new ResponseEntity<>(errorDetails, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
ResourceNotFoundException.java
package com.fidolease.fidolease.exceptions;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
#ResponseStatus(value = HttpStatus.NOT_FOUND)
public class ResourceNotFoundException extends Exception{
private static final long serialVersionUID = 1L;
public ResourceNotFoundException(String message){
super(message);
}
}
Unit.java
package com.fidolease.fidolease.models;
import javax.persistence.*;
#Entity
#Table(name = "units")
public class Unit {
private long id;
private String unit_heading;
private int unit_type_id;
private int number_of_bedroom;
private double number_of_bathroom;
private int number_of_balcony;
private int leasing_info_id;
private String date_of_posting;
private String date_available_from;
private int posted_by;
private boolean is_active;
private String unit_description;
private int carpet_area;
private String unit_number;
private int unit_floor_number;
private int parent_unit_id;
public Unit(){ }
public Unit(String unit_heading, int unit_type_id, int number_of_bedroom, double number_of_bathroom,
int number_of_balcony, int leasing_info_id, String date_of_posting, String date_available_from,
int posted_by, boolean is_active, String unit_description, int carpet_area, String unit_number,
int unit_floor_number, int parent_unit_id) {
this.unit_heading = unit_heading;
this.unit_type_id = unit_type_id;
this.number_of_bedroom = number_of_bedroom;
this.number_of_bathroom = number_of_bathroom;
this.number_of_balcony = number_of_balcony;
this.leasing_info_id = leasing_info_id;
this.date_of_posting = date_of_posting;
this.date_available_from = date_available_from;
this.posted_by = posted_by;
this.is_active = is_active;
this.unit_description = unit_description;
this.carpet_area = carpet_area;
this.unit_number = unit_number;
this.unit_floor_number = unit_floor_number;
this.parent_unit_id = parent_unit_id;
}
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
public long getId(){
return this.id;
}
public void setId(long id){
this.id = id;
}
#Column(name = "unit_heading", nullable = false)
public String getUnit_heading(){
return this.unit_heading;
}
public void setUnit_heading(String unit_heading){
this.unit_heading = unit_heading;
}
#Column(name = "unit_type_id", nullable = false)
public int getUnit_type_id(){
return this.unit_type_id;
}
public void setUnit_type_id(int unit_type_id){
this.unit_type_id = unit_type_id;
}
#Column(name = "number_of_bedroom", nullable = false)
public int getNumber_of_bedroom(){
return this.number_of_bedroom;
}
public void setNumber_of_bedroom(int number_of_bedroom){
this.number_of_bedroom = number_of_bedroom;
}
#Column(name = "number_of_bathroom", nullable = false)
public double getNumber_of_bathroom(){
return this.number_of_bathroom;
}
public void setNumber_of_bathroom(double number_of_bathroom){
this.number_of_bathroom = number_of_bathroom;
}
#Column(name = "number_of_balcony", nullable = false)
public int getNumber_of_balcony(){
return this.number_of_balcony;
}
public void setNumber_of_balcony(int number_of_balcony){
this.number_of_balcony = number_of_balcony;
}
#Column(name = "leasing_info_id", nullable = false)
public int getLeasing_info_id(){
return this.leasing_info_id;
}
public void setLeasing_info_id(int leasing_info_id){
this.leasing_info_id = leasing_info_id;
}
#Column(name = "date_of_posting", nullable = false)
public String getDate_of_posting(){
return this.date_of_posting;
}
public void setDate_of_posting(String date_of_posting){
this.date_of_posting = date_of_posting;
}
#Column(name = "date_available_from", nullable = false)
public String getDate_available_from(){
return this.date_available_from;
}
public void setDate_available_from(String date_available_from){
this.date_available_from = date_available_from;
}
#Column(name = "posted_by", nullable = false)
public int getPosted_by(){
return this.posted_by;
}
public void setPosted_by(int posted_by){
this.posted_by = posted_by;
}
#Column(name = "is_active", nullable = false)
public boolean getIs_active(){
return this.is_active;
}
public void setIs_active(boolean is_active){
this.is_active = is_active;
}
#Column(name = "unit_description", nullable = false)
public String getUnit_description(){
return this.unit_description;
}
public void setUnit_description(String unit_description){
this.unit_description = unit_description;
}
#Column(name = "carpet_area", nullable = false)
public int getCarpet_area(){
return this.carpet_area;
}
public void setCarpet_area(int carpet_area){
this.carpet_area = carpet_area;
}
#Column(name = "unit_number", nullable = false)
public String getUnit_number(){
return this.unit_number;
}
public void setUnit_number(){
this.unit_number = unit_number;
}
#Column(name = "unit_floor_number", nullable = false)
public int getUnit_floor_number(){
return this.unit_floor_number;
}
public void setUnit_floor_number(int unit_floor_number){
this.unit_floor_number = unit_floor_number;
}
#Column(name = "parent_unit_id", nullable = false)
public int getParent_unit_id(){
return this.parent_unit_id;
}
public void setParent_unit_id(int parent_unit_id){
this.parent_unit_id = parent_unit_id;
}
#Override
public String toString() {
return "Unit{" +
"id=" + id +
", unit_heading='" + unit_heading + '\'' +
", unit_type_id=" + unit_type_id +
", number_of_bedroom=" + number_of_bedroom +
", number_of_bathroom=" + number_of_bathroom +
", number_of_balcony=" + number_of_balcony +
", leasing_info_id=" + leasing_info_id +
", date_of_posting='" + date_of_posting + '\'' +
", date_available_from='" + date_available_from + '\'' +
", posted_by=" + posted_by +
", is_active=" + is_active +
", unit_description='" + unit_description + '\'' +
", carpet_area=" + carpet_area +
", unit_number='" + unit_number + '\'' +
", unit_floor_number=" + unit_floor_number +
", parent_unit_id=" + parent_unit_id +
'}';
}
}
UnitRepository.java
package com.fidolease.fidolease.repository;
import com.fidolease.fidolease.models.Unit;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
#Repository
public interface UnitRepository extends JpaRepository<Unit, Long> {
}
FidoLeaseApplication.java
package com.fidolease.fidolease;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class FidoleaseApplication {
public static void main(String[] args) {
SpringApplication.run(FidoleaseApplication.class, args);
}
}
When I run the application, I get the following error:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'unitRepository' defined in com.fidolease.fidolease.repository.UnitRepository defined in #EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration: Cannot resolve reference to bean 'jpaMappingContext' while setting bean property 'mappingContext'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jpaMappingContext': Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.MappingException: Could not get constructor for org.hibernate.persister.entity.SingleTableEntityPersister
When I searched around, it seemed as if the error might occur if I don't have JPA in my pom file but after searching it, I have the following:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
Does anyone have any suggestions as to what I am doing wrong here or maybe a reference to some documentation that may explain my issue? Thank you all for your time and if there is anything I can do to clarify, please let me know.
EDIT: The following is my properties file:
spring.datasource.initialization-mode=always
spring.datasource.platform=postgres
spring.datasource.url=jdbc:postgresql://digitaloceanservername:theport/mydbname
spring.datasource.username=myusername
spring.datasource.password=mypassword
Edit 2: Adding the full strack trac -> https://pastebin.com/RskBMJjL
There is a bug in your setter method for unit_number, it is not taking a parameter. It should be:
public void setUnit_number(String unit_number){
this.unit_number = unit_number;
}

Hibernate OneToMany SELECT gives repeated column in mapping for entity

I need to make one to many relation between Society and BlockFloors Table. Error:
Invocation of init method failed; nested exception is org.hibernate.MappingException: Repeated column in mapping for entity: com.example.domain.SocietyBlockFloor column: society_id (should be mapped with insert="false" update="false")
SocietyDetails.java
package com.example.domain;
import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;
#Entity
#Table(name="society_details")
public class SocietyDetails {
public static final long serialVersionUID = 1L;
#Id
#Column(name = "society_id")
private String societyId;
#Column(name = "society_name")
private String societyName;
#Column (name = "society_address")
private String societyAddress;
#Column (name = "society_country_details_code")
private String societyCountryDetailsCode;
#OneToMany(mappedBy = "societyDetails", cascade = CascadeType.ALL)
private List<SocietyBlockFloor> societyBlockFloor = new ArrayList<SocietyBlockFloor>();
#Override
public String toString() {
return "Society{" +
"societyId='" + societyId + '\'' +
", societyName='" + societyName + '\'' +
", societyAddress='" + societyAddress + '\'' +
", societyCountryDetailsCode='" + societyCountryDetailsCode + '\'' +
", societyBlockFloor='" + societyBlockFloor + '\'' +
'}';
}
public static long getSerialVersionUID() {
return serialVersionUID;
}
public String getSocietyId() {
return societyId;
}
public void setSocietyId(String societyId) {
this.societyId = societyId;
}
public String getSocietyName() {
return societyName;
}
public void setSocietyName(String societyName) {
this.societyName = societyName;
}
public String getSocietyAddress() {
return societyAddress;
}
public void setSocietyAddress(String societyAddress) {
this.societyAddress = societyAddress;
}
public String getSocietyCountryDetailsCode() {
return societyCountryDetailsCode;
}
public void setSocietyCountryDetailsCode(String societyCountryDetailsCode) {
this.societyCountryDetailsCode = societyCountryDetailsCode;
}
public List<SocietyBlockFloor> getSocietyBlockFloor() {
return societyBlockFloor;
}
public void setSocietyBlockFloor(List<SocietyBlockFloor> societyBlockFloor) {
this.societyBlockFloor = societyBlockFloor;
}
}
SocietyBlockFloor.java
package com.example.domain;
import javax.persistence.*;
import java.io.Serializable;
#Entity
#Table(name="society_block_floor")
public class SocietyBlockFloor implements Serializable {
public static final long serialVersionUID = 1L;
#Id
#Column(name="society_id")
private String societyBlockFloorId;
#Column(name="society_block")
private String societyBlock;
#Column(name="society_floor")
private String societyFloor;
#ManyToOne
#JoinColumn(name = "society_id", nullable = false)
private SocietyDetails societyDetails;
#Override
public String toString() {
return "HASocietyBlockFloor{" +
"societyBlockFloorId='" + societyBlockFloorId + '\'' +
", societyBlock='" + societyBlock + '\'' +
", societyFloor='" + societyFloor + '\'' +
", societyDetails='" + societyDetails + '\'' +
'}';
}
public String getSocietyBlockFloorId() {
return societyBlockFloorId;
}
public String getSocietyBlock() {
return societyBlock;
}
public void setSocietyBlock(String societyBlock) {
this.societyBlock = societyBlock;
}
public String getSocietyFloor() {
return societyFloor;
}
public void setSocietyFloor(String societyFloor) {
this.societyFloor = societyFloor;
}
public SocietyDetails getSocietyDetails() {
return societyDetails;
}
public void setSocietyDetails(SocietyDetails societyDetails) {
this.societyDetails = societyDetails;
}
}
DAO Class
package com.example.dao.impl;
#Repository
public class SocietyDetailsDAOImpl extends BaseDAOImpl implements SocietyDetailsDAO {
#Override
public List<SocietyDetails> getSocietyDetailsByName(String societyName) throws Exception {
try {
String queryString = "from SocietyDetails society JOIN society.societyBlockFloor where society.societyName=:societyName";
Query query = getSessionFactory().getCurrentSession().createQuery(queryString);
query.setParameter("societyName", societyName);
List<SocietyDetails> societyDetails = query.list();
return societyDetails;
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
}
I've already tried to change the name of SocietyBlockFloor.societyBlockFloorId, but then in the ON clause it still uses (society.societyId = societyBlockFloor.societyId) where societyBlockFloor.societyId doesn't exist.
you have a repeated column in the mapping. You mapped the same database column twice. you have:
#Id
#Column(name="society_id")
private String societyBlockFloorId;
And
#ManyToOne
#JoinColumn(name = "society_id", nullable = false)
private SocietyDetails societyDetails;
This seems useless
#Id
#Column(name="society_id")
private String societyBlockFloorId;
If you want societyid just ask to societyDetails.getId();
And this on the manyToOne side
referencedColumnName = "society_id"

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.

Not able to save child table data using hibernate

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).

Categories

Resources