Re: Tapestry-Hibernate Configuration Woes - The user must supply a JDBC connection

2012-07-23 Thread Alex Kotchnev
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(
  MappedConfigurationString, 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(
  OrderedConfigurationHibernateConfigurer config) {
 
  HibernateConfigurer hibernateConfigurer = new HibConfig(datasourceName);
 
  config.add(hibconfig, hibernateConfigurer);
   }
 
  public void contributeHibernateEntityPackageManager(
  ConfigurationString 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
 



Re: Tapestry-Hibernate Configuration Woes - The user must supply a JDBC connection

2012-07-23 Thread Michael Prescott
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(
   MappedConfigurationString, 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(
   OrderedConfigurationHibernateConfigurer config) {
  
   HibernateConfigurer hibernateConfigurer = new
 HibConfig(datasourceName);
  
   config.add(hibconfig, hibernateConfigurer);
}
  
   public void contributeHibernateEntityPackageManager(
   ConfigurationString 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
  
 



Tapestry-Hibernate Configuration Woes - The user must supply a JDBC connection

2012-07-20 Thread Michael Prescott
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(
MappedConfigurationString, 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(
OrderedConfigurationHibernateConfigurer config) {

HibernateConfigurer hibernateConfigurer = new HibConfig(datasourceName);

config.add(hibconfig, hibernateConfigurer);
 }

public void contributeHibernateEntityPackageManager(
ConfigurationString 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


Re: Tapestry-Hibernate Configuration Woes - The user must supply a JDBC connection

2012-07-20 Thread Michael Prescott
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.comwrote:

 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(
 MappedConfigurationString, 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(
 OrderedConfigurationHibernateConfigurer config) {

 HibernateConfigurer hibernateConfigurer = new HibConfig(datasourceName);

 config.add(hibconfig, hibernateConfigurer);
  }

 public void contributeHibernateEntityPackageManager(
 ConfigurationString 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



Tapestry Hibernate configuration

2009-01-26 Thread Graham Ford

Hi,

Is there a way of setting the hibernate configuration file for the 
HibernateModule? For example in my src/main/resources I want the config 
to point to a live database, but for testing a different database. Is 
there a way of doing this, without having to configure hibernate myself 
and then adding it to the HibernateModule?


Thanks,
Graham

-
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org



Re: Tapestry Hibernate configuration

2009-01-26 Thread Howard Lewis Ship
You can contribute to the HibernateSessionSource service. Your
contributions are objects that are used to configure the Hibernate.
Such objects can decide what mode (production vs. development) you
are in, and set the correct values for various Hibernate Configuration
properties.

On Mon, Jan 26, 2009 at 12:39 PM, Graham Ford grahamjf...@gmail.com wrote:
 Hi,

 Is there a way of setting the hibernate configuration file for the
 HibernateModule? For example in my src/main/resources I want the config to
 point to a live database, but for testing a different database. Is there a
 way of doing this, without having to configure hibernate myself and then
 adding it to the HibernateModule?

 Thanks,
 Graham

 -
 To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
 For additional commands, e-mail: users-h...@tapestry.apache.org





-- 
Howard M. Lewis Ship

Creator Apache Tapestry and Apache HiveMind

-
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org



Re: Tapestry Hibernate configuration

2009-01-26 Thread Daniel Jue
Aside from a purely T5 way of doing it,

*You can also look up a JNDI source, configured in your web.xml and in a
context.xml, and then have a different context.xml on each server you deploy
to.  (This is assuming you can use the same dialect and options.)  I used to
switch back and forth between JavaDB (Derby) and Oracle, but the Oracle
stuff got so hairy I ended up just installing Oracle on a VM so the app
would behave.
You can specify the JNDI source in your hibernate.cfg.xml, etc.  A
server-specific context.xml can live on each app server.  If eclipse tries
to erase your context file, try defining it somewhere else, like a
server.xml or context.xml.default.  (at least in Tomcat)

*I bet you could do all sorts of maven/ant kung-fu packaging different
hibernate configs for different profiles.

*You can use a context.xml type file to store variables that your App
modules can load, for doing such useful things like turning on HTTPS only,
production mode, etc.  Then that over-the-phone-sys-admin can just poke
around the context.xml, instead of in your WAR directory, when the
servername needs to be switched, or a password changes.

Daniel

On Mon, Jan 26, 2009 at 5:38 PM, Howard Lewis Ship hls...@gmail.com wrote:

 You can contribute to the HibernateSessionSource service. Your
 contributions are objects that are used to configure the Hibernate.
 Such objects can decide what mode (production vs. development) you
 are in, and set the correct values for various Hibernate Configuration
 properties.

 On Mon, Jan 26, 2009 at 12:39 PM, Graham Ford grahamjf...@gmail.com
 wrote:
  Hi,
 
  Is there a way of setting the hibernate configuration file for the
  HibernateModule? For example in my src/main/resources I want the config
 to
  point to a live database, but for testing a different database. Is there
 a
  way of doing this, without having to configure hibernate myself and then
  adding it to the HibernateModule?
 
  Thanks,
  Graham
 
  -
  To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
  For additional commands, e-mail: users-h...@tapestry.apache.org
 
 



 --
 Howard M. Lewis Ship

 Creator Apache Tapestry and Apache HiveMind

 -
 To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
 For additional commands, e-mail: users-h...@tapestry.apache.org