/* * JBoss, Home of Professional Open Source * Copyright 2012, Red Hat, Inc. and/or its affiliates, and individual * contributors by the @authors tag. See the copyright.txt in the * distribution for a full listing of individual contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.as.quickstarts.kitchensink.model; import java.io.Serializable; import java.util.ArrayList; import java.util.List; import javax.persistence.CascadeType; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.OneToMany; import javax.validation.Valid; import javax.validation.constraints.NotNull; import javax.validation.constraints.Pattern; import javax.validation.constraints.Size; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import org.hibernate.annotations.GenericGenerator; import org.hibernate.annotations.Proxy; import org.hibernate.search.annotations.Analyze; import org.hibernate.search.annotations.Field; import org.hibernate.search.annotations.Fields; import org.hibernate.search.annotations.Indexed; import org.hibernate.search.annotations.IndexedEmbedded; import org.hibernate.search.annotations.Norms; import org.hibernate.search.annotations.Store; @Entity @XmlRootElement @Indexed @Proxy(lazy = false) public class Member implements Serializable { @Id @GeneratedValue(generator = "uuid") @GenericGenerator(name = "uuid", strategy = "uuid2") private String id; @NotNull @Size(min = 1, max = 50) @Pattern(regexp = "[A-Za-z ]*", message = "must contain only letters and spaces") @Fields({ @Field(analyze = Analyze.NO, norms = Norms.NO, store = Store.YES, name = "sortableStoredName"), @Field(analyze = Analyze.YES, norms = Norms.YES) }) private String name; @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) @XmlElement(name = "contacts") @Valid @IndexedEmbedded private List<ContactDetails> contactDetails; public Member() { contactDetails = new ArrayList<ContactDetails>(); } public String getId() { return id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public List<ContactDetails> getContactDetails() { return contactDetails; } public void addContactDetails(ContactDetails newContactDetails) { contactDetails.add( newContactDetails ); } @Override public String toString() { final StringBuilder sb = new StringBuilder(); sb.append( "Member" ); sb.append( "{id='" ).append( id ).append( '\'' ); sb.append( ", name='" ).append( name ).append( '\'' ); sb.append( ", contactDetails=" ).append( contactDetails ); sb.append( '}' ); return sb.toString(); } }