Hah, embarrassing.  Thanks very much, Alex.  Glad it was something dumb and
not something complicaeted, though!

On 23 July 2012 09:10, Alex Kotchnev <akoch...@gmail.com> wrote:

> It seems that you might be setting the wrong hibernate configuration
> property - at least this thread (
>
> http://stackoverflow.com/questions/5303671/configure-hibernate-to-connect-to-database-via-jndi-datasource
> )
> on stack overflow indicates that the datasource property is
> "hibernate.connection.datasource" and not "connection.datasource" .
>
> The reason your migration works is that you manually look up the
> datasource.
>
> Cheers,
>
> Alex K
>
>
>
> On Fri, Jul 20, 2012 at 4:17 PM, Michael Prescott <
> michael.r.presc...@gmail.com> wrote:
>
> > The problem goes away if I provide a hibernate.cfg.xml file with all the
> > database connection properties, and set
> > HibernateSymbols.DEFAULT_CONFIGURATION to true.
> >
> > So I suppose my question is:
> >
> > What do I need to do to get rid of the hibernate.cfg.xml file?  I need to
> > have my application use a data source whose name is itself specified by
> the
> > container.  I can inject the name just fine, but my HibConfig class
> doesn't
> > seem to be cutting the mustard.
> >
> > Michael
> >
> > On 20 July 2012 15:19, Michael Prescott <michael.r.presc...@gmail.com
> > >wrote:
> >
> > > I'm having trouble getting a connection through tapestry-hibernate.
>  Any
> > > help would be appreciated!  I imagine I'm not seeing some small thing
> > I've
> > > overlooked.
> > >
> > > I'm configuring the hibernate connection in code, to use a DataSource
> > > provided by the servlet container.
> > >
> > > The data source is available - I can tell, because I'm using it in my
> > > tapestry module to run Flyway database migration scripts, which do
> modify
> > > the database - but any tapestry-hibernate action (e.g. invoking a
> method
> > on
> > > a DAO) produces:
> > >
> > > *java.lang.UnsupportedOperationException*
> > > *The user must supply a JDBC connection*
> > >
> > >    -
> > >
> >
>  
> org.hibernate.connection.UserSuppliedConnectionProvider.getConnection(UserSuppliedConnectionProvider.java:54)
> > >    -
> > >
> >
>  
> org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:446)
> > >    -
> > >
> >
>  
> org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:167)
> > >    - org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:160)
> > >    -
> > >
> >  org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:81)
> > >    -
> > >
>  org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1473)
> > >    -
> > >
> >
>  
> org.apache.tapestry5.internal.hibernate.HibernateSessionManagerImpl.startNewTransaction(HibernateSessionManagerImpl.java:38)
> > >    -
> > >
> >
>  
> org.apache.tapestry5.internal.hibernate.HibernateSessionManagerImpl.<init>(HibernateSessionManagerImpl.java:33)
> > >    - ...
> > >
> > > Attached are the relevant lines out of my module:
> > >
> > >
> > > public void contributeApplicationDefaults(
> > > MappedConfiguration<String, String> configuration) {
> > >
> > > // There's no hibernate.cfg.xml file
> > > configuration.add(HibernateSymbols.DEFAULT_CONFIGURATION, "false");
> > >  }
> > >
> > > @EagerLoad
> > > public DatabaseMigrator buildDatabaseMigrator() {
> > >  DataSource dataSource = (DataSource) lookup(datasourceName);
> > > FlywayDatabaseMigrator migrator = new
> FlywayDatabaseMigrator(dataSource);
> > >  migrator.updateDatabase();
> > > return migrator;
> > > }
> > >
> > > public void contributeHibernateSessionSource(
> > > OrderedConfiguration<HibernateConfigurer> config) {
> > >
> > > HibernateConfigurer hibernateConfigurer = new
> HibConfig(datasourceName);
> > >
> > > config.add("hibconfig", hibernateConfigurer);
> > >  }
> > >
> > > public void contributeHibernateEntityPackageManager(
> > > Configuration<String> configuration) {
> > >  // Specifies the package
> > > configuration.add("com.tsg.configtool.domain");
> > >  }
> > >
> > > private static final class HibConfig implements HibernateConfigurer {
> > >  private String datasourceName;
> > >
> > > HibConfig(String datasourceName) {
> > >  this.datasourceName = datasourceName;
> > > }
> > >
> > > @Override
> > >  public void configure(org.hibernate.cfg.Configuration configuration) {
> > > configuration.setProperty("hibernate.dialect", DB_DIALECT);
> > >  configuration.setProperty("connection.datasource", datasourceName);
> > > }
> > >  }
> > >
> > > private Object lookup(String resourceName) {
> > > try {
> > >  return new InitialContext().lookup(resourceName);
> > > } catch (NamingException e) {
> > >  throw new RuntimeException("Unable to lookup resource \""
> > > + resourceName + "\".", e);
> > >  }
> > > }
> > >
> > >
> > >
> > > Michael
> > >
> >
>

Reply via email to