-->
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.  [ 6 posts ] 
Author Message
 Post subject: Classloading problem?
PostPosted: Wed May 19, 2004 6:41 am 
Newbie

Joined: Wed Jan 21, 2004 8:23 am
Posts: 18
I develop an application deployed as a .war file in JBoss 3.2.4RC2, using Hibernate 2.1.3 and MS SQL jdbc drivers towards MS SQL server 2000.

The hibernate mapping is done in a JBoss .sar file.

Previously I deployed all my source code inside of the .war file, but parts of the code is quite generic, and was refactored out into a separate project, and placed in a separate 'common' -jar file.

Then the problems started, first I tried to include the 'common' library inside of the .war file, but I got this exception:

ERROR [Configuration] Could not compile the mapping document
net.sf.hibernate.MappingException: persistent class [no.cronus.forit.hibernate.Users] not found
- I had now rewritten the hibernate mapping class to implement an interface in common.jar, so I figured that common.jar had to be in jboss classpath during statrup:
- Then I put the common.jar file into jboss\server\default\lib instead, and at least JBoss startup now went without errors being logged...


Then som info on my mapping (changed info is bold):
Code:
<hibernate-mapping>
<class name="no.cronus.forit.hibernate.Users" table="Users">
    <meta attribute="class-description" inherit="false">
       @hibernate.class table="Users"
    </meta>

    <!-- Added -->
    <meta attribute="implements" inherit="false">no.cronus.common.value.User</meta>
    <!-- /Added -->

    <id name="userId" type="java.lang.Integer" column="UserId" unsaved-value="0">
        <meta attribute="field-description">
           @hibernate.id generator-class="identity" type="java.lang.Integer" column="UserId" unsaved-value="0"
        </meta>
        <generator class="identity" />
    </id>
    <property name="userName" type="java.lang.String" column="UserName" not-null="true" unique="true" length="40">
        <meta attribute="field-description">
           @hibernate.property column="UserName" length="40" not-null="true"
        </meta>   
    </property>
    <property name="userPassword" type="java.lang.String" column="UserPassword" not-null="true" length="100">
        <meta attribute="field-description">
           @hibernate.property column="UserPassword" length="100" not-null="true"
        </meta>   
    </property>
    <property name="createdBy" type="java.lang.Integer" column="CreatedBy" length="10">
        <meta attribute="field-description">
           @hibernate.property column="CreatedBy" length="10"
        </meta>   
    </property>
    <property name="createdDate" type="java.sql.Timestamp" column="CreatedDate" length="23">
        <meta attribute="field-description">
           @hibernate.property column="CreatedDate" length="23"
        </meta>   
    </property>
    <property name="modifiedBy" type="java.lang.Integer" column="ModifiedBy" length="10">
        <meta attribute="field-description">
           @hibernate.property column="ModifiedBy" length="10"
        </meta>   
    </property>
    <property name="modifiedDate" type="java.sql.Timestamp" column="ModifiedDate" length="23">
        <meta attribute="field-description">
           @hibernate.property column="ModifiedDate" length="23"
        </meta>   
    </property>
    <property name="voided" type="java.lang.Short" column="Voided" length="5">
        <meta attribute="field-description">
           @hibernate.property column="Voided" length="5"
        </meta>   
    </property>
    <!-- associations -->
    <!-- bi-directional one-to-many association to UserAccess -->
    <set name="userAccess" lazy="true" inverse="true">
        <meta attribute="field-description">
           @hibernate.set lazy="true" inverse="true"
           @hibernate.collection-key column="UserId"
           @hibernate.collection-one-to-many class="no.cronus.forit.hibernate.UserAccess"
        </meta>
        <key><column name="UserId" /></key>
        <one-to-many class="no.cronus.forit.hibernate.UserAccess"/>
    </set>
</class>
</hibernate-mapping>


On the Java side I changed my hardcoded reference to the Hibernate mapping class, to one that is decided runtime in this method:
Code:
public static Class getHibernateMappingClass() {
  Class o = null;
  String className = Constants.getProperty("hibernate.mapping.class");
  if (className != null) {
    try {
      o = Class.forName(className);
    } catch (Exception e) {
      log.fatal("Could not load Hibernate mapping class.", e);
    }
  }
  return o;
}


Java code that access the database via Hibernate:
Code:
...
Session session = HibernateUtil.getSession();
/*
  Before:
  Criteria criteria = session.createCriteria(myapp.hib.Users.class);
*/
Criteria criteria = session.createCriteria(getHibernateMappingClass());
Object result;
if (mUserId != null) {
  criteria.add(Expression.eq("userId", mUserId));
  result = criteria.list()!=null && criteria.list().size()>0 ? criteria.list().get(0) : null;
} else {
  criteria.addOrder(orderAscending
    ? Order.asc(getOrderByColumn())
    : Order.desc(getOrderByColumn()));
  if (!includeVoidedRecords) criteria.add(Expression.or(Expression.eq("voided", new Short("0")), Expression.isNull("voided")));
  if (mUserName!=null) criteria.add(Expression.eq("userName", mUserName));
  result = criteria.list();
}
session.flush();
session.close();
return result;


Hibernate debug logging:
Code:
2004-05-19 12:36:02,450 DEBUG [net.sf.hibernate.impl.SessionFactoryObjectFactory] JNDI lookup: HibernateFactory
2004-05-19 12:36:02,450 DEBUG [net.sf.hibernate.impl.SessionFactoryObjectFactory] lookup: uid=d1801936fc9cd0b800fc9cd0cb350000
2004-05-19 12:36:02,450 DEBUG [net.sf.hibernate.impl.SessionImpl] opened session
2004-05-19 12:36:02,450 DEBUG [net.sf.hibernate.impl.SessionImpl] flushing session
2004-05-19 12:36:02,450 DEBUG [net.sf.hibernate.impl.SessionImpl] Flushing entities and processing referenced collections
2004-05-19 12:36:02,450 DEBUG [net.sf.hibernate.impl.SessionImpl] Processing unreferenced collections
2004-05-19 12:36:02,450 DEBUG [net.sf.hibernate.impl.SessionImpl] Scheduling collection removes/(re)creates/updates
2004-05-19 12:36:02,450 DEBUG [net.sf.hibernate.impl.SessionImpl] Flushed: 0 insertions, 0 updates, 0 deletions to 0 objects
2004-05-19 12:36:02,450 DEBUG [net.sf.hibernate.impl.SessionImpl] Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
2004-05-19 12:36:02,450 DEBUG [net.sf.hibernate.impl.SessionImpl] Dont need to execute flush
2004-05-19 12:36:02,450 DEBUG [net.sf.hibernate.impl.SessionImpl] flushing session
2004-05-19 12:36:02,450 DEBUG [net.sf.hibernate.impl.SessionImpl] Flushing entities and processing referenced collections
2004-05-19 12:36:02,450 DEBUG [net.sf.hibernate.impl.SessionImpl] Processing unreferenced collections
2004-05-19 12:36:02,450 DEBUG [net.sf.hibernate.impl.SessionImpl] Scheduling collection removes/(re)creates/updates
2004-05-19 12:36:02,450 DEBUG [net.sf.hibernate.impl.SessionImpl] Flushed: 0 insertions, 0 updates, 0 deletions to 0 objects
2004-05-19 12:36:02,450 DEBUG [net.sf.hibernate.impl.SessionImpl] Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
2004-05-19 12:36:02,450 DEBUG [net.sf.hibernate.impl.SessionImpl] executing flush
2004-05-19 12:36:02,450 DEBUG [net.sf.hibernate.impl.SessionImpl] post flush
2004-05-19 12:36:02,450 DEBUG [net.sf.hibernate.impl.SessionImpl] closing session
2004-05-19 12:36:21,108 DEBUG [net.sf.hibernate.impl.SessionFactoryObjectFactory] JNDI lookup: HibernateFactory
2004-05-19 12:36:21,108 DEBUG [net.sf.hibernate.impl.SessionFactoryObjectFactory] lookup: uid=d1801936fc9cd0b800fc9cd0cb350000
2004-05-19 12:36:21,108 DEBUG [net.sf.hibernate.impl.SessionImpl] opened session
2004-05-19 12:36:21,118 DEBUG [net.sf.hibernate.impl.SessionImpl] flushing session
2004-05-19 12:36:21,118 DEBUG [net.sf.hibernate.impl.SessionImpl] Flushing entities and processing referenced collections
2004-05-19 12:36:21,118 DEBUG [net.sf.hibernate.impl.SessionImpl] Processing unreferenced collections
2004-05-19 12:36:21,118 DEBUG [net.sf.hibernate.impl.SessionImpl] Scheduling collection removes/(re)creates/updates
2004-05-19 12:36:21,118 DEBUG [net.sf.hibernate.impl.SessionImpl] Flushed: 0 insertions, 0 updates, 0 deletions to 0 objects
2004-05-19 12:36:21,118 DEBUG [net.sf.hibernate.impl.SessionImpl] Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
2004-05-19 12:36:21,118 DEBUG [net.sf.hibernate.impl.SessionImpl] Dont need to execute flush
2004-05-19 12:36:21,118 DEBUG [net.sf.hibernate.impl.SessionImpl] flushing session
2004-05-19 12:36:21,118 DEBUG [net.sf.hibernate.impl.SessionImpl] Flushing entities and processing referenced collections
2004-05-19 12:36:21,128 DEBUG [net.sf.hibernate.impl.SessionImpl] Processing unreferenced collections
2004-05-19 12:36:21,128 DEBUG [net.sf.hibernate.impl.SessionImpl] Scheduling collection removes/(re)creates/updates
2004-05-19 12:36:21,128 DEBUG [net.sf.hibernate.impl.SessionImpl] Flushed: 0 insertions, 0 updates, 0 deletions to 0 objects
2004-05-19 12:36:21,128 DEBUG [net.sf.hibernate.impl.SessionImpl] Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
2004-05-19 12:36:21,128 DEBUG [net.sf.hibernate.impl.SessionImpl] executing flush
2004-05-19 12:36:21,128 DEBUG [net.sf.hibernate.impl.SessionImpl] post flush
2004-05-19 12:36:21,128 DEBUG [net.sf.hibernate.impl.SessionImpl] closing session



The database table contains these records:
Code:
...
7;oper;-54-7d-38-1c3-2b-3b-10-7e-1d731a4f-5e7e7f-1635-7e22;<NULL>;2004-04-23 18:59:21.733;<NULL>;<NULL>;0;
...



After changing to this more dynamic behaviour, Hibernate just decides that this record does not exist in the database, and does not return any records when queried!


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 19, 2004 10:29 am 
Newbie

Joined: Wed Jan 21, 2004 8:23 am
Posts: 18
After cleaning up some more in my classpath, and making sure I have only one copy of my common.jar, my application classes and of the hibernate mapping classes, I get this exception when executing the code shown over:

Code:
no.cronus.common.SystemException:Couldn't complete command execution
   at no.cronus.common.cmd.CommandBase.execute(CommandBase.java:79)
   at no.cronus.common.cmd.CommandBase.getFirstResult(CommandBase.java:113)
   at no.cronus.forit.action.ForitLoginAction.isLoginAllowed(ForitLoginAction.java:149)
   at no.cronus.common.struts.action.LoginAction.execute(LoginAction.java:84)
   at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
   at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
   at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
   at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
   at org.displaytag.filter.ResponseOverrideFilter.doFilter(ResponseOverrideFilter.java:87)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
   at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
   at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:66)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
   at org.jboss.web.tomcat.security.JBossSecurityMgrRealm.invoke(JBossSecurityMgrRealm.java:277)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
   at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
   at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:793)
   at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:702)
   at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:571)
   at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:644)
   at java.lang.Thread.run(Thread.java:534)
Caused by: java.lang.NullPointerException
   at net.sf.hibernate.expression.AbstractCriterion.getColumns(AbstractCriterion.java:26)
   at net.sf.hibernate.expression.Order.toSqlString(Order.java:37)
   at net.sf.hibernate.loader.CriteriaLoader.<init>(CriteriaLoader.java:80)
   at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:3586)
   at net.sf.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:238)
   at no.cronus.common.cmd.base.GetUsers.performExecute(GetUsers.java:54)
   at no.cronus.common.cmd.CommandBase.execute(CommandBase.java:64)
   ... 40 more
[/code]


Top
 Profile  
 
 Post subject: Closing in on the problem??
PostPosted: Wed May 19, 2004 12:23 pm 
Newbie

Joined: Wed Jan 21, 2004 8:23 am
Posts: 18
I have debugged my way into the Hibernate code, and this is where it fails: CriteriaLoader.class:
line 76++:

Code:
StringBuffer orderBy = new StringBuffer(30);
iter = criteria.iterateOrderings();
while ( iter.hasNext() ) {
  Order ord = (Order) iter.next();
  orderBy.append( ord.toSqlString( factory, criteria.getCriteriaClass(), getAlias() ) );
  if ( iter.hasNext() ) orderBy.append(", ");
}


ord.propertyName=null

Maybe a 'null' should be tested for, and better error descriptions be added here?


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 19, 2004 1:39 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Add it to JIRA with a simple offending testcase

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Jira
PostPosted: Fri May 21, 2004 4:06 am 
Newbie

Joined: Wed Jan 21, 2004 8:23 am
Posts: 18
I will, and the TestCase is this simple:

criteria.addOrder(Order.asc(null));


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 29, 2004 6:41 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I mean a minimal fully runnable testcase (hbm, domain model, Main class etc)

_________________
Emmanuel


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