-->
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: mapping documents in different direcyory than calling class
PostPosted: Wed Oct 19, 2005 3:45 pm 
Beginner
Beginner

Joined: Wed Oct 19, 2005 3:30 pm
Posts: 25
Id like to keep hibernate objects and mapping documents in a seperate directory from the class thats calling them. My application works fine and then I move all the .hbm.xml and hibernate classes to their own directory, change the .cfg.xml files to update this move and change the mapping files to reflect it as well and yet hibernate is still looking in the old directory (edu.asu.SFAO.Actions) rather than the new one (edu.asu.SFAO.Daos). A search through my entire project reveals that nowhere else is anything hardcoded with edu.asu.SFAO.Actions.Affiliate so its got to be coming from hibernate. What gives? Is there a way around keeping everything in the same directory?





Hibernate version:
hibernate-3.0.5

Full stack trace of any exception that occurs:
org.hibernate.MappingException: Unknown entity: edu.asu.SFAO.Actions.Affiliate
at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:569)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:62)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:621)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:614)
at edu.asu.SFAO.Actions.GenerateMainAction.authExecute(GenerateMainAction.java:44)
at edu.asu.SFAO.Actions.WebAuthAction.execute(WebAuthAction.java:68)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:307)
at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:385)
at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:748)
at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:678)
at org.apache.jk.common.SocketConnection.runIt(ChannelSocket.java:871)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:534)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 19, 2005 4:22 pm 
Expert
Expert

Joined: Wed Apr 06, 2005 5:03 pm
Posts: 273
Location: Salt Lake City, Utah, USA
There is no problem with mapping files being in different directories from the classes. That is how we have things set up. Just remember that if your cfg file has resource="X.hbm.xml" that it's going to look the file up as a resource, meaning it must be found relative to your classpath.

If you can't figure it out, post your files.

_________________
nathan


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 19, 2005 5:50 pm 
Beginner
Beginner

Joined: Wed Oct 19, 2005 3:30 pm
Posts: 25
<hibernate-configuration>


<session-factory>

<property name="dialect">org.hibernate.dialect.SQLServerDialect</property>
<property name="connection.url">jdbc:jtds:sqlserver://uuidbdev.uui.asu.edu:1433/SFAO</property>
<property name="connection.driver_class">net.sourceforge.jtds.jdbc.Driver</property>
<property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
<property name="use_outer_join">true</property>
<property name="cache.use_query_cache">true</property>
<property name="show_sql">true</property>
<property name="connection.username">*****</property>
<property name="connection.password">*****</property>
<property name="dbcp.autoCommit">false</property>
<property name="dbcp.minCount">2</property>
<property name="dbcp.maxCount">5</property>
<property name="dbcp.testOnBorrow">true</property>
<property name="dbcp.ValidationQuery">select 1</property>
<property name="dbcp.testWhileIdle">true</property>
<property name="dbcp.timeBetweenEvictionRunsMillis">5000</property>
<property name="dbcp.testOnBorrow">true</property>

<!-- Mapping files -->
<mapping resource="edu/asu/SFAO/Daos/Options.hbm.xml"/>
<mapping resource="edu/asu/SFAO/Daos/FlightHours.hbm.xml"/>
<mapping resource="edu/asu/SFAO/Daos/DegreePrograms.hbm.xml"/>
<mapping resource="edu/asu/SFAO/Daos/AgConcentrations.hbm.xml"/>
<mapping resource="edu/asu/SFAO/Daos/FlightSafetyCourses.hbm.xml"/>
<mapping resource="edu/asu/SFAO/Daos/Semesters.hbm.xml"/>
<mapping resource="edu/asu/SFAO/Daos/EastScholAp.hbm.xml"/>
<mapping resource="edu/asu/SFAO/Daos/Variables.hbm.xml"/>
</session-factory>

</hibernate-configuration>




<hibernate-mapping>

<class name="edu.asu.SFAO.Daos.Affiliate" table="OTHER_ID">
<cache usage="read-only"/>
<id name="id" column="IDENTIFICATION_NO">
<generator class="native"/>
</id>

<property name="affiliate">
<column name="AFFILIATE_ID"/>
</property>

</class>
</hibernate-mapping>




So all my hibernate classes and mapping files were in my Actions directory earlier and everything worked. I just created a directory under SFAO and called it Daos and put them all in there and then changed both of these files to point to Daos rather than Actions. However now I get that exception and its still looking for affiliate under Actions. What am I missing?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 19, 2005 5:54 pm 
Beginner
Beginner

Joined: Wed Oct 19, 2005 3:30 pm
Posts: 25
Oops, heres the other cfg file, the one that actually maps the Affiliate object

<hibernate-configuration>


<session-factory>
<property name="dialect">org.hibernate.dialect.SybaseDialect</property>
<property name="connection.url">jdbc:sybase:Tds:enterprise2.asu.edu:2500/AFFILIATE</property>
<property name="connection.driver_class">com.sybase.jdbc3.jdbc.SybDriver</property>
<property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
<property name="use_outer_join">true</property>
<property name="cache.use_query_cache">true</property>
<property name="show_sql">true</property>
<property name="connection.username">*****</property>
<property name="connection.password">*****</property>
<property name="dbcp.autoCommit">false</property>
<property name="dbcp.minCount">2</property>
<property name="dbcp.maxCount">5</property>
<property name="dbcp.testOnBorrow">true</property>
<property name="dbcp.ValidationQuery">select count(*) from other_id where identification_no = null</property>
<property name="dbcp.testWhileIdle">true</property>
<property name="dbcp.timeBetweenEvictionRunsMillis">15000</property>
<property name="dbcp.testOnBorrow">true</property>

<!-- Mapping files -->
<mapping resource="edu/asu/SFAO/Daos/Affiliate.hbm.xml"/>
<mapping resource="edu/asu/SFAO/Daos/Student.hbm.xml"/>
</session-factory>


</hibernate-configuration>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 19, 2005 6:29 pm 
Expert
Expert

Joined: Wed Apr 06, 2005 5:03 pm
Posts: 273
Location: Salt Lake City, Utah, USA
Ok, I'm guessing your classes are still in the Actions directory, and you just wanted to move your mapping files to the Daos directory. So what you probably have is a java class edu.asu.SFAO.Actions.Affiliate, and a mapping file that says
Code:
<class name="edu.asu.SFAO.Daos.Affiliate">

They need to match up. Change your mapping file back (Actions instead of Daos):
Code:
<class name="edu.asu.SFAO.Actions.Affiliate">

_________________
nathan


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 19, 2005 6:45 pm 
Beginner
Beginner

Joined: Wed Oct 19, 2005 3:30 pm
Posts: 25
No, Id like to, and have, moved both.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 19, 2005 6:54 pm 
Expert
Expert

Joined: Wed Apr 06, 2005 5:03 pm
Posts: 273
Location: Salt Lake City, Utah, USA
Ah, sorry, I misunderstood your post.

Looks like you are somehow passing edu.asu.SFAO.Actions.Affiliate class to the Session.get() method (from the stack trace: at edu.asu.SFAO.Actions.GenerateMainAction.authExecute(GenerateMainAction.java:44) ). Maybe it's a rebuild problem? You've got classes in the old Actions package still hanging around?

Post your code if you still can't figure it out.

_________________
nathan


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 19, 2005 7:00 pm 
Beginner
Beginner

Joined: Wed Oct 19, 2005 3:30 pm
Posts: 25
Exactly, except the odd thing is Im not passing that. Ive done a search through the entire project for that string and it doesnt exist. heres the code anyway. Heres the calling class

/*
* GenerateMainAction.java
*
* Created on September 01, 2004, 9:19 AM
*
* Struts default action which sets up the DAOs and Form and inserts tehm into
* the session
*/

package edu.asu.SFAO.Actions;

import javax.servlet.*;
import javax.servlet.http.*;
import org.apache.struts.action.*;
import edu.asu.SFAO.Forms.*;
import edu.asu.SFAO.Actions.*;
import edu.asu.SFAO.Helpers.*;
import edu.asu.SFAO.Daos.*;
import edu.asu.webauth.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.*;

public class GenerateMainAction extends WebAuthAction
{
private static Log log = LogFactory.getLog(HibernateUtil1.class);

public ActionForward authExecute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
{

HttpSession session = request.getSession();
ServletContext context = servlet.getServletContext();
StudentForm sform = new StudentForm();
Affiliate affiliate;
Student student;
//use the asurite to get the affiliateid from the affiliate hibernate object, pass it
//to the student hibernate object to recieve a student object
org.hibernate.Session sess1 = HibernateUtil1.currentSession();
try
{
affiliate = (Affiliate) sess1.get(Affiliate.class,(String)session.getAttribute("asuriteid"));
student = (Student) sess1.get(Student.class,affiliate.getAffiliate());
}catch (Throwable ex)
{
//if the access failed log the error and add it the action errors before
//cleaning up and returning failure
HibernateUtil1.closeSession();
session.setAttribute("student", sform);
log.error("Affiliate access failed.", ex);
return (mapping.findForward("globalerror"));
}
HibernateUtil1.closeSession();
//if we got this far we have our student so set their name and asuid into the session form
sform.setAffilLastName(student.getAffilLastName());
sform.setAffilFirstName(student.getAffilFirstName());
sform.setAffilMiddleName(student.getAffilMiddleName());
sform.setAsuId(student.getAsuId());

session.setAttribute("student", sform);
return (mapping.findForward("success"));

}
}



Thanks for the help thus far, btw.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 19, 2005 7:03 pm 
Beginner
Beginner

Joined: Wed Oct 19, 2005 3:30 pm
Posts: 25
Its the Affiliate.class , isnt it. .. damnit. I guess I never understood that declaration, just took it from the hibernate docs. How would I specify the new location?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 19, 2005 7:06 pm 
Expert
Expert

Joined: Wed Apr 06, 2005 5:03 pm
Posts: 273
Location: Salt Lake City, Utah, USA
check your import for Affiliate:

Code:
affiliate = (Affiliate) sess1.get(Affiliate.class,(String)session.getAttribute("asuriteid"));


I guarantee it's importing from Actions. You have a .class file for Affiliate in your Actions directory that you need to delete. That's why I suggested it might be a rebuild problem.

If you import Affiliate explicitly or do a clean rebuild, the problem will go away.

_________________
nathan


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 19, 2005 7:08 pm 
Beginner
Beginner

Joined: Wed Oct 19, 2005 3:30 pm
Posts: 25
Yeah I got it, I just needed to explicitly declare asu.edu.SFAO.Daos.Affiliate

Stupid mistake, guess I just needed someone to bounce it off of. Thanks for the help


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.