If I want to have DB table with scheme id|column1|rest of columns...
such as:
@Entity
@Table(name = "SampleEntity")
class SampleEntity(
@Id @GeneratedValue val id: Long,
)
how can I add columns to table such that the table has these columns, but my entity does not?
I would like to be able to add these columns programmatically with a for loop. But any pointers would be appreciated.
1 Replies
If you want to alter the table programmatically just use spring-JDBC which will allow you to execute SQL queries thus making changes to the table programmatically.
It is completely ok if your entity doesn't have all the columns - columns that don't have matching attributes inside of the class just will be ignored by the entity in Spring JPA. Alternatively, you could just use spring-JDBC with a custom row-mapper.