Andrzej Sawoniewicz

07/26/2018, 11:14 AM
Hi guys! I am using Room library and for a POJO class I want to use immutable data class. It is working fine with var fields with default value. Can it be working with val fields?
Copy code
// Cross table entity class
	primaryKeys = ["boundId", "flightId"],
	indices = [
		(Index("boundId")), (Index("flightId"))
	foreignKeys = [
		(ForeignKey(entity = Bound::class, parentColumns = arrayOf("id"), childColumns = arrayOf("boundId"), onDelete = ForeignKey.CASCADE)),
		(ForeignKey(entity = Flight::class, parentColumns = arrayOf("id"), childColumns = arrayOf("flightId")))
data class FlightBooking(val boundId: Long, val flightId: Long)

// Pojo class
data class FlightBookingWithFlight(
	val flightBooking: FlightBooking,

	@Relation(parentColumn = "flightId", entityColumn = "id", entity = Flight::class)
	val flightWithAirlinesAndAirportsSet: Set<FlightWithAirlinesAndAirports>
I got the error: FlightBookingWithFlight.java6 error: Entities and Pojos must have a usable public constructor. You can have an empty constructor or a constructor whose parameters match the fields (by name and type). public final class FlightBookingWithFlight {