alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Hibernate example source code file (ParentEntity.java)

This example Hibernate source code file (ParentEntity.java) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Hibernate tags/keywords

audited, classtypeentity, classtypeentity, discriminator_query, from, generatedvalue, id, long, long, parententity, parententity, string, string, where

The Hibernate ParentEntity.java source code

package org.hibernate.envers.test.integration.inheritance.single.discriminatorformula;

import org.hibernate.annotations.DiscriminatorFormula;
import org.hibernate.envers.Audited;

import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

/**
 * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
 */
@Entity
@DiscriminatorFormula(ParentEntity.DISCRIMINATOR_QUERY)
@DiscriminatorValue(ClassTypeEntity.PARENT_TYPE)
@Audited
public class ParentEntity {
    public static final String DISCRIMINATOR_QUERY = "(SELECT c.type FROM ClassTypeEntity c WHERE c.id = typeId)";

    @Id
    @GeneratedValue
    protected Long id;

    protected Long typeId;

    protected String data;

    public ParentEntity() {
    }

    public ParentEntity(Long typeId, String data) {
        this.typeId = typeId;
        this.data = data;
    }

    public ParentEntity(Long id, Long typeId, String data) {
        this.id = id;
        this.typeId = typeId;
        this.data = data;
    }

    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof ParentEntity)) return false;

        ParentEntity that = (ParentEntity) o;

        if (id != null ? !id.equals(that.id) : that.id != null) return false;
        if (typeId != null ? !typeId.equals(that.id) : that.typeId != null) return false;
        if (data != null ? !data.equals(that.data) : that.data != null) return false;

        return true;
    }

    public int hashCode() {
        int result;
        result = (id != null ? id.hashCode() : 0);
        result = 31 * result + (typeId != null ? typeId.hashCode() : 0);
        result = 31 * result + (data != null ? data.hashCode() : 0);
        return result;
    }

    public String toString() {
        return "ParentEntity(id = " + id + ", typeId = " + typeId + ", data = " + data + ")";
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getTypeId() {
        return typeId;
    }

    public void setTypeId(Long typeId) {
        this.typeId = typeId;
    }

    public String getData() {
        return data;
    }

    public void setData(String data) {
        this.data = data;
    }
}

Other Hibernate examples (source code examples)

Here is a short list of links related to this Hibernate ParentEntity.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.