i upgrade my project and i want to use Embedded and associated.
I have 2 class are Person and Book. a book will have an author. Book will have relationship one - one with Person and Person will have relationship one - many with Book. 2 class as below :
Person.java
Code:
package quickstart.model;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import org.hibernate.mapping.Set;
import org.hibernate.search.annotations.*;
import quickstart.model.Person;
@Entity
@Indexed(index="indexes/Person")
public class Person {
@Id
@GeneratedValue
@DocumentId
private Integer id;
@Field(index=Index.TOKENIZED, store=Store.NO)
private String firstName;
@Field(index=Index.TOKENIZED, store=Store.NO)
private String lastName;
@ContainedIn
@OneToMany(mappedBy = "Person")
private Set<Book> books;
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
}
and Book.java
Code:
package quickstart.model;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import org.hibernate.annotations.CascadeType;
import org.hibernate.search.annotations.*;
@Entity
@Indexed(index="indexes/Book")
public class Book {
@Id
@GeneratedValue
@DocumentId
private Integer id;
@Field(index=Index.TOKENIZED, store=Store.NO)
private String name;
@OneToOne( cascade = { CascadeType.PERSIST, CascadeType.REMOVE } )
@IndexedEmbedded
private int author;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAuthor() {
return author;
}
public void setAuthor(int author) {
this.author = author;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
}
but it throw 5 errors as below:
Code:
-Type mismatch: cannot convert from CascadeType to CascadeType
-The type Set is not generic; it cannot be parameterized with arguments <Book>
-Target null.class is not an entity
-Target null.class is not an entity
-MappedBy specified for books does not exist on the target entity class
can you show me the problem????
thx[/code][/quote]