-->
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.  [ 3 posts ] 
Author Message
 Post subject: Can a Oracle View be mapped using Hibernate 3?
PostPosted: Wed Nov 12, 2008 4:22 am 
Newbie

Joined: Wed Nov 12, 2008 4:18 am
Posts: 2
Location: Singapore
Hi All,

Can a Oracle database view be mapped in Hibernate 3?

-Murali*


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 12, 2008 4:35 am 
Newbie

Joined: Wed Nov 12, 2008 2:14 am
Posts: 6
Yes.
There is no difference between a view and a base table for a Hibernate mapping.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 12, 2008 4:53 am 
Newbie

Joined: Wed Nov 12, 2008 4:18 am
Posts: 2
Location: Singapore
if it is possible then i understand the ID columns can be any single column or composite columns.

I have a problem when trying to establish a relationship between a view and a table.

I am pasting the code,


1 . Lecture View

@Entity
@Table(name="NCE_EPF_LPA")
public class LecturerPartics {

private String deptCode;
private String staffNo;
private String facultyCode;


private Department department;

@Id
@Column(name="STF_N")
public String getStaffNo() {
return staffNo;
}
public void setStaffNo(String staffNo) {
this.staffNo = staffNo;
}

@Column(name="DEPT_C")
public String getDeptCode() {
return deptCode;
}
public void setDeptCode(String deptCode) {
this.deptCode = deptCode;
}


@Column(name="FAC_C")
public String getFacultyCode() {
return facultyCode;
}
public void setFacultyCode(String facultyCode) {
this.facultyCode = facultyCode;
}


@ManyToOne
@JoinColumn(name="DEPT_C")
public Department getDepartment() {
return department;
}
public void setDepartment(Department department) {
this.department = department;
}


}


2. Department Table


@Entity
@Table(name="DEPARTMENT")
public class Department {

private String deptCode;
private String facCode;


private Faculty faculty;
private List<LecturerPartics> lecturer = new ArrayList<LecturerPartics>();

@Id
@Column(name="DEPT_C")
public String getDeptCode() {
return deptCode;
}
public void setDeptCode(String deptCode) {
this.deptCode = deptCode;
}

@Column(name="FAC_C")
public String getFacCode() {
return facCode;
}
public void setFacCode(String facCode) {
this.facCode = facCode;
}

@OneToMany(mappedBy="department")
@PrimaryKeyJoinColumn
public List<LecturerPartics> getLecturer() {
return lecturer;
}
public void setLecturer(List<LecturerPartics> lecturer) {
this.lecturer = lecturer;
}

// equals and hashcode included

@OneToMany(mappedBy="department")
@JoinColumn(name="FAC_C")
public Faculty getFaculty() {
return faculty;
}
public void setFaculty(Faculty faculty) {
this.faculty = faculty;
}

}



3. Faculty <Table> -- please note it doesn't have any column to map to department.


@Entity
@Table(name="FACULTY")
public class Faculty {

private String facultyCode;
private String facultyText;

private Department department;

@Id
@Column(name="FAC_C")
public String getFacultyCode() {
return facultyCode;
}
public void setFacultyCode(String facultyCode) {
this.facultyCode = facultyCode;
}

@Column(name="FAC_T")
public String getFacultyText() {
return facultyText;
}
public void setFacultyText(String facultyText) {
this.facultyText = facultyText;
}


@OneToMany(mappedBy="faculty",fetch=FetchType.LAZY)
@JoinColumn(name="FAC_C")
public List<LecturerPartics> getLecturer() {
return lecturer;
}
public void setLecturer(List<LecturerPartics> lecturer) {
this.lecturer = lecturer;
}


@ManyToOne
public Department getDepartment() {
return department;
}
public void setDepartment(Department department) {
this.department = department;
}

// equals and hashcode implemented
}



Please let me know if i am doing something wrong here.

-Murali*


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.