krush icon indicating copy to clipboard operation
krush copied to clipboard

@Column not processed as expected regarding updatable

Open ChristianSch opened this issue 5 years ago • 1 comments

Hi guys,

Using the aforementioned annotation (as you do in the examples) with @Column(updatable=false) doesn't do anything.

@Entity
data class Customer(
        @Id
        val uuid: UUID = UUID.randomUUID(),

        val email: String,

        @Column(updatable = false)
        val name: String,

        @Embedded
        var address: CustomerAddress = CustomerAddress(),

        var groupId: String?
)

generates the following mapping (mapping.kt):

fun UpdateBuilder<Any>.from(customer: Customer) {
  	this[CustomerTable.uuid] = customer.uuid
  	this[CustomerTable.email] = customer.email
  	this[CustomerTable.name] = customer.name
  	this[CustomerTable.groupId] = customer.groupId
  	this[CustomerTable.addressCity] = customer.address.city
  	this[CustomerTable.addressCountry] = customer.address.country
  	this[CustomerTable.addressLine1] = customer.address.line1
  	this[CustomerTable.addressLine2] = customer.address.line2
  	this[CustomerTable.addressPostalCode] = customer.address.postalCode
  	this[CustomerTable.addressState] = customer.address.state
}

I expect the uuid and the name to not be included in this generated update mapping.

So it would be nice to either have documentation on what you actually process (found it here indirectly though). I feel like it's weird behaviour btw that I can just update an id after creation. My question is: can I somehow prevent updating with krush? If not, would it be something you'd consider implementing?

ChristianSch avatar Jul 09 '20 09:07 ChristianSch

Hi, thanks for the submission. For now we support @Transient annotation which prevents property from either read or update. updatable=false seems like a good feature to implement - I'll keep the issue open to track the progress. Sure, id should not be in the UpdateBuilder - we'll check this as well.

pjagielski avatar Jul 09 '20 16:07 pjagielski