tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrew Hughes <ahhug...@gmail.com>
Subject A little help with hibernate.cfg.xml and test datasources
Date Wed, 27 Apr 2011 04:00:05 GMT
Hi All,

Hopefully this is really simple, we're using hibernate and its configured
with a mixture of hibernate.cfg.xml and AnnotationConfiguration. But
hibernate can't locate the datasource I've created with OpenEJB, and it
always yields "javax.naming.NoInitialContextException: *Need to specify
class name in environment or system property*". Can anyone please help with
this?


I have tried in a test to create a datasource called "*myapp.portal.ds*"
with most of the param's fed in as system params (ref. Surefire System
Properties<http://maven.apache.org/plugins/maven-surefire-plugin/examples/system-properties.html>
)

@BeforeClass
public static void setUp() throws Exception {
final Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.openejb.client.LocalInitialContextFactory");
p.put("myapp.portal.ds", "new://Resource?type=DataSource");
p.put("myapp.portal.ds.JdbcDriver", SQLServerDriver.class.getName());
p.put("myapp.portal.ds.JdbcUrl",
System.getProperty("myappPortalDsJdbcUrl"));
p.put("myapp.portal.ds.UserName",
System.getProperty("myappPortalDsUserName"));
p.put("myapp.portal.ds.Password",
System.getProperty("myappPortalDsPassword"));
p.put("myapp.portal.ds.JtaManaged", "true");
context = new InitialContext(p);
}

The *hibernate.cfg.xm*l is as follows:

<hibernate-configuration>
    <session-factory name="myapp.portal.ds">
     <property
name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property>
        <property name="show_sql">true</property>
        <property
name="hibernate.connection.datasource">myapp.portal.ds</property>
<property
name="hibernate.query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactory</property>

<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>
 <!-- Annotated classes removed they don't need to be here -->
    </session-factory>
</hibernate-configuration>



The *code that creates the hibernate configration* is as follows (I know
this could be removed):

Configuration conf = new AnnotationConfiguration("hibernate.cfg.xml");
SessionFactory = *conf.buildSessionFactory();  // EPIC FAIL HERE EVERY TIME
:(*



The Exception that I am getting is here....

FATAL - Could not find datasource: myapp.portal.ds
javax.naming.NoInitialContextException: *Need to specify class name in
environment or system property*, or as an applet parameter, or in an
application resource file:  java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:247)
at
javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:284)
at javax.naming.InitialContext.lookup(InitialContext.java:351)
at
org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:52)
at
org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:124)
at
org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:56)
at
org.hibernate.cfg.SettingsFactory.createConnectionProvider(SettingsFactory.java:414)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:62)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2009)
at
org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1292)
at
org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:915)



Help+Advice+Sympathy would be most appreciated :)

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message