Hibernate sem properties!

pessoal,
devido a grande dificuldade de ajustes no classpath e tb no hibernate.properties que o pessoal encontra ao usar o hibernate, é possível usar a seguinte solução. (hard code).

AmigoDAO.java

public Connection getConexao() {
	try {
		Class.forName("org.gjt.mm.mysql.Driver");
		con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test");
		System.out.println("Conexao ok");
	}
	catch(ClassNotFoundException e.getMessage() ){

e.printStackTrace();
}
catch(SQLException e) {
e.printStackTrace();
}
return con;
}

onde o metodo openSession do objeto SessionFactory usa o metodo getConexao.

Session session = factory.openSession(getConexao());

isso e possivel, porem fica muito feio…

 Configuration configuration = new Configuration();

 Properties p = new Properties();       
 p.put("hibernate.connection.url","jdbc:mysql://....");
 p.put("o restante das propriedades...","xxx..")... 
 configuration.setProperties(p);

 configuration.configure();
 configuration.addClass(adicionando o bean.class)
 SessionFactory sessionFactory = configuration.buildSessionFactory();
            

Pde ser tambem atraves do hibernate.cfg.xml

[code]
<?xml version=‘1.0’ encoding=‘UTF-8’?>
<!DOCTYPE hibernate-configuration PUBLIC
“-//Hibernate/Hibernate Configuration DTD 2.0//EN”
http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd”>

<!-- DO NOT EDIT: This is a generated file that is synchronized -->
<!-- by MyEclipse Hibernate tool integration. -->
<hibernate-configuration>

&lt;session-factory&gt;
    &lt;!-- properties --&gt;
    &lt;property name=&quot;connection.username&quot;&gt;sa&lt;/property&gt;
    &lt;property name=&quot;show_sql&quot;&gt;true&lt;/property&gt;
    &lt;property name=&quot;connection.url&quot;&gt;jdbc&#58;jtds&#58;sqlserver&#58;//luizrossetti&#58;1433/Northwind&lt;/property&gt;
    &lt;property name=&quot;dialect&quot;&gt;net.sf.hibernate.dialect.SQLServerDialect&lt;/property&gt;
    &lt;property name=&quot;connection.password&quot;&gt;100314&lt;/property&gt;
    &lt;property name=&quot;connection.driver_class&quot;&gt;net.sourceforge.jtds.jdbc.Driver&lt;/property&gt;

    &lt;!-- mapping files --&gt;
    &lt;mapping resource=&quot;br/com/dts/dtswebnorthwind/beans/Categories.hbm.xml&quot;/&gt;

&lt;/session-factory&gt;

</hibernate-configuration>[/code]

Resolver um problema de ambiente (classpath, sistema operacional, etc) com codigo na aplicacao eh seeeeeeeeempre uma ma ideia. :wink: