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

Hibernate example source code file (PropertyList.java)

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

cascade, column, generatedvalue, integer, joincolumn, joincolumn, list, property, property, propertylist, propertylist, string, string, t, util

The Hibernate PropertyList.java source code

package org.hibernate.test.annotations.any;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.OrderColumn;
import javax.persistence.Table;
import org.hibernate.annotations.Any;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import org.hibernate.annotations.ManyToAny;

@Entity
@Table( name = "property_list" )
public class PropertyList<T extends Property> {
	private Integer id;

	private String name;

	private T someProperty;

	private List<T> generalProperties = new ArrayList();

	public PropertyList() {
		super();
	}

	public PropertyList(String name) {
		this.name = name;
	}

    @ManyToAny( metaDef = "Property", metaColumn = @Column(name = "property_type") )
    @Cascade( { org.hibernate.annotations.CascadeType.ALL })
    @JoinTable(name = "list_properties",
			joinColumns = @JoinColumn(name = "obj_id"),
			inverseJoinColumns = @JoinColumn(name = "property_id")
	)
    @OrderColumn(name = "prop_index")
    public List<T> getGeneralProperties() {
        return generalProperties;
    }

    public void setGeneralProperties(List<T> generalProperties) {
        this.generalProperties = generalProperties;
    }

	@Id
	@GeneratedValue
	public Integer getId() {
		return id;
	}

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

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

    @Any( metaDef = "Property", metaColumn = @Column(name = "property_type") )
	@Cascade( CascadeType.ALL )
	@JoinColumn(name = "property_id")
	public T getSomeProperty() {
        return someProperty;
    }

	public void setSomeProperty(T someProperty) {
		this.someProperty = someProperty;
	}

	public void addGeneratedProperty(T property) {
		this.generalProperties.add( property );
	}
}

Other Hibernate examples (source code examples)

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