-->
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.  [ 11 posts ] 
Author Message
 Post subject: hibernate mapping file not found
PostPosted: Wed Dec 06, 2006 3:53 pm 
Newbie

Joined: Wed Jul 26, 2006 1:41 pm
Posts: 18
Hi,

When i deploy my struts+hibernate application on tomcat i get the following error:

**** Initilizing HibernatePlugIn for HRIS**********
Error while initializing hibernate: Resource: org/theclass/candidate/view/Candidate.hbm.xml not found


I have hibernate.cfg.xml under WEB-INF/classes & WEB-INF/src directory

hibernate.cfg.xml:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"

"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>

<session-factory>

<!-- Database connection settings -->
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/theclass_TheClassDB?autoReconnect=true</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">password</property>

<!-- SQL dialect -->
<!--<property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property> -->
<!-- <property name="dialect">org.hibernate.dialect.MySQLInnoDBDialect</property> -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>

<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>

<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>

<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">update</property>

<!-- Disable the second-level cache-->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>

<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>

<property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>

<mapping resource="org/theclass/candidate/view/Candidate.hbm.xml"/>

</session-factory>

</hibernate-configuration>

Here is HibernatePlugin.java:

package org.theclass.candidate.view;

import java.net.URL;
import javax.servlet.ServletException;
import javax.servlet.ServletContext;

import org.hibernate.HibernateException;
import org.hibernate.MappingException;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.ActionServlet;
import org.apache.struts.action.PlugIn;
import org.apache.struts.config.ModuleConfig;


public class HibernatePlugin implements PlugIn {


private String configFilePath = "/hibernate.cfg.xml";

public static final String SESSION_FACTORY_KEY
= SessionFactory.class.getName();

private SessionFactory factory = null;

public void destroy() {
try {
factory.close();
} catch (HibernateException e) {
//log.error("unable to close factory", e);
System.out.println("Unable to close Hibernate Session Factory: " + e.getMessage());
}
} //EOF destroy

public void init(ActionServlet servlet, ModuleConfig modConfig)
throws ServletException {
System.out.println("**** Initilizing HibernatePlugIn for HRIS**********");

ServletContext context = null;
Configuration config = null;
URL url = null;


try {

//ClassLoader finds the Hibernate.cfg.xml file

url = HibernatePlugin.class.getResource(configFilePath);
context = servlet.getServletContext();
config = (new Configuration()).configure(url);
factory = config.buildSessionFactory();


//Store Hibernate Factory object in Servlet Context
context.setAttribute(SESSION_FACTORY_KEY, factory);
System.out.println("Storing SessionFactory in context");


} catch (HibernateException e) {
System.out.println("Error while initializing hibernate: " + e.getMessage());
}

System.out.println("*************************************");

} //EOF init


public void setConfigFilePath(String configPath) {
if ((configPath == null) || (configPath.trim().length() == 0)) {
throw new IllegalArgumentException(
"configFilePath cannot be blank or null.");
}

System.out.println("Setting 'configFilePath' to '" + configPath + "'...");
configFilePath = configPath;
}

} //EOF HibernatePlugIn class

What could possible be wrong. Any help would be appreciated.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 07, 2006 2:03 am 
Newbie

Joined: Thu Dec 07, 2006 1:28 am
Posts: 4
where are you storing the candidate.hbm.xml?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 07, 2006 3:48 pm 
Newbie

Joined: Wed Jul 26, 2006 1:41 pm
Posts: 18
Thanks for taking a look at my post. I am storing the Candidate.hbm.xml in the directory WEB-INF/src/ org/theclass/candidate/view
My POJO Candidate.java is also under the same directory.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 07, 2006 6:53 pm 
Newbie

Joined: Thu Dec 07, 2006 1:28 am
Posts: 4
but your config file is looking for candidate.hbm.xml in :

Quote:
<mapping resource="org/theclass/candidate/view/Candidate.hbm.xml"/>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 07, 2006 8:58 pm 
Newbie

Joined: Mon Jul 10, 2006 5:52 pm
Posts: 6
Location: Bay Area, California, USA
Previous poster is correct. I also colocate the mapping file with source file as well, but have my ant script copy over hbm.xml files as well.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 07, 2006 9:58 pm 
Newbie

Joined: Wed Jul 26, 2006 1:41 pm
Posts: 18
Thank you ramvem & hibernate_pro for ur response but I guess whats in config file is correct. Is there any mistake? Can you please explain in detail what can be done.

I dont use Ant. I compile the .java files using javac & copy paste the class files into the approriate directory.


Top
 Profile  
 
 Post subject: Try putting the Candidate.hbm.xml file in classes
PostPosted: Mon Dec 11, 2006 1:13 pm 
Newbie

Joined: Mon Dec 11, 2006 10:43 am
Posts: 3
Put your Candidate.hbm.xml file in the same folder as the .class file. Putting it with the source files (.java) will not allow Hibernate to find the file. Hibernate uses the classpath. Also, ensure that the files are named with the correct case. i.e. make sure the file is Candidate.hbm.xml and not candidate.hbm.xml.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 12, 2006 3:38 pm 
Newbie

Joined: Wed Jul 26, 2006 1:41 pm
Posts: 18
Thank you very much. Now i dont get that error.
But i get a different error now.

"Error while initializing hibernate: Could not find a getter for id in class org.theclass.candidate.view.Candidate"

I have getter & setter methods.
Here is my POJO class
package org.theclass.candidate.view;

public class Candidate
{

protected Integer candidateid;
protected String firstname;
protected String middlename;
protected String lastname;
protected String addrsline1;
protected String addrsline2;
protected String city;
protected String state;
protected Integer zipcode;
protected String homephno;
protected String cellphno;
protected String email;
protected String skills;
protected String status;
protected String teaminterest;
protected String jobpositions;
protected String experience;
protected int [] selectedJobCategories;

public int[] getSelectedJobCategories()
{
return selectedJobCategories;
}
public void setSelectedJobCategories(int[] is)
{
selectedJobCategories = is;
}


public void setCandidateid(Integer candidateid)
{
this.candidateid = candidateid;
}

public Integer getCandidateid()
{

return candidateid;
}
public String getFirstname()
{

return firstname;
}

public void setFirstname(String firstname)
{

this.firstname = firstname;
}
public String getMiddlename()
{

return middlename;
}

public void setMiddlename(String middlename)
{

this.middlename = middlename;
}

public String getLastname()
{

return lastname;
}

public void setLastname(String lastname)
{

this.lastname = lastname;
}
public String getAddrsline1 ()
{

return addrsline1;
}

public void setAddrsline1(String addrsline1)
{

this.addrsline1 = addrsline1;
}
public String getAddrsline2 ()
{

return addrsline2;
}

public void setAddrsline2(String addrsline2)
{

this.addrsline2 = addrsline2;
}
public String getCity ()
{

return city;
}
public void setCity(String city)
{

this.city = city;
}
public String getState ()
{

return state;
}
public void setState(String state)
{

this.state = state;
}
public Integer getZipcode ()
{

return zipcode;
}
public void setZipcode(Integer zipcode)
{

this.zipcode = zipcode;
}
public String getEmail ()
{

return email;
}
public void setEmail(String email)
{

this.email = email;
}
public String getHomephno ()
{

return homephno;
}
public void setHomephno(String homephno)
{

this.homephno = homephno;
}
public String getCellphno ()
{

return cellphno;
}
public void setCellphno(String cellphno)
{

this.cellphno = cellphno;
}
public String getStatus ()
{

return status;
}
public void setStatus(String status)
{

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

this.experience = experience;
}

public String getExperience ()
{

return experience;
}

public String getSkills()
{

return skills;
}

public void setSkills(String skills)
{

this.skills = skills;
}


public String getJobpositions()
{

return jobpositions;
}

public void setJobpositions(String jobpositions)
{

this.jobpositions= jobpositions;
}

public String getTeaminterest()
{

return teaminterest;
}

public void setTeaminterest(String teaminterest)
{

this.teaminterest = teaminterest;
}

}

Any thing wrong in the above program.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 12, 2006 11:11 pm 
Newbie

Joined: Mon Jul 10, 2006 5:52 pm
Posts: 6
Location: Bay Area, California, USA
Can you check the type of the id as defined in Candidate.hbm.xml and make sure its "int". Default is long so this could be a signature mismatch.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 13, 2006 4:19 pm 
Newbie

Joined: Wed Jul 26, 2006 1:41 pm
Posts: 18
Hi,

I fixed the error.I made a mistake in the Candidate.hbm.xml
There was a mismatch in the id name.

I initially had:

<id name="id" column="candidateid" type="java.lang.Long">
<generator class="native"/>
</id>

later corrected it to:

<id name="candidateid" column="candidateid" type="java.lang.Long">
<generator class="native"/>
</id>

My POJO had id identifier as "candidateid" which is Long.

Thank you very much for all the help so far.


Top
 Profile  
 
 Post subject: Help me with this GenericJDBCException!!!
PostPosted: Thu Dec 14, 2006 5:00 pm 
Newbie

Joined: Wed Jul 26, 2006 1:41 pm
Posts: 18
I am trying to insert data in to DB.But i get the following exception on my tomcat
" org.hibernate.exception.GenericJDBCException: could not insert : [org.theclass.candidate.view.Candidate]"
I looked exhaustively in the forum,but could not find any help.

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

<hibernate-mapping>

<class name="org.theclass.candidate.view.Candidate" table="candidate">
<id name="candidateid" column="candidateid" type="java.lang.Integer">
<generator class="native"/>
</id>
<property name="firstname" column="firstname" length="30" type="java.lang.String"/>
<property name="middlename" column="middlename" length="30" type="java.lang.String"/>
<property name="lastname" column="lastname" length="30" type="java.lang.String"/>
<property name="addrsline1" column="addrsLine1" length="30" type="java.lang.String"/>
<property name="addrsline2" column="addrsLine2" length="30" type="java.lang.String"/>
<property name="city" column="city" length="30" type="java.lang.String"/>
<property name="state" column="state" length="2" type="java.lang.String"/>
<property name="zipcode" column="zipcode" length="30" type="java.lang.Integer"/>
<property name="homephno" column="homePhNo" length="30" type="java.lang.String"/>
<property name="cellphno" column="cellPhNo" length="30" type="java.lang.String"/>
<property name="email" column="email" length="30" type="java.lang.String"/>
<property name="skills" column="skills" length="30" type="java.lang.String"/>
<property name="status" column="status" length="30" type="java.lang.String"/>
<property name="teaminterest" column="teamInterest" length="30" type="java.lang.String"/>
<property name="jobpositions" column="jobPositions" length="30" type="java.lang.String"/>
<property name="experience" column="experience" length="30" type="java.lang.String"/>

</class>
</hibernate-mapping>

Config file:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"

"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>

<session-factory>

<!-- Database connection settings -->
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/theclass_TheClassDB?autoReconnect=true</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">***</property>

<!-- SQL dialect -->
<!--<property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property> -->
<!-- <property name="dialect">org.hibernate.dialect.MySQLInnoDBDialect</property> -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>

<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>

<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>

<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">update</property>

<!-- Disable the second-level cache-->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>

<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>

<property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>

<mapping resource="org/theclass/candidate/view/Candidate.hbm.xml"/>

</session-factory>

</hibernate-configuration>

I use Mysql 4.1,hibernate 3.1.Can some one help me?
[/quote][/code]


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