-->
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.  [ 4 posts ] 
Author Message
 Post subject: Putting HelloWorld on JBoss
PostPosted: Wed Sep 15, 2004 1:06 pm 
Beginner
Beginner

Joined: Mon Sep 06, 2004 9:36 am
Posts: 35
Hi all,

I am trying to follow the Hello World example in the book. My aim is to have a Global Hibernate running on JBoss whose job is to create a SessionFactory.

I created an ODBC connection which is connecting to my MS SQL Server database which already has table MESSAGES with concerned columns. Then in JBoss's odbc-ds.xml I add this entry under <datasources> </datasources>.

<local-tx-datasource>
<jndi-name>HTestDS</jndi-name>
<connection-url>jdbc:odbc:HTest</connection-url>
<driver-class>sun.jdbc.odbc.JdbcOdbcDriver</driver-class>
<user-name>sa</user-name>
<password></password>
</local-tx-datasource>

Now I created a POJO Message.java

package hello;

import java.io.Serializable;

public class Message implements Serializable {
private Long id;
private String text;
private Message nextMessage;

public Message() {}
public Message(String text) {
this.text = text;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public Message getNextMessage() {
return nextMessage;
}
public void setNextMessage(Message nextMessage) {
this.nextMessage = nextMessage;
}
}

Then I created Message.hbm.xml

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="hello.Message" table="MESSAGES">
<id name="id" column="MESSAGE_ID">
<generator class="increment"/>
</id>
<property name="text" column="MESSAGE_TEXT"/>
<many-to-one
name="nextMessage"
cascade="all"
column="NEXT_MESSAGE_ID"/>
</class>
</hibernate-mapping>

Then I created hibernate.cfg.xml

<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">

<hibernate-configuration>
<!-- Bound the SessionFactory to JNDI -->
<session-factory name="java:/hibernate/HibernateFactory">
<property name="show_sql">true</property>
<property name="connection.datasource">
java:/comp/env/jdbc/HTestDS<
/property>
<property name="dialect">
net.sf.hibernate.dialect.SQLServerDialect
</property>
<propert name="transaction.mamager_lookup_class">
net.sf.hibernate.transaction.JBossTransactionManagerLookup
</property>

<!-- Hello mapping files. -->
<mapping resource="hello/Message.hbm.xml"/>
</session-factory>
</hibernate-configuration>


Finally I created HibernateGlobal.java in package global.

package global;

import net.sf.hibernate.cfg.Configuration;
import net.sf.hibernate.SessionFactory;
import net.sf.hibernate.HibernateException;

public class HibernateGlobal {
private String configFilePath = "/hibernate.cfg.xml";
private SessionFactory factory = null;

public HibernateGlobal() {
Configuration configuration = null;
try {
factory = new Configuration()
.configure(configFilePath)
.buildSessionFactory();
} catch (Throwable t) {
System.out.println("Exception while initializing Hibernate.");
t.printStackTrace();
}
}
public SessionFactory getFactory() {
return factory;
}
}


Now what steps I should take so that HibernateGlobal is installed successfully on JBoss and available for other *.java to access? Please give an input.

Thanks


For example I have written this MessageManipulation.java

package hello;

import global.HibernateGlobal;
import net.sf.hibernate.Session;
import net.sf.hibernate.Transaction;

public class MessageManipulation {
public static void addMessage(String messageText) throws Exception {
HibernateGlobal hg = new HibernateGlobal();
Session session = hg.openSession();
Transaction tx = session.beginTransaction();
Message message = new Message(messageText);
session.save(message);
tx.commit();
session.close();
}
}


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 15, 2004 1:16 pm 
Beginner
Beginner

Joined: Mon Sep 06, 2004 9:36 am
Posts: 35
I forget to mention that i already copied these required Hibernate jar files to JBoss's lib folder:

cglib.jar
commons-collections.jar
commons-lang.jar
commons-logging.jar
dom4j.jar
hibernate2.jar
jcs.jar


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 17, 2004 12:19 pm 
Beginner
Beginner

Joined: Mon Sep 06, 2004 9:36 am
Posts: 35
would anybody be kind enough to give me a reply please?
(there you go showing my canadians roots...)


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 19, 2004 5:54 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
http://www.hibernate.org/?cmd=srchdoc&q=jboss

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


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