Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

unable to map the hbm files

 
vijaya Yarlagadda
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

This is my code...

/*
* studentRegistrationDTO.java
*
* Created on June 16, 2008, 10:03 AM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/

package com.sms.dto;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class studentRegistrationDTO {

/** Creates a new instance of studentRegistrationDTO */
public studentRegistrationDTO() {
}

private String cls;
private String section;
private int id;
private String studentFirstName;
private String studentLastName;
// private List details = new ArrayList();
private Set details = new HashSet();


public int getid() {
return getId();
}

public void setid(int id) {
this.setId(id);
}

public String getStudentFirstName() {
return studentFirstName;
}

public void setStudentFirstName(String studentFirstName) {
this.studentFirstName = studentFirstName;
}

public String getStudentLastName() {
return studentLastName;
}

public void setStudentLastName(String studentLastName) {
this.studentLastName = studentLastName;
}

public void addDetail(marksMasterDTO marks) {
getDetails().add(marks);
}

public void removeDetail(marksMasterDTO marks) {
getDetails().remove(marks);
}

public String getSection() {
return section;
}

public void setSection(String section) {
this.section = section;
}

public String getCls() {
return cls;
}

public void setCls(String cls) {
this.cls = cls;
}

public int getId() {
return id;
}

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

public Set getDetails() {
return details;
}

public void setDetails(Set details) {
this.setDetails(details);
}
}

studentRegistration.hbm.xml::

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
<class name="com.sms.dto.studentRegistrationDTO" table="student_registration">
<id name="id" column="id" type="int" >
<generator class="assigned"/>
</id>
<property name="cls" column="class"/>
<property name="section" column="section"/>
<property name="studentFirstName" column="first_name" />
<property name="studentLastName" column="last_name" />
<set name="details" cascade="all" inverse="true" lazy="true">
<key column="class"/>
<one-to-many class="com.sms.dto.marksMasterDTO"/>
</set>
</class>
</hibernate-mapping>

marksMaster class(pojo class)

/*
* marksMasterDTO.java
*
* Created on June 16, 2008, 10:07 AM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/

package com.sms.dto;
public class marksMasterDTO {
private String cls;
private String section;
private String total;
private String status;
private String rank;
private int id;


public String getStatus() {
return status;
}

public void setStatus(String status) {
this.status = status;
}

public String getRank() {
return rank;
}

public void setRank(String rank) {
this.rank = rank;
}

public String getCls() {
return cls;
}

public void setCls(String cls) {
this.cls = cls;
}

public String getSection() {
return section;
}

public void setSection(String section) {
this.section = section;
}

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}
public String getTotal() {
return total;
}

public void setTotal(String total) {
this.total = total;
}
}

marksMaster hbm file::

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
<class name="com.sms.dto.marksMasterDTO" table="marks_status">
<id name="id" column="id" type="int" unsaved-value="0">
<generator class="assigned"/>
</id>
<property name="cls" column="class"/>
<property name="section" column="section"/>
<property name="total" column="total" />
<property name="status" column="status" />
<property name="rank" column="rank"/>

</class>
</hibernate-mapping>

these are my classes and hbm files. My cfg file is being configured. and this is my class

public ArrayList getDetailsForPromotion(PromotionDTO pdto) {

System.out.println("entered PromotionDAO");

ArrayList promotion = new ArrayList();

try {
System.out.println("entered try of PromotionDAO");
String clsName=(String)pdto.getClassName();
System.out.println(clsName);
String clsDivision = (String)pdto.getClassDivision();
System.out.println(clsDivision);
Configuration cfg = new Configuration()
.addClass(com.sms.dto.studentRegistrationDTO.class)
.addClass(com.sms.dto.marksMasterDTO.class);
System.out.println("configuration------ ");
System.out.println("configuration "+cfg);
SessionFactory factory=cfg.buildSessionFactory();
Session session=factory.openSession();
Transaction tx = session.beginTransaction();
String query="select s.id,s.studentLastName, s.studentFirstName,m.rank,m.status,m.total from studentRegistrationDTO s, marksMasterDTO m where s.cls='"+clsName+"' and m.class='"+clsName+"'";
Query query1=session.createQuery(query);
System.out.println(query1);

for(Iterator it=query1.iterate();it.hasNext() {

studentRegistrationDTO insurance=(studentRegistrationDTO)it.next();
System.out.println("firstName: " + insurance.getStudentFirstName());
pdto.setStudentFirstName(insurance.getStudentFirstName());
System.out.println("Last Name: " + insurance.getStudentLastName());
pdto.setStudentLastName(insurance.getStudentLastName());
System.out.println("id :"+ insurance.getId());
pdto.setId(insurance.getId());
}

for(Iterator it1=query1.iterate();it1.hasNext() {

marksMasterDTO marks=(marksMasterDTO)it1.next();
System.out.println("rank: " + marks.getRank());
pdto.setRank(marks.getRank());
System.out.println("total: " + marks.getTotal());
pdto.setPercentage(marks.getTotal());
System.out.println("id :"+ marks.getStatus());
pdto.setStatus(marks.getStatus());
}

promotion.add(pdto);

} catch (Exception e) {

System.out.println(e.getMessage());
}
return promotion;
}

Now I am not able to configure the hbm files using 'addClass'. I would be thankful for those who tries to sort out my problem. this is something urgent.. Thanks in advance..
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the error you see? Why are you using the addClass() rather than a configuration file?
 
vijaya Yarlagadda
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am getting an error like "Error reading resource: com/sms/dto/studentRegistrationDTO.hbm.xml". I am unable to configure the hbm files in cfg file directly. Basically the two pojo classes are for two tables to be mapped.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

i am getting an error like "Error reading resource: com/sms/dto/studentRegistrationDTO.hbm.xml"

So probably your mapping file is not on your classpath (or if not in the folder it should be), or it is invalid. If you read the full exception message it should tell you which is is.


I am unable to configure the hbm files in cfg file directly

Why not? It is the better way of doing it (you don;t need a code change to add a new mapped class).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic