I am trying to retrieve the entries from the Business_Journal table by using the Merchant_Id. There are some matched entries but unable to retrieve.
I'm getting an Exception : "Unable to find com.suntronix.model.MerchantUser with id 1; nested exception is javax.persistence.EntityNotFoundException: Unable to find com.suntronix.model.MerchantUser with id 1"
I've tried different annotations which are all specified when I'm searching for a solution but I couldn't fix this problem.
My Service:
@Service
public class MerchantServiceImpl<T> implements MerchantService<T>, Constant {
@Autowired
MerchantUserRepository<T> merchantUserRepository;
@Autowired
MerchantRepository merchantRepository;
@Autowired
ConsumerRepository<T> consumerRepository;
@Autowired
BusinessJournalRepository<T> businessJournalRepository;
@Autowired
@Override
public Object viewAllTransactions(MerchantUserBean merchantUserBean) throws SuntronixException {
if (merchantUserBean.getSessionKey() == null || merchantUserBean.getSessionKey().isEmpty())
throw new SuntronixException(ErrorCode.NULL_SESSION_KEY);
else if (merchantUserRepository.isSessionKeyExists(merchantUserBean.getSessionKey()) != 1)
throw new SuntronixException(ErrorCode.SESSION_KEY_DOES_NOT_EXIST);
else {
MerchantUser merchantUser = merchantUserRepository.getMerchantBySession(merchantUserBean.getSessionKey());
int merchantId = merchantUser.getMerchantId().getMerchantId();
List<BusinessJournal> list = businessJournalRepository.getAllTransactionsByMerchantId(merchantId);
if (list.size() != 0) {
return list;
} else {
throw new SuntronixException(ErrorCode.NO_RECORDS_FOUND);
}
}
}
}
My Repository:
@Repository
public interface BusinessJournalRepository<T>
extends JpaRepository<BusinessJournal, Integer>{
@Query(BusinessJournalQuery.getAllTransactionsByMerchantId)
List<BusinessJournal> getAllTransactionsByMerchantId(@Param("merchant") int i);
}
My Query:
public class BusinessJournalQuery {
public static final String getAllTransactionsByMerchantId = "select b from #{#entityName} b where b.merchant.merchantId= :merchant";
}
My Entities: (Getters & Setters excluded) Business Journal
@Entity
@Table(name = "business_journal")
@EntityListeners(AuditingEntityListener.class)
public class BusinessJournal {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "Journal_Id")
private int journalId;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "merchant_id")
private Merchant merchant;
@ManyToOne
@JoinColumn(name = "Consumer_Id")
private Consumer consumer;
@Column(name = "Journal_Entry_Type")
private int journalEntryType;
@Column(name = "Amount")
private int amount;
@ManyToOne
@JoinColumn(name = "Transaction_Id")
private ConsumerTransaction consumerTransaction;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "created_date", nullable = false, updatable = false)
@CreatedDate
private Date createdDate;
}
Merchant Entity:
@Entity
@Table(name = "merchant")
@EntityListeners(AuditingEntityListener.class)
public class Merchant {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "merchant_id")
private int merchantId;
@Column(name = "merchant_name")
private String merchantName;
@Column(name = "merchant_address")
private String merchantAddress;
@Column(name = "merchant_city")
private String merchantCity;
@Column(name = "merchant_state")
private String merchantState;
@Column(name = "merchant_pincode")
private int merchantPincode;
@Column(name = "status")
private byte Status;
@OneToMany(mappedBy = "merchant")
private List<BusinessJournal> businessJournal;
@OneToMany(mappedBy = "merchantId")
private List<MerchantUser> merchantUser;
}
Merchant User Entity:
@Entity
@Table(name = "merchant_user")
@EntityListeners(AuditingEntityListener.class)
@JsonIgnoreProperties(value = { "createdDate", "updatedDate" }, allowGetters = true)
public class MerchantUser {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "merchant_user_id")
private int merchantUserId;
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name = "merchant_id")
private Merchant merchantId;
@Column(name = "merchant_username")
private String merchantUserName;
@Column(name = "merchant_User_Mobile")
private Long merchantUserMobile;
@Column(name = "otp")
private String otp;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "otp_time", updatable = true)
private Date otpTime;
@Column(name = "session_key")
private String sessionKey;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "session_date", updatable = true)
private Date sessionDate;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "created_date", nullable = false, updatable = false)
@CreatedDate
private Date createdDate;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "updated_date", updatable = true)
@LastModifiedDate
private Date updatedDate;
@Column(name = "app_version")
private String appVersion;
@Column(name = "status")
private Byte status;
}
Thanks in advance.
Comments
Post a Comment