JBoss TS with PostgreSQL without JNDI
laliluna Mar 28, 2008 9:45 AMHello,
I was actually trying to integrate Hibernate, TreeCache and JBoss TS in a standalone application.
I found the blog post http://blogs.jboss.com/blog/gzamarreno/?permalink=No_Need_To_Hacer_De_Celestina_Any_More.txt
and evaluated the example at http://wiki.jboss.org/wiki/Wiki.jsp?page=JBossCacheHibernateTransactionsStandaloneExample.
This example application used allready JBossTS with TreeCache but used a plain JDBCTransaction in Hibernate.
The missing things are only a special kind of JTSTransaction and JtsTransaction Manager to allow Hibernate integration with JTS. I developed them on the base of the JTA implementations and just used JTS specific code where required - only a couple of changes. But this is not yet working as the JbossTs transaction was not bound to the JDBC connection.
The problem, I am having know is a pure JBossTS problem. I would like to use PostgreSQL as database but I do not manage to bind the driver to the JBoss Ts transaction. The Ts commit does not commit the database.
I simplified the code and have a pure JDBC snippet now. It is not working, the connection is always Null.
The programmers guide of JbossTs 4.2.3 is not very clear on DynamicClass and does not perfectly correspond to the JBoss TS source.
Here a couple of questions:
Can I integrate a simple JDBC driver?
Do I need a dynamicClass implementation, if my database is not supported out of the box?
Do I have to use a XADatasource or is this only required, if I really want to go for a distributed transaction?
Do I have to use JNDI for the JDBC driver?
Can somebody give me a tip on how to make my code snipped work?
Best Regards
Sebastian Hennebrueder
public static void main(String[] args) { System.setProperty("jdbc.drivers", "org.postgresql.Driver"); Properties dbProps = new Properties(); dbProps.setProperty(TransactionalDriver.userName, "postgres"); dbProps.setProperty(TransactionalDriver.password, "p"); String url = "jdbc:postgresql://localhost:5432/learninghibernate"; TransactionalDriver arjunaJDBC2Driver = new TransactionalDriver(); try { Connection connection = arjunaJDBC2Driver .connect(url, dbProps); Random r = new Random(); int id = r.nextInt(); System.out.println("conn="+connection); javax.transaction.UserTransaction ut = UserTransaction.userTransaction(); try { ut.begin(); connection .prepareStatement("insert into plant (id, name, growing) values (" + id + ",'abc',true)").execute(); ut.commit(); } catch (NotSupportedException e) { e.printStackTrace(); } catch (SystemException e) { e.printStackTrace(); } catch (RollbackException e) { e.printStackTrace(); } catch (HeuristicMixedException e) { e.printStackTrace(); } catch (HeuristicRollbackException e) { e.printStackTrace(); } } catch (SQLException e) { e.printStackTrace(); } }