Person.java
// license-header java merge-point
//
// Attention: Generated code! Do not modify by hand!
// Generated by: hibernate/HibernateEntity.vsl in andromda-hibernate-cartridge.
//
package org.andromda.test;
import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import java.util.HashSet;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
/**
* TODO: Model Documentation for Person
*/
@Entity
@Table(name = "PERSON")
// Uncomment to enable caching for Person
// @org.hibernate.annotations.Cache(usage = org.hibernate.annotations.CacheConcurrencyStrategy.read-write)
@NamedQueries
({
@NamedQuery(name = "Person.findAll", query = "from Person as person"),
@NamedQuery(name = "Person.findByName", query = "from Person as person where person.name = ?"),
@NamedQuery(name = "Person.findByNameOrBirthDate", query = "from Person as person where person.name = ? and person.birthDate = ?")
})
// HibernateEntity.vsl annotations merge-point
public abstract class Person
implements Serializable, Comparable<Person>
{
/**
* The serial version UID of this class. Needed for serialization.
*/
private static final long serialVersionUID = 2884649199794959150L;
// Generate 3 attributes
private String name;
/**
* TODO: Model Documentation for Person.name
* @return this.name String
*/
@Column(name = "NAME", unique = true, nullable = true, insertable = true, updatable = true)
public String getName()
{
return this.name;
}
/**
* TODO: Model Documentation for Person.name
* @param nameIn String
*/
public void setName(String nameIn)
{
this.name = nameIn;
}
private Date birthDate;
/**
* TODO: Model Documentation for Person.birthDate
* @return this.birthDate Date
*/
@Column(name = "BIRTH_DATE", unique = true, nullable = true, insertable = true, updatable = true)
public Date getBirthDate()
{
return this.birthDate;
}
/**
* TODO: Model Documentation for Person.birthDate
* @param birthDateIn Date
*/
public void setBirthDate(Date birthDateIn)
{
this.birthDate = birthDateIn;
}
private Long id;
/**
* TODO: Model Documentation for Person.id
* @return this.id Long
*/
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "ID", unique = false, nullable = false, insertable = true, updatable = true)
public Long getId()
{
return this.id;
}
/**
* TODO: Model Documentation for Person.id
* @param idIn Long
*/
public void setId(Long idIn)
{
this.id = idIn;
}
// Generate 1 associations
private Collection<Car> cars = new HashSet<Car>();
/**
* TODO: Model Documentation for Car
* @return this.cars Collection<Car>
*/
@OneToMany( mappedBy = "owner")
public Collection<Car> getCars()
{
return this.cars;
}
/**
* TODO: Model Documentation for Car
* @param carsIn Collection<Car>
*/
public void setCars(Collection<Car> carsIn)
{
this.cars = carsIn;
}
/**
* TODO: Model Documentation for Car
* @param elementToAdd Car
* @return <tt>true</tt> if this collection changed as a result of the
* call
*/
public boolean addCars(Car elementToAdd)
{
return this.cars.add(elementToAdd);
}
/**
* TODO: Model Documentation for Car
* @param elementToRemove Car
* @return <tt>true</tt> if this collection changed as a result of the
* call
*/
public boolean removeCars(Car elementToRemove)
{
return this.cars.remove(elementToRemove);
}
/**
* Returns <code>true</code> if the argument is an Person instance and all identifiers for this entity
* equal the identifiers of the argument entity. Returns <code>false</code> otherwise.
*/
@Override
public boolean equals(Object object)
{
if (this == object)
{
return true;
}
if (!(object instanceof Person))
{
return false;
}
final Person that = (Person)object;
if (this.id == null || that.getId() == null || !this.id.equals(that.getId()))
{
return false;
}
return true;
}
/**
* Returns a hash code based on this entity's identifiers.
*/
@Override
public int hashCode()
{
int hashCode = 0;
hashCode = 29 * hashCode + (this.id == null ? 0 : this.id.hashCode());
return hashCode;
}
/**
* Constructs new instances of {@link Person}.
*/
public static final class Factory
{
/**
* Constructs a new instance of {@link Person}.
* @return new PersonImpl()
*/
public static Person newInstance()
{
return new PersonImpl();
}
/**
* Constructs a new instance of {@link Person}, taking all required and/or
* read-only properties as arguments, except for identifiers.
* @param name String
* @param birthDate Date
* @return newInstance
*/
public static Person newInstance(String name, Date birthDate)
{
final Person entity = new PersonImpl();
entity.setName(name);
entity.setBirthDate(birthDate);
return entity;
}
/**
* Constructs a new instance of {@link Person}, taking all possible properties
* (except the identifier(s))as arguments.
* @param name String
* @param birthDate Date
* @param cars Collection<Car>
* @return newInstance Person
*/
public static Person newInstance(String name, Date birthDate, Collection<Car> cars)
{
final Person entity = new PersonImpl();
entity.setName(name);
entity.setBirthDate(birthDate);
entity.setCars(cars);
return entity;
}
}
/**
* @see Comparable#compareTo
*/
public int compareTo(Person o)
{
int cmp = 0;
if (this.getId() != null)
{
cmp = this.getId().compareTo(o.getId());
}
else
{
if (this.getName() != null)
{
cmp = (cmp != 0 ? cmp : this.getName().compareTo(o.getName()));
}
if (this.getBirthDate() != null)
{
cmp = (cmp != 0 ? cmp : this.getBirthDate().compareTo(o.getBirthDate()));
}
}
return cmp;
}
// HibernateEntity.vsl merge-point
}