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

Hibernate example source code file (Item.java)

This example Hibernate source code file (Item.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

column, double, double, generatedvalue, id, io, item, item, items, items_sec, items_sec, long, long, override, table

The Hibernate Item.java source code

package org.hibernate.test.namingstrategy;

import javax.persistence.*;
import java.io.Serializable;

/**
 * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
 */
@Entity
@Table(name = "ITEMS")
@SecondaryTable(name="ITEMS_SEC")
public class Item implements Serializable {
    @Id
    @GeneratedValue
    private Long id;

    @Column(name = "price")
    private Double price;

    @Column(name = "price", table = "ITEMS_SEC")
    private Double specialPrice;

    public Item() {
    }

    public Item(Double price, Double specialPrice) {
        this.price = price;
        this.specialPrice = specialPrice;
    }

    public Item(Long id, Double price, Double specialPrice) {
        this.id = id;
        this.price = price;
        this.specialPrice = specialPrice;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Item item = (Item) o;

        if (id != null ? !id.equals(item.id) : item.id != null) return false;
        if (price != null ? !price.equals(item.price) : item.price != null) return false;
        if (specialPrice != null ? !specialPrice.equals(item.specialPrice) : item.specialPrice != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = id != null ? id.hashCode() : 0;
        result = 31 * result + (price != null ? price.hashCode() : 0);
        result = 31 * result + (specialPrice != null ? specialPrice.hashCode() : 0);
        return result;
    }

    public Long getId() {
        return id;
    }

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

    public Double getPrice() {
        return price;
    }

    public void setPrice(Double price) {
        this.price = price;
    }

    public Double getSpecialPrice() {
        return specialPrice;
    }

    public void setSpecialPrice(Double specialPrice) {
        this.specialPrice = specialPrice;
    }
}

Other Hibernate examples (source code examples)

Here is a short list of links related to this Hibernate Item.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.