zoukankan      html  css  js  c++  java
  • [Kotlin] Mapping between two entities

    For example we have tow Entities:

    package com.virtualpairprogrammers.theater.domain
    
    import javax.persistence.*
    
    @Entity
    data class Performance(
            @Id @GeneratedValue(strategy = GenerationType.AUTO)
            val id: Long,
            val title: String,
            @OneToMany(mappedBy = "performance")
            val bookings: List<Booking>
    )
    package com.virtualpairprogrammers.theater.domain
    
    import javax.persistence.*
    
    @Entity
    data class Booking(
            @Id @GeneratedValue(strategy = GenerationType.AUTO)
            val id: Long,
            // relationship
            // multi seats can exists in one booking
            @ManyToOne
            val seat: Seat,
            @ManyToOne
            val performance: Performance,
            val customerName: String
    )

    Actually, it is not good to put 'bookings, performance, customerName' into constructor. Because it will generate very long sql string.

    A better way:

    package com.virtualpairprogrammers.theater.domain
    
    import javax.persistence.*
    
    @Entity
    data class Performance(
            @Id @GeneratedValue(strategy = GenerationType.AUTO)
            val id: Long,
            val title: String
    ) {
            @OneToMany(mappedBy = "performance")
            lateinit var bookings: List<Booking>
    }
    


    package com.virtualpairprogrammers.theater.domain import javax.persistence.* @Entity data class Booking( @Id @GeneratedValue(strategy = GenerationType.AUTO) val id: Long, val customerName: String ) { // relationship // multi seats can exists in one booking @ManyToOne lateinit var seat: Seat @ManyToOne lateinit var performance: Performance }
  • 相关阅读:
    gulp ( http://markpop.github.io/2014/09/17/Gulp入门教程 )
    less 官网讲解 ( http://www.bootcss.com/p/lesscss/ )
    js 闭包 弊端
    js 闭包 理解 copy
    js 中 的 if使用条件
    $ each() 小结
    文件自动加载
    (openssl_pkey_get_private 函数不存在)phpstudy开启openssl.dll 时提示httpd.exe 丢失libssl-1_1.dll
    form
    js字符串处理
  • 原文地址:https://www.cnblogs.com/Answer1215/p/13945906.html
Copyright © 2011-2022 走看看