-->
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: Join table - where place @Id?
PostPosted: Sat May 22, 2010 9:39 am 
Newbie

Joined: Wed Mar 11, 2009 7:15 am
Posts: 13
I have classes Clinic, Test and joinclass TestClinic.
Code:
@Entity
@Table(name = "Test")
public class Test {

   private long id;
   private String name;

   @Id
   @GeneratedValue
   public long getId() {
      return id;
   }
   public void setId(long id) {
      this.id = id;
   }

   public String getName() {
      return name;
   }
   public void setName(String name) {
      this.name = name;
   }

Code:
@Entity
@Table(name = "Clinic")
public class Clinic {

   private long id;
   private String name;
   
   public Clinic() {
   }
   
   @Id
   @GeneratedValue
   public long getId() {
      return id;
   }
   public void setId(long id) {
      this.id = id;
   }

   public String getName() {
      return name;
   }

   public void setName(String name) {
      this.name = name;
   }
}

And the join class with extra column (price):
Code:
@Entity
@Table(name = "TestClinic")
public class TestClinic {

   private float price;
   private Test test;
   private Clinic clinic;

   public float getPrice() {
      return price;
   }
   public void setPrice(float price) {
      this.price = price;
   }

   //@Id
   @ManyToOne
   @JoinColumn(name="test_id")
   public Test getTest() {
      return test;
   }
   public void setTest(Test test) {
      this.test = test;
   }

   //@Id
   @ManyToOne
   @JoinColumn(name="clinic_id")
   public Clinic getClinic() {
      return clinic;
   }
   public void setClinic(Clinic clinic) {
      this.clinic = clinic;
   }
}

Code:
Caused by: org.hibernate.AnnotationException: No identifier specified for entity: pl.diagno.model.vo.TestClinic

I know that the problem is with lack of @Id... I tried to add @Id before getters of Clinic and Test, but there is another exception:
Code:
Caused by: org.hibernate.MappingException: Could not determine type for: pl.diagno.model.vo.Test, for columns: [org.hibernate.mapping.Column(test)]

Where should I add @Id or maybe should I design classes in the another way? But how? :|
Help appreciated!


Top
 Profile  
 
 Post subject: Re: Join table - where place @Id?
PostPosted: Sat May 22, 2010 1:18 pm 
Newbie

Joined: Wed Mar 11, 2009 7:15 am
Posts: 13
Second solution from this blog
http://sieze.wordpress.com/2009/09/04/m ... using-jpa/
helps me, but if someone know easier solution, please share this knowledge.


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.