I'm trying to get a simple many-to-one relationship working with annotation based Hibernate objects, however I don't want to create another entity for the joined value as all I need to retrieve is a string.
As a simple example, I have a table with name titles in it (Mr, Mrs, etc) [id, label], and I have a table with people in it [id, title id, surname]. I want to have a String attribute in my Person class that maps to the label field of the titles table. I had a look at the hibernate annotations documentation and attempted to copy the example there but Hibernate complains that the OneToMany references an unknown entity: java.lang.String. Here is the code I'm using:
Code:
@Entity
@Table(name="people")
public class Account
{
private Long id;
private String title;
private String surname;
private void setId(Long id) { this.id = id; }
public void setTitle(String title) { this.title = title; }
public void setSurname(String surname) { this.surname = surname; }
@Id @GeneratedValue(strategy=GenerationType.AUTO)
public Long getId()
{
return this.id;
}
@ManyToOne
@JoinTable(name="titles", joinColumns={@JoinColumn(name="id")})
public String getTitle()
{
return this.title;
}
public String getSurname()
{
return this.surname;
}
}
I've used the CollectionOfElements annotation to retrieve a collection of String objects from another table, I can't manage to get a single String value though.
Any help would be much appreciated, thanks!