-->
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: How to Use Hibernate Annotations?
PostPosted: Thu Jun 22, 2006 7:00 am 
Newbie

Joined: Thu Jun 22, 2006 6:51 am
Posts: 1
I am using HIbernate3.2.0cr2 with hibernate-anntations-3.2.0

I have the foll . use case :

Student ------ Registrar ---------College


I am using annotations for specifying many-to-many relationship via the association table "Registrar"


Here are the POJOs :

Student.java :
@Entity
@Table(name = "tbl_student")
@Inheritance(strategy=InheritanceType.JOINED)
public class Student implements Serializable {


private static final long serialVersionUID = 1L;

private Long id;

private String name;

protected Set colleges = new HashSet();

public Student() {

}

@Column(name = "student_name", nullable = false, length = 50)
public String getName() {
return name;
}

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

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long getId() {
return id;
}

public void setId(Long student_id) {
this.id = student_id;
}

@ManyToMany(
cascade={CascadeType.PERSIST, CascadeType.MERGE},
mappedBy="college",
targetEntity=College.class
)
public Set getColleges() {
return colleges;
}


}



College.java :
@Entity

@Table(name = "tbl_college")

@Inheritance(strategy = InheritanceType.SINGLE_TABLE)

@DiscriminatorColumn(name = "college_type",
discriminatorType = DiscriminatorType.STRING)

public class College implements Serializable {


@ManyToMany(
targetEntity = Student.class,
cascade = { CascadeType.PERSIST,CascadeType.MERGE }
)
@JoinTable(
name = "TBL_REGISTRAR",
joinColumns = { @JoinColumn(name = "COLLEGE_ID") },
inverseJoinColumns = { @JoinColumn(name = "STUDENT_ID") }
)

public Set getStudents() {
return students;
}

protected Set students = new HashSet();

private static final long serialVersionUID = 1L;

Long college_id;

private String name;

public College() {

// TODO Auto-generated constructor stub
}

@Column(name = "college_name", nullable = false, length = 50)
public String getName() {
return name;
}

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

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long getCollege_id() {
return college_id;
}

public void setCollege_id(Long college_id) {
this.college_id = college_id;
}

}


Registrar.java:
@Entity
@Table(name = "tbl_registrar")

public class Registrar implements Serializable {

private static final long serialVersionUID = 1L;

public Registrar() {

}



}

I am getting this exception :
Caused by: org.hibernate.AnnotationException: mappedBy reference an unknown property: com.webify.registration.domain.College.college in com.webify.registration.domain.Student.college

Pls help me with the mapping?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 22, 2006 7:48 am 
Beginner
Beginner

Joined: Tue Nov 22, 2005 5:33 am
Posts: 31
Change to:
mappedBy="students"

_________________
Emil
Don't forget to rate, I'm desperate!


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.