0

This is my data class.

@Entity
@Table(name = "loan_category")
data class Loan_category (

    @Id
    @Column(name = "loan_id")
    @GeneratedValue(strategy = GenerationType.AUTO)
    val id: Long? = null,

    @Column(name = "category_name",unique = true,nullable = false)
    val categoryName : String = "",

    @Column(name = "interest_rate")
    val interest_rate : Float = 0.0F,

    @Column(name = "overdue_interest")
    val overdue_interest : Float = 0.0F,

    @Column(name = "overdue_period")
    val overdue_period : String = "",

    @Column(name = "minSurety")
    val minSurety:Int = 0,

    @Column(name = "totaline")
    val totalFine: Float = 0.0F
)

I want to declare this data class like an ArrayList in another entity. How can it be done?

Pang
  • 9,564
  • 146
  • 81
  • 122

1 Answers1

0

If I understood correctly, you want to have a list of this data class, in another data class?

data class Loan(
    @SerializedName("loan_categories")
    val categories: List<LoanCategory>
)

And you would instantiate it as

Loan(emptyList())
Reinherd
  • 5,476
  • 7
  • 51
  • 88
  • First of all, let me tell you I'm just a beginner to kotlin and springboot. So the doubt I have is, now when I declare as this will I be able to access the loan category fields when I call loan entity? – Anjaly Abraham Sep 20 '18 at 10:43
  • Yeah you should be able to do so like this: loan.categories.forEach {//Do whatever} – Reinherd Sep 20 '18 at 18:52