What are the steps to install my Hibernate Application on JBoss? It would have been nice if there is a FAQ about the steps involved.
I have these files :
* HibernateSession.java in com.mti.main package in src folder
* SchGroup.java in com.mti.sch.model package in src folder
* SchGroup.hbm.xml in com.mti.sch.model package in src folder
* hibernate.cfg.xml in src folder
* log4j.properties in src folder
My hibernate.cfg.xml is :
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">
<hibernate-configuration>
<session-factory name="java:/hibernate/HibernateFactory">
<property name="hibernate.connection.datasource">java:/SchDB</property>
<property name="hibernate.transaction.factory_class">net.sf.hibernate.transaction.JTATransactionFactory</property>
<property name="hibernate.transaction.manager_lookup_class">net.sf.hibernate.transaction.JBossTransactionManagerLookup</property>
<property name="hibernate.dialect">net.sf.hibernate.dialect.SQLServerDialect</property>
<property name="hibernate.query.substitutions">true 1, false 0, yes 'Y', no 'N'</property>
<mapping resource="com\mti\sch\model\SchGroup.hbm.xml"/>
</session-factory>
</hibernate-configuration>
My HibernateSession.java is :
public class HibernateSession {
private static final ThreadLocal threadSession = new ThreadLocal();
private static final ThreadLocal threadTransaction = new ThreadLocal();
static {
try {
Configuration cfg = new Configuration().configure();
cfg.buildSessionFactory();
} catch ( Throwable th ) {
System.out.println( "HibernateSession: Static Initializer Block failed." );
th.printStackTrace( System.out );
throw new ExceptionInInitializerError( th );
}
}
public static SessionFactory getSessionFactory() {
SessionFactory sessions = null;
try {
Context ctx = new InitialContext();
String jndiName = "java:/hibernate/HibernateFactory";
sessions = (SessionFactory)ctx.lookup( jndiName );
} catch ( NamingException nex ) {
System.out.println( "HibernateSession: Lookup failed" );
}
return sessions;
}
public static Session getSession() {
Session s = (Session)threadSession.get();
// Open a new Session, if this thread has none yet
try {
if (s == null) {
System.out.println( "HibernateSession: Opening new Session for this thread." );
s = getSessionFactory().openSession();
threadSession.set(s);
}
} catch ( HibernateException hex ) {
hex.printStackTrace();
}
return s;
}
public static void closeSession() {
try {
Session s = (Session)threadSession.get();
threadSession.set( null );
if ( s != null && s.isOpen() ) {
System.out.println( "HibernateSession: Closing Session of this thread." );
s.close();
}
} catch ( HibernateException hex ) {
hex.printStackTrace();
}
}
public static void beginTransaction() {
Transaction tx = (Transaction)threadTransaction.get();
try {
if ( tx == null ) {
System.out.println( "Starting new database transaction in this thread." );
tx = getSession().beginTransaction();
threadTransaction.set( tx );
}
} catch ( HibernateException hex ) {
hex.printStackTrace();
}
}
public static void rollbackTransaction() throws InfrastructureException {
Transaction tx = (Transaction)threadTransaction.get();
try {
threadTransaction.set( null );
if ( tx != null && !tx.wasCommitted() && !tx.wasRolledBack() ) {
System.out.println( "Trying to rollback database transaction of this thread." );
tx.rollback();
}
} catch ( HibernateException hex ) {
hex.printStackTrace();
} finally {
closeSession();
}
}
public static void commitTransaction() throws InfrastructureException {
Transaction tx = (Transaction)threadTransaction.get();
try {
if ( tx != null && !tx.wasCommitted() && !tx.wasRolledBack() )
System.out.println( "Committing database transaction of this thread." );
tx.commit();
threadTransaction.set(null);
} catch ( HibernateException hex ) {
hex.printStackTrace();
rollbackTransaction();
}
}
I created a Sch.jar file which has these files :
hibernate.cfg.xml
log4j.properties
meta-inf\Manifest.mf
com\mti\main\HibernateSession.class
com\mti\sch\model\SchGroup.class
com\mti\sch\model\SchGroup.hbm.xml
I have created mssql-ds.xml in {JBOSS_HOME}\server\default\deploy folder:
<?xml version="1.0" encoding="UTF-8"?>
<datasources>
<local-tx-datasource>
<jndi-name>SchDB</jndi-name>
<connection-url>jdbc:microsoft:sqlserver://CERD_DEV_DBS:1433;DatabaseName=wf_dev_Sched</connection-url>
<driver-class>com.microsoft.jdbc.sqlserver.SQLServerDriver</driver-class>
<user-name>sa</user-name>
<password></password>
</local-tx-datasource>
</datasources>
In {JBOSS_HOME}\server\default\lib folder I copied the hibernate Jar files and the MS SQLServer JDBC Driver jar files.
when i run the server (default) I can see in the sever.log file that the datasource is now available:
2004-11-09 17:34:59,150 INFO [org.jboss.resource.connectionmanager.RARDeployment] Started jboss.jca:service=ManagedConnectionFactory,name=SchDB
2004-11-09 17:34:59,150 INFO [org.jboss.resource.connectionmanager.JBossManagedConnectionPool] Started jboss.jca:service=ManagedConnectionPool,name=SchDB
2004-11-09 17:35:01,369 INFO [org.jboss.resource.adapter.jdbc.local.LocalManagedConnectionFactory.SchDB] Bound connection factory for resource adapter for ConnectionManager 'jboss.jca:service=LocalTxCM,name=SchDB to JNDI name 'java:/SchDB'
2004-11-09 17:35:01,369 INFO [org.jboss.resource.connectionmanager.TxConnectionManager] Started jboss.jca:service=LocalTxCM,name=SchDB
Now I created a folder "Rizwan" in {JBOSS_HOME}\server\default\deploy folder. Inside this folder I created "WEB-INF" folder inside which I created "classes" folder and "lib" folder.
Then in the lib folder I copied the Sch.jar file. It was successful :
2004-11-09 17:40:33,791 INFO [org.jboss.deployment.MainDeployer] Starting deployment of package: file:/C:/DevPrograms/jboss-3.2.3/server/default/deploy/Rizwan/WEB-INF/lib/Sch.jar
2004-11-09 17:40:33,791 INFO [org.jboss.deployment.MainDeployer] Deployed package: file:/C:/DevPrograms/jboss-3.2.3/server/default/deploy/Rizwan/WEB-INF/lib/Sch.jar
Now I created an index.jsp file in "Rizwan" folder which is an empty html page.
2004-11-09 17:43:08,791 INFO [org.jboss.deployment.MainDeployer] Starting deployment of package: file:/C:/DevPrograms/jboss-3.2.3/server/default/deploy/Rizwan/index.jsp
2004-11-09 17:43:08,791 WARN [org.jboss.deployment.JARDeployer] Failed to add deployable jar: file:/C:/DevPrograms/jboss-3.2.3/server/default/tmp/deploy/tmp56737index.jsp
java.util.zip.ZipException: error in opening zip file
at java.util.zip.ZipFile.open(Native Method)
at java.util.zip.ZipFile.<init>(ZipFile.java:112)
at java.util.jar.JarFile.<init>(JarFile.java:127)
at java.util.jar.JarFile.<init>(JarFile.java:65)
at org.jboss.deployment.SubDeployerSupport.processNestedDeployments(SubDeployerSupport.java:245)
at org.jboss.deployment.SubDeployerSupport.init(SubDeployerSupport.java:143)
at org.jboss.deployment.MainDeployer.init(MainDeployer.java:696)
at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:632)
at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:605)
at sun.reflect.GeneratedMethodAccessor20.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke(ReflectedMBeanDispatcher.java:284)
at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:546)
at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:177)
at $Proxy6.deploy(Unknown Source)
at org.jboss.deployment.scanner.URLDeploymentScanner.deploy(URLDeploymentScanner.java:302)
at org.jboss.deployment.scanner.URLDeploymentScanner.scan(URLDeploymentScanner.java:476)
at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.doScan(AbstractDeploymentScanner.java:201)
at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.loop(AbstractDeploymentScanner.java:212)
at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.run(AbstractDeploymentScanner.java:191)
2004-11-09 17:43:08,806 INFO [org.jboss.deployment.MainDeployer] Deployed package: file:/C:/DevPrograms/jboss-3.2.3/server/default/deploy/Rizwan/index.jsp
Any reason why it is happening? Thanks
|