Hey!
I hope you can help me with my obviously simple problem. :)
I am using the Dropwizard Framework with the integrated hibernate to access a MySQL database and now I would like to do a simple JOIN.
I think it is good to break down the problem to a simple Room<-->Person example:
So, given the following sample table structure with Person(ID,ROOM_ID) and ROOM(ID,NAME):
[SQL]
CREATE TABLE IF NOT EXISTS `PERSON` (
`ID` VARCHAR(100) NOT NULL,
`ROOM_ID` INT NULL,
PRIMARY KEY (`ID`))
ENGINE = InnoDB;
CREATE TABLE IF NOT EXISTS `ROOM` (
`ID` INT NOT NULL AUTO_INCREMENT,
`NAME` VARCHAR(45) NULL,
PRIMARY KEY (`ID`))
ENGINE = InnoDB;
[/SQL]
... I would like to join PERSON p with ROOM r ON p.ROOM_ID=r.ID. --> NOTHING special at all :(
Of course, pure SQL works:
[SQL]
SELECT p.ID,r.NAME FROM PERSON p INNER JOIN ROOM r ON p.ROOM_ID=r.ID
[/SQL]
So, since I am using Hibernate, there are two sample POJOs:
[JAVA]
@Entity
@Table(name = "PERSON")
@NamedQuery(name = "...", query = "SELECT p,r FROM Person p INNER JOIN FETCH p.room r")
public class Person
{
@Id
@Column(name = "ID")
private String ID;
@ManyToOne(targetEntity = Room.class)
@Fetch(FetchMode.JOIN)
@JoinColumn(name = "ID")
private Room room;
//getter, setter, stuff :)
}
@/*just to clarify:*/javax.persistence.Entity
@Table(name = "ROOM")
public class Room
{
@Id
private int ID;
@Column(name = "NAME")
private String NAME;
@OneToMany(targetEntity = Person.class)
@JoinColumn(name = "ROOM_ID")
private Set<Person> persons;
//again ... getter, setter, stuff
}
[/JAVA]
And when I start the Dropwizard project, there occurs the following error:
org.hibernate.AnnotationException: Use of @OneToMany or @ManyToMany targeting an unmapped class com.bla.bla.Room.persons[this.is.shit.isn't.it.Person]
So, what are the problems? :)