Last active
July 25, 2019 06:14
-
-
Save proteus-russ/e0b3786bd79ccd82a509a129355d73ce to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abstract class Entity<T : Serializable> { | |
abstract var id: T | |
override fun equals(other: Any?): Boolean = when { | |
this === other -> true | |
other == null -> false | |
Hibernate.getClass(other) != Hibernate.getClass(this) -> false | |
else -> Objects.equals(id, (other as Entity<*>).id) | |
} | |
override fun hashCode(): Int = id.hashCode() | |
override fun toString(): String = "${javaClass.simpleName}#${this.id}" | |
} | |
@Entity | |
@Table(name = SomeRule.TABLE_NAME, schema = Config.SCHEMA) | |
class SomeRule @JvmOverloads constructor( | |
@get:Id | |
@get:GeneratedValue(strategy = GenerationType.SEQUENCE, generator = GENERATOR) | |
@get:SequenceGenerator(name = GENERATOR, sequenceName = GENERATOR) | |
@get:Column(name = ID_COLUMN) | |
@get:NotNull | |
override var id: Long = 0, | |
@get:Type(type = ZipRangeUserType.USER_TYPE_NAME) | |
@get:Column(name = "zipRange", length = 1024) | |
var zipRange: ZipRange? = null, | |
@get:NotNull | |
var baz: String | |
) : Entity<Long>() { | |
companion object { | |
const val TABLE_NAME = "SomeRule" | |
const val ID_COLUMN = "${TABLE_NAME}_id" | |
private const val GENERATOR = "${Config.SCHEMA}.${ID_COLUMN}_seq" | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment