On my backend, I have a DTO data class that includes information about a PHD Dissertation. It is defined as follows:
@Serializable
data class PhdDissertationDTO(
val id: Int? = null,
val title: String,
@SerialName("greek_abstract")
val abstractGR: String,
@SerialName("english_abstract")
val abstractEN: String,
@SerialName("publication_year")
val date: String,
val url: String,
val language: String,
val views: String,
val reads: String,
val tags: List<String>,
val authors: List<String>,
@SerialName("institution")
val institutions: List<String>,
@SerialName("scientific_fields")
val scientificFields: List<String>,
@SerialName("exam_board")
val examBoardMembers: List<String>,
val updatedAt: String? = null,
val createdAt: String? = null
)
I have also defined the respective Exposed tables, entities and Joint tables (i.e. Phds x Tags, Phds x Members, etc). So now I am trying to implement batch insert capabilities as follows:
override suspend fun addDissertationsBatch(dissertations: List<PhdDissertationDTO>): List<String> =
suspendTransaction {
val failedInsertionPhdTitles = arrayListOf<String>()
dissertations.forEach { phdDissertationDTO ->
try {
val phdDissertation =
PhdDissertationEntity.new {
title = phdDissertationDTO.title
abstractGR = phdDissertationDTO.abstractGR
abstractEN = phdDissertationDTO.abstractEN
date = phdDissertationDTO.date
url = phdDissertationDTO.url
language = phdDissertationDTO.language
views = phdDissertationDTO.views.toLongOrNull() ?: 0
reads = phdDissertationDTO.reads.toLongOrNull() ?: 0
updatedAt = Clock.System.now()
createdAt = Clock.System.now()
}
// Add tags
phdDissertation.tags = SizedCollection(phdDissertationDTO.tags.map { tag ->
PhdTagEntity.find { PhdTagsTable.title eq tag }.firstOrNull() ?: PhdTagEntity.new {
title = tag
updatedAt = Clock.System.now()
createdAt = Clock.System.now()
}
})
// Add authors
phdDissertation.authors = SizedCollection(phdDissertationDTO.authors.map { author ->
PhdAuthorEntity.find { PhdAuthorsTable.fullName eq author }.firstOrNull()
?: PhdAuthorEntity.new {
fullName = author
updatedAt = Clock.System.now()
createdAt = Clock.System.now()
}
})
// Add scientific fields
phdDissertation.scientificFields =
SizedCollection(phdDissertationDTO.scientificFields.map { field ->
PhdScientificFieldEntity.find { PhdScientificFieldsTable.field eq field }.firstOrNull()
?: PhdScientificFieldEntity.new {
title = field
updatedAt = Clock.System.now()
createdAt = Clock.System.now()
}
})
// Add exam board members
phdDissertation.examBoardMembers =
SizedCollection(phdDissertationDTO.examBoardMembers.map { member ->
PhdExamBoardMemberEntity.find { PhdExamBoardTable.examinerFullName eq member }.firstOrNull()
?: PhdExamBoardMemberEntity.new {
fullName = member
updatedAt = Clock.System.now()
createdAt = Clock.System.now()
}
})
// add institutions
phdDissertation.institutions =
SizedCollection(phdDissertationDTO.institutions.map { institution ->
PhdInstitutionEntity.find { PhdInstitutionsTable.title eq institution }.firstOrNull()
?: PhdInstitutionEntity.new {
title = institution
updatedAt = Clock.System.now()
createdAt = Clock.System.now()
}
})
} catch (e: Exception) {
e.printStackTrace()
failedInsertionPhdTitles.add(phdDissertationDTO.title)
}
}
return@suspendTransaction failedInsertionPhdTitles
}
The issue that occurs though is:
org.jetbrains.exposed.sql.statements.BatchDataInconsistentException: Can’t add a new batch because columns: phd_institutions.title, phd_institutions.updated_at, phd_institutions.created_at don’t have default values. DB defaults are not supported in batch inserts
I am having a hard time understanding how this can be since I am providing the “title”, “createdAt” and “updatedAt” column values when creating a new entry (if needed). Here is the relevant table definition just in case, as well as the payload for my batch insert test that causes the fail:
Table:
object PhdInstitutionsTable: IntIdTable("phd_institutions") {
val title = text("title")
val updatedAt = timestamp("updated_at")
val createdAt = timestamp("created_at")
}
Payload:
[
{
"title": "Test entry 1",
"greek_abstract": "",
"english_abstract": "The wide spread of mobile communication since the late 1980’s raises questions about the effects of electromagnetic fields (EMFs) on the human body. The non-thermal effects of electromagnetic radiation (EMR) have been the focus of most studies. Low energy EMFs seem to cause structural and functional changes in the cell membrane of different cell types, leading to abnormal cell response. Such changes within the central nervous system (CNS) and auditory system, which directly receive EMR during mobile phone use, are of particular interest. Various studies suggest that EMR directly affects neurons by reducing the neuronal reactivity, increasing the neural membrane conductivity and prolonging their refractory period. Furthermore, although it has been suggested that EMR is related with increased incidence of specific tumors and can interact with known carcinogenic agents, no conclusive evidence exists supporting its role in carcinogenesis.nThe objective of the present study was to investigate the possible electrophysiological time-related changes in auditory pathway during mobile phone electromagnetic field exposure. Thirty healthy rabbits were enrolled in an experimental study of exposure to GSM-900 radiation for 60 min and auditory brainstem responses (ABRs) were recorded at regular time-intervals during exposure. The study subjects were radiated via an adjustable power and frequency radio transmitter for GSM-900 mobile phone emission simulation, designed and manufactured according to the needs of the experiment. The mean absolute latency of waves III–V showed a statistically significant delay (p <0.05) after 60, 45 and 15 min of exposure to electromagnetic radiation of 900 MHz, respectively. Interwave latency I–III was found to be prolonged after 60 min of radiation exposure in correspondence to wave III absolute latency delay. Interwave latencies I–V and III–V were found with a statistically significant delay (p< 0.05) after 30 min of radiation. No statistically significant delay was found for the same ABR parameters in recordings from the ear contralateral to the radiation source at 60 min radiation exposure compared with baseline ABR. The ABR measurements returned to baseline recordings 24 h after the exposure to electromagnetic radiation of 900 MHz. The prolongation of interval latencies I–V and III–V indicates that exposure to electromagnetic fields emitted by mobile phone can affect the normal electrophysiological activity of the auditory system, and these findings fit the pattern of general responses to a stressor.",
"authors": [
"Καπράνα, Αντιγόνη (Πατρώνυμο: Ευάγγελος)"
],
"publication_year": "2011",
"institution": [
"Πανεπιστήμιο Κρήτης",
"Σχολή Επιστημών Υγείας",
"Τμήμα Ιατρικής",
"Κλινική Ωτορινολαρυγγολογική"
],
"exam_board": [
"Βελεγράκης Γεώργιος",
"Χελιδόνης Εμμανουήλ",
"Σταθόπουλος Ευστάθιος",
"Τσιλιμπάρης Μιλτιάδης",
"Χριστοδούλου Παναγιώτης",
"Βαρδιάμπασης Ιωάννης",
"Σπανάκη Κλεάνθη"
],
"scientific_fields": [
"Ιατρική και Επιστήμες ΥγείαςΒασική Ιατρική"
],
"tags": [
"Ηλεκτρομαγνητική ακτινοβολία",
"Ακουστική οδός",
"Κεντρικό νευρικό σύστημα",
"Κινητό τηλέφωνο",
"Ακουστικά προκλητά δυναμικά εγκεφαλικού στελέχους"
],
"language": "Ελληνικά",
"views": "",
"reads": "",
"url": "https://www.didaktorika.gr/eadd/readonline?handle=10442/25980"
},
{
"title": "test entry 2",
"greek_abstract": "",
"english_abstract": "The wide spread of mobile communication since the late 1980’s raises questions about the effects of electromagnetic fields (EMFs) on the human body. The non-thermal effects of electromagnetic radiation (EMR) have been the focus of most studies. Low energy EMFs seem to cause structural and functional changes in the cell membrane of different cell types, leading to abnormal cell response. Such changes within the central nervous system (CNS) and auditory system, which directly receive EMR during mobile phone use, are of particular interest. Various studies suggest that EMR directly affects neurons by reducing the neuronal reactivity, increasing the neural membrane conductivity and prolonging their refractory period. Furthermore, although it has been suggested that EMR is related with increased incidence of specific tumors and can interact with known carcinogenic agents, no conclusive evidence exists supporting its role in carcinogenesis.nThe objective of the present study was to investigate the possible electrophysiological time-related changes in auditory pathway during mobile phone electromagnetic field exposure. Thirty healthy rabbits were enrolled in an experimental study of exposure to GSM-900 radiation for 60 min and auditory brainstem responses (ABRs) were recorded at regular time-intervals during exposure. The study subjects were radiated via an adjustable power and frequency radio transmitter for GSM-900 mobile phone emission simulation, designed and manufactured according to the needs of the experiment. The mean absolute latency of waves III–V showed a statistically significant delay (p <0.05) after 60, 45 and 15 min of exposure to electromagnetic radiation of 900 MHz, respectively. Interwave latency I–III was found to be prolonged after 60 min of radiation exposure in correspondence to wave III absolute latency delay. Interwave latencies I–V and III–V were found with a statistically significant delay (p< 0.05) after 30 min of radiation. No statistically significant delay was found for the same ABR parameters in recordings from the ear contralateral to the radiation source at 60 min radiation exposure compared with baseline ABR. The ABR measurements returned to baseline recordings 24 h after the exposure to electromagnetic radiation of 900 MHz. The prolongation of interval latencies I–V and III–V indicates that exposure to electromagnetic fields emitted by mobile phone can affect the normal electrophysiological activity of the auditory system, and these findings fit the pattern of general responses to a stressor.",
"authors": [
"Καπράνα, Αντιγόνη (Πατρώνυμο: Ευάγγελος)"
],
"publication_year": "2011",
"institution": [
"Πανεπιστήμιο Κρήτης",
"Σχολή Επιστημών Υγείας",
"Τμήμα Ιατρικής",
"Κλινική Ωτορινολαρυγγολογική"
],
"exam_board": [
"Βελεγράκης Γεώργιος",
"Χελιδόνης Εμμανουήλ",
"Σταθόπουλος Ευστάθιος",
"Τσιλιμπάρης Μιλτιάδης",
"Χριστοδούλου Παναγιώτης",
"Βαρδιάμπασης Ιωάννης",
"Σπανάκη Κλεάνθη"
],
"scientific_fields": [
"Ιατρική και Επιστήμες ΥγείαςΒασική Ιατρική"
],
"tags": [
"Ηλεκτρομαγνητική ακτινοβολία",
"Ακουστική οδός",
"Κεντρικό νευρικό σύστημα",
"Κινητό τηλέφωνο",
"Ακουστικά προκλητά δυναμικά εγκεφαλικού στελέχους"
],
"language": "Ελληνικά",
"views": "",
"reads": "",
"url": "https://www.didaktorika.gr/eadd/readonline?handle=10442/25980"
}
]