-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Annotations - Simple join a string from another table?
PostPosted: Mon Aug 17, 2009 11:50 am 
Newbie

Joined: Thu Aug 06, 2009 10:59 am
Posts: 6
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!


Top
 Profile  
 
 Post subject: Re: Annotations - Simple join a string from another table?
PostPosted: Tue Aug 18, 2009 5:05 am 
Newbie

Joined: Thu Aug 06, 2009 10:59 am
Posts: 6
Still trying to work this out, can anyone at least hint as to whether or not I actually need another class here? I don't believe I do and I'd really rather not use another class to join a String.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.