Java tutorial
/* **************************************************************************** * * * (c) Copyright 2006 ABM-utvikling * * * * This program is free software; you can redistribute it and/or modify it * * under the terms of the GNU General Public License as published by the * * Free Software Foundation; either version 2 of the License, or (at your * * option) any later version. * * * * This program is distributed in the hope that it will be useful, but * * WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General * * Public License for more details. http://www.gnu.org/licenses/gpl.html * * * **************************************************************************** */ package no.abmu.questionnarie.domain; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.hibernate.annotations.ForeignKey; import org.hibernate.annotations.Index; import org.hibernate.annotations.Cache; import org.hibernate.annotations.CacheConcurrencyStrategy; import org.hibernate.validator.NotNull; import javax.persistence.*; import java.util.HashSet; import java.util.Set; /** * @author Erik Romson, erik@zenior.no * @author $Author:$ * @version $Rev:$ * $Date:$ * copyright ABM-Utvikling * @hibernate.subclass discriminator-value="main_schema" * @hibernate.cache usage="nonstrict-read-write" * @composed 1 Has * no.abmu.finances.domain.SubReportSchema * @ view * @ opt schemaView */ @javax.persistence.Entity //@DiscriminatorValue("MainReportSchema") @javax.persistence.Table(schema = "QUESTIONNARIE", name = "QUESTIONNARIE_MAIN_REPORT_SCHEMA", uniqueConstraints = { @UniqueConstraint(columnNames = { "name", "version" }) }) //@Cache(usage = CacheConcurrencyStrategy.READ_ONLY) public class MainReportSchema extends ReportSchema { private static final Log logger = (Log) LogFactory.getLog(MainReportSchema.class); private Set<SubReportSchema> subReportSchemas = new HashSet<SubReportSchema>(); protected MainReportSchema() { } public MainReportSchema(String name) { super(name); } protected MainReportSchema(String name, String description) { super(name, description); } /** * @return * @hibernate.id generator-class="increment" */ @Id @GeneratedValue(strategy = GenerationType.AUTO) public Long getId() { return super.getId(); } /** * unique_key="unique_name_version" * * @hibernate.property not-null="true" */ @NotNull // @Column(unique = true) @Index(name = "reports_schema_name_idx") public String getName() { return super.getName(); } /** * @hibernate.property not-null="true" */ @NotNull(message = "report_schema_desc_not_null") public String getDescription() { return super.getDescription(); } /** * unique_key="unique_name_version" * * @hibernate.property not-null="true" */ @NotNull(message = "report_schema_version_not_null") public String getVersion() { return super.getVersion(); } /** * @hibernate.set lazy="false" * cascade="save-update" * table="FINANCE_REPORT_SCHEMA_ACCOUNT" * @hibernate.key column="FK_REPORT_SCHEMA_ID" * @hibernate.many-to-many class="no.abmu.finances.domain.Account" * column="FK_ACCOUNT_ID" * @hibernate.collection-key column="FK_REPORT_SCHEMA_ID" * @hibernate.collection-many-to-many class="no.abmu.finances.domain.Account" * column="FK_ACCOUNT_ID" */ // @ManyToMany(cascade = {CascadeType.ALL}) // @ForeignKey(name = "FK_REPORT_SCHEMA_ID", inverseName = "FK_ACCOUNT_ID") // @JoinTable( //// schema = "QUESTIONNARIE" // ) @ManyToMany(cascade = { CascadeType.ALL }, fetch = FetchType.EAGER, //TODO mappedBy = "mainReportSchemas") // @Cache(usage = CacheConcurrencyStrategy.READ_ONLY) public Set<Account> getAccounts() { return super.getAccounts(); } /** * @hibernate.set lazy="false" * cascade="save-update" * @hibernate.key column="FK_RS_SUBREPORT_ID" * @hibernate.one-to-many class="no.abmu.finances.domain.SubReportSchema" * @hibernate.collection-key column="FK_RS_SUBREPORT_ID" * @hibernate.collection-one-to-many class="no.abmu.finances.domain.SubReportSchema" * @hibernate.collection-cache usage="nonstrict-read-write" */ @OneToMany(cascade = { CascadeType.ALL }) @JoinColumn(name = "mrs_fk") // @Cache(usage = CacheConcurrencyStrategy.READ_ONLY) public Set<SubReportSchema> getSubReportSchemas() { return subReportSchemas; } public void addSubReportSchema(SubReportSchema subReportSchema) { subReportSchemas.add(subReportSchema); } private void setSubReportSchemas(Set<SubReportSchema> subReportSchemas) { this.subReportSchemas = subReportSchemas; } public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } final MainReportSchema that = (MainReportSchema) o; if (!getName().equals(that.getName())) { return false; } return true; } public int hashCode() { int result; result = (getName() != null ? getName().hashCode() : 0); result = 29 * result + (getDescription() != null ? getDescription().hashCode() : 0); return result; } }