Techiio-author
Started by Peter DanielsSep 25, 2021

Open
how to add columns to database table that are not contained in Entity

1 VIEWES 0 LIKES 0 DISLIKES SHARE
0 LIKES 0 DISLIKES 1 VIEWES SHARE

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

Techiio-commentatorNeel Dey replied 5 months ago0 likes0 dislikes

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.

You must be Logged in to reply
Techiio-logo

Techiio is on the journey to build an ocean of technical knowledge, scouring the emerging stars in process and proffering them to the corporate world.

Follow us on:

Subscribe to get latest updates

You can unsubscribe anytime from getting updates from us
Developed and maintained by Wikiance
Developed and maintained by Wikiance