Skip to content
Snippets Groups Projects
Commit f7a90786 authored by Tamas Bunth's avatar Tamas Bunth
Browse files

jpa one-to-many, finally

parent 9d7e23ca
No related branches found
No related tags found
No related merge requests found
......@@ -22,10 +22,8 @@ data class MobilData(
var wifiDataUsage: Int?,
@Temporal(TemporalType.TIMESTAMP)
var actualTime: Date?,
@ElementCollection
@CollectionTable(
name="process",
joinColumns = arrayOf(JoinColumn(name = "process_id")))
@OneToMany(cascade=arrayOf(CascadeType.ALL), orphanRemoval = true)
@JoinColumn(name = "user_id")
var processList: List<MobileProcess>?,
@Id @GeneratedValue(strategy = GenerationType.AUTO)
var id: Long = 0) {
......
package mobildata.model
import javax.persistence.Column
import javax.persistence.Embeddable
import java.lang.reflect.Constructor
import javax.persistence.*
@Embeddable
@Entity
@Table(name = "process")
data class MobileProcess(
@Column(name="process")
val process: String? = null
){}
\ No newline at end of file
val process: String? = null,
@Column(name="user_id")
var user_id: Long,
@Id @GeneratedValue(strategy = GenerationType.AUTO)
var id: Long = 0
){
constructor() :this(null, 0, 0)
}
\ No newline at end of file
......@@ -21,7 +21,7 @@ class MobilDataHandler (val mobilRepository: MobilDataRepository,
private fun inputToMobilData(input : MobilDataIn, user:User? ): MobilData {
var processes = ArrayList<MobileProcess>()
input.processList?.forEach {
processes.add(MobileProcess(it))
processes.add(MobileProcess(it, 0, 0))
}
return MobilData(user_id = user!!.id, location_lat = input.location?.latitude,
location_long = input.location?.longitude, battery = input.battery,
......
......@@ -18,6 +18,7 @@ create table "user" (
create table process (
id int8 not null,
user_id int8 not null,
process VARCHAR(255)
);
......@@ -36,7 +37,6 @@ create table mobil_data (
battery_temp DOUBLE PRECISION,
mobile_data_usage INTEGER,
wifi_data_usage INTEGER,
process_id INTEGER,
actual_time TIMESTAMP not null,
is_charging BOOLEAN
);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment