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