I've been trying to get hibernate to work for the past week and a half but have been unsuccessful and now am baffled by the results. If anyone has a bit of time could you please try and help me resolve these problems?
Code:
2006-02-28 10:57:23,467 1997412 DEBUG [org.hibernate.persister.entity.AbstractEntityPersister.logStaticSQL(AbstractEntityPersister.java:2454)] Delete 0: delete from db2.dbo.SclType where SclTypeCode=?
2006-02-28 10:57:23,497 1997442 ERROR [com.util.HibernateUtil.<clinit>(Unknown Source)] Initial SessionFactory creation failed.java.lang.ClassCastException
2006-02-28 10:57:23,537 1997482 ERROR [org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:307)] Dispatch[/showAnnualExamDetail] to method showExamDetail returned an exception
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:280)
at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:216)
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:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:672)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:463)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:398)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:301)
at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1069)
at org.apache.struts.tiles.TilesRequestProcessor.doForward(TilesRequestProcessor.java:274)
at org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:455)
at org.apache.struts.tiles.TilesRequestProcessor.processForwardConfig(TilesRequestProcessor.java:320)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:279)
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:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
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.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:39)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:153)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:59)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.jboss.web.tomcat.tc5.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:138)
at org.apache.catalina.authenticator.SingleSignOn.invoke(SingleSignOn.java:365)
at org.apache.catalina.valves.FastCommonAccessLogValve.invoke(FastCommonAccessLogValve.java:481)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
at java.lang.Thread.run(Thread.java:534)
Caused by: java.lang.ExceptionInInitializerError
at com..util.HibernateUtil.<clinit>(Unknown Source)
at com.delegate.hbm.HibAnnualExamDel.getAnnualExam(Unknown Source)
at coml.action.AdminExamAction.showExamDetail(Unknown Source)
... 49 more
Caused by: java.lang.ClassCastException
at org.hibernate.tuple.PropertyFactory.buildVersionProperty(PropertyFactory.java:83)
at org.hibernate.tuple.EntityMetamodel.<init>(EntityMetamodel.java:157)
at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:412)
at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:108)
at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:55)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:215)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1176)
... 52 more
The tools are:
AServer: JBoss-4.0.2
Hibernate: Hibernate3
DB Server: SQLServer7.0
JDBCDriver: net.sourceforge.jtds.jdbcx.JtdsDataSource
I've applied the info in the forums to reverse eng. the database schemas.
Code:
...
<hbm2java
jdk5="false"
ejb3="false"/>
...
This results in:
db1: 32 .hbm.xml & 39 .java files
db2: 195 .hbm.xml & 315 .java files
I've used the HibernateUtil example class to configure hibernate:
Code:
public class HibernateUtil {
private static final SessionFactory db1Factory, db2Factory;
static {
try {
// Create the SessionFactory from hibernate.cfg.xml
db1Factory = new Configuration().configure("db1.cfg.xml").buildSessionFactory();
db2Factory = new Configuration().configure("db2.cfg.xml").buildSessionFactory();
} catch (Throwable ex) {
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getDb1Factory() {
return db1Factory;
}
public static SessionFactory getDb2Factory() {
return db2Factory;
}
}
Viewing the output generated by hibernate it appears that it follows in order the mappings listed in the *.cfg.xml file.
The last one listed successfully looks to be:
Code:
<mapping resource="com/model/hbm/db2/SclType.hbm.xml" />
The next one is:
Code:
<mapping resource="com/model/hbm/db2/Site1.hbm.xml" />
Here are the two files:
SclType.hbm.xml
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Feb 22, 2006 12:53:08 PM by Hibernate Tools 3.1.0.beta4 -->
<hibernate-mapping>
<class name="com.model.hbm.db2.SclType" table="SclType" schema="dbo" catalog="Db2">
<id name="sclTypeCode" type="string">
<column name="SclTypeCode" length="3" />
<generator class="assigned" />
</id>
<property name="sclTypeName" type="string">
<column name="SclTypeName" length="64" not-null="true" />
</property>
<set name="tsts" inverse="true">
<key>
<column name="SclTypeCode" length="3" not-null="true" />
</key>
<one-to-many class="com.model.hbm.db2.Tst" />
</set>
<set name="scls" inverse="true">
<key>
<column name="SclTypeCode" length="3" not-null="true" />
</key>
<one-to-many class="com.model.hbm.db2.Scl" />
</set>
</class>
</hibernate-mapping>
and:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Feb 22, 2006 12:53:08 PM by Hibernate Tools 3.1.0.beta4 -->
<hibernate-mapping>
<class name="com.model.hbm.db2.Site1" table="Site1" schema="dbo" catalog="db2">
<id name="Id" type="int">
<column name="ID" />
<generator class="assigned" />
</id>
<many-to-one name="locByBillToLocI1d" class="com.model.hbm.db2.Loc" fetch="select">
<column name="BillToLocID" not-null="true" />
</many-to-one>
<many-to-one name="locBySLocId" class="com.model.hbm.db2.Loc" fetch="select">
<column name="SLocID" />
</many-to-one>
<property name="compNme" type="string">
<column name="CompNme" length="128" not-null="true" />
</property>
<property name="fs" type="string">
<column name="Fs" length="128" />
</property>
<property name="onAcctBal" type="double">
<column name="OnAcctBal" scale="4" />
</property>
<property name="fSC" type="string">
<column name="FSC" length="8" not-null="true" unique="true" />
</property>
<property name="ipq4" type="short">
<column name="IPQ4" not-null="true" />
</property>
<property name="expiration" type="timestamp">
<column name="Expiration" length="16" />
</property>
<!--property name="noPublic" type="java.lang.Character"-->
<!--column name="NoPublic" length="1" /-->
<!--/property-->
<set name="sCSLists" inverse="true">
<key>
<column name="ID" not-null="true" />
</key>
<one-to-many class="com.model.hbm.SCSList" />
</set>
<set name="sTlists" inverse="true">
<key>
<column name="ID" not-null="true" />
</key>
<one-to-many class="com.model.hbm.db2.STlist" />
</set>
<set name="sOLists" inverse="true">
<key>
<column name="ID" not-null="true" />
</key>
<one-to-many class="com.model.hbm.db2.SOList" />
</set>
<set name="sCLists" inverse="true">
<key>
<column name="ID" not-null="true" />
</key>
<one-to-many class="com.model.hbm.db2.SCList" />
</set>
<set name="sPLists" inverse="true">
<key>
<column name="ID" not-null="true" />
</key>
<one-to-many class="com.model.hbm.db2.SPList" />
</set>
<set name="sTPLists" inverse="true">
<key>
<column name="ID" not-null="true" />
</key>
<one-to-many class="com.model.hbm.db2.STPList" />
</set>
</class>
</hibernate-mapping>
With the size of the output and my newness to hibernate I'm really not sure where to begin, what to look for and how to fix it?
Any help is greatly appreciated!
Graham