Skip to content

Instantly share code, notes, and snippets.

@Tonel
Created July 26, 2020 13:50
Show Gist options
  • Select an option

  • Save Tonel/9f96f5543604a9f3fdd2d7bd32b9c126 to your computer and use it in GitHub Desktop.

Select an option

Save Tonel/9f96f5543604a9f3fdd2d7bd32b9c126 to your computer and use it in GitHub Desktop.
@Entity
@Table(name = "author")
open class Author {
@get:Id
@get:GeneratedValue(strategy = GenerationType.IDENTITY, generator = "native")
@get:Column(name = "id", unique = true, nullable = false)
open var id: Int? = null
@get:Basic
@get:Column(name = "name", nullable = false, length = 50)
open var name: String? = null
@get:Basic
@get:Column(name = "surname", nullable = false, length = 50)
open var surname: String? = null
@get:Basic
@get:Column(name = "birthDate", nullable = true)
@get:Temporal(TemporalType.DATE)
open var birthDate: Date? = null
@get:ManyToMany(fetch = FetchType.LAZY)
@get:JoinTable(
name = "author_book",
joinColumns = [JoinColumn(name = "author_id")],
inverseJoinColumns = [JoinColumn(name = "book_id")]
)
open var books: MutableSet<Book> = HashSet()
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false
other as Author
if (id != other.id) return false
return true
}
override fun hashCode(): Int {
if (id == null)
return 0
return id!!
}
}
@Entity
@Table(name = "book")
open class Book {
@get:Id
@get:GeneratedValue(strategy = GenerationType.IDENTITY, generator = "native")
@get:Column(name = "id", unique = true, nullable = false)
open var id: Int? = null
@get:Basic
@get:Column(name = "title", nullable = false, length = 50)
open var title: String? = null
@get:Basic
@get:Column(name = "releaseDate", nullable = true)
@get:Temporal(TemporalType.DATE)
open var releaseDate: Date? = null
@get:ManyToMany(
fetch = FetchType.LAZY,
mappedBy = "books"
)
open var authors: MutableSet<Author> = HashSet()
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false
other as Book
if (id != other.id) return false
return true
}
override fun hashCode(): Int {
if (id == null)
return 0
return id!!
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment