-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 13 posts ] 
Author Message
 Post subject: database as command line argument
PostPosted: Fri Apr 22, 2005 9:35 am 
Beginner
Beginner

Joined: Fri Feb 04, 2005 2:44 pm
Posts: 25
Location: Buffalo, NY
Hello

I would like to use Hibernate but I need to have the name of the database come from a command line argument.

I tried leaving the database off of the "hibernate.connection.url" property, and then using Configurgation().setProperty(). But that doesn't work. I am not sure if that is related to Hibernate itself, or to the Hibernate Synchronizer Eclipse plugin?

Code:
    public void connect(String database)
    {
        Configuration config = null;
       
        try
        {
            config = new Configuration();
            String url = config.getProperty("hibernate.connection.url");
            url = url + database;
            config.setProperty("hibernate.connection.url", url);
            sessionFactory = config.buildSessionFactory();
        }
        catch (HibernateException e)
        {
            e.printStackTrace();
        }
    }


Code:
    public void test()
    {
        try
        {
           _RootDAO.initialize();
           T_scase scase = null;
           T_scaseDAO dao = new T_scaseDAO();
           T_scaseID id = new T_scaseID("foo", "bar");
           scase = dao.load(id);
           System.out.println(scase.getAge());
        }
        catch (HibernateException e)
        {
            e.printStackTrace();
        }
    }


And in the hibernate.cfg.xml:
<property name="hibernate.connection.url">jdbc:edbc://myserver:s27/</property>

The error is:
Caused by: ca.edbc.util.EdbcEx: Database name starting with ''
starts with an invalid character.
at ca.edbc.jdbc.EdbcObj.readResults(EdbcObj.java:782)
at ca.edbc.jdbc.EdbcConnect.dbms_connect(EdbcConnect.java:766)
at ca.edbc.jdbc.EdbcConnect.<init>(EdbcConnect.java:349)
at ca.edbc.jdbc.EdbcDriver.connect(EdbcDriver.java:444)
at java.sql.DriverManager.getConnection(DriverManager.java:512)
at java.sql.DriverManager.getConnection(DriverManager.java:140)
at net.sf.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:101)
at net.sf.hibernate.impl.BatcherImpl.openConnection(BatcherImpl.java:289)

Any ideas on how I can suppy the database dynamically?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 22, 2005 10:16 am 
Senior
Senior

Joined: Mon Apr 04, 2005 8:04 am
Posts: 128
Location: Manchester, NH USA
It is possible to do what you are trying to do by setting the configuration property dynamically. It looks like you are having some trouble reading the property from your [non-Hibernate] configuration file. Have you tried stepping into your connect method with a debugger?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 22, 2005 2:28 pm 
Beginner
Beginner

Joined: Fri Feb 04, 2005 2:44 pm
Posts: 25
Location: Buffalo, NY
The problem is NOT in my connect method. The exception gets thrown on the dao.save() call.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 22, 2005 2:30 pm 
Beginner
Beginner

Joined: Fri Feb 04, 2005 2:44 pm
Posts: 25
Location: Buffalo, NY
Sorry, I meant to say: dao.load(id);

weaselboy1976 wrote:
The problem is NOT in my connect method. The exception gets thrown on the dao.save() call.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 22, 2005 2:44 pm 
Senior
Senior

Joined: Mon Apr 04, 2005 8:04 am
Posts: 128
Location: Manchester, NH USA
Are you looking at a different stack trace? I don't see .load anywhere in the stack trace you posted:
Quote:
The error is:
Caused by: ca.edbc.util.EdbcEx: Database name starting with ''
starts with an invalid character.
at ca.edbc.jdbc.EdbcObj.readResults(EdbcObj.java:782)
at ca.edbc.jdbc.EdbcConnect.dbms_connect(EdbcConnect.java:766)
at ca.edbc.jdbc.EdbcConnect.<init>(EdbcConnect.java:349)
at ca.edbc.jdbc.EdbcDriver.connect(EdbcDriver.java:444)
at java.sql.DriverManager.getConnection(DriverManager.java:512)
at java.sql.DriverManager.getConnection(DriverManager.java:140)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 25, 2005 8:26 am 
Beginner
Beginner

Joined: Fri Feb 04, 2005 2:44 pm
Posts: 25
Location: Buffalo, NY
I'm still not 100% sure, but it looks like an issue with the code that the Hibernate Synchronizer plugin generates. What I did was:

1) I never call the _BaseRootDAO.initialize() method
2) in all my DAO load and save calls, I provide the session [ex. scase = dao.load(id, session);]

It seems to work doing this. It's not ideal, but it's ok.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 25, 2005 8:29 am 
Beginner
Beginner

Joined: Fri Feb 04, 2005 2:44 pm
Posts: 25
Location: Buffalo, NY
I know, that's weird. But I ran with debugger and it is on the call to load that fails. The call to connect in the stack trace isn't *my* conect method, but the one in the jdbc I use.

pmularien wrote:
Are you looking at a different stack trace? I don't see .load anywhere in the stack trace you posted:
Quote:
The error is:
Caused by: ca.edbc.util.EdbcEx: Database name starting with ''
starts with an invalid character.
at ca.edbc.jdbc.EdbcObj.readResults(EdbcObj.java:782)
at ca.edbc.jdbc.EdbcConnect.dbms_connect(EdbcConnect.java:766)
at ca.edbc.jdbc.EdbcConnect.<init>(EdbcConnect.java:349)
at ca.edbc.jdbc.EdbcDriver.connect(EdbcDriver.java:444)
at java.sql.DriverManager.getConnection(DriverManager.java:512)
at java.sql.DriverManager.getConnection(DriverManager.java:140)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 25, 2005 8:55 am 
Senior
Senior

Joined: Mon Apr 04, 2005 8:04 am
Posts: 128
Location: Manchester, NH USA
Can you please post the complete stack trace, then?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 25, 2005 9:12 am 
Beginner
Beginner

Joined: Fri Feb 04, 2005 2:44 pm
Posts: 25
Location: Buffalo, NY
pmularien wrote:
Can you please post the complete stack trace, then?


09:05:28,421 INFO Environment:478 - Hibernate 2.1.7
09:05:28,421 INFO Environment:507 - hibernate.properties not found
09:05:28,437 INFO Environment:538 - using CGLIB reflection optimizer
09:05:28,437 INFO Environment:567 - using JDK 1.4 java.sql.Timestamp handling
09:05:28,453 INFO Configuration:934 - configuring from file: test.cfg.xml
09:05:29,078 INFO Configuration:331 - Mapping resource: config/T_scase.hbm.xml
09:05:29,281 INFO Binder:230 - Mapping class: config.T_scase -> SCASE
09:05:29,703 INFO Configuration:1058 - Configured SessionFactory: null
09:05:29,703 INFO Configuration:632 - processing one-to-many association mappings
09:05:29,703 INFO Configuration:641 - processing one-to-one association property references
09:05:29,703 INFO Configuration:666 - processing foreign key constraints
09:05:29,750 INFO Dialect:86 - Using dialect: net.sf.hibernate.dialect.IngresDialect
09:05:29,781 INFO SettingsFactory:74 - Use outer join fetching: true
09:05:29,796 INFO DriverManagerConnectionProvider:42 - Using Hibernate built-in connection pool (not for production use!)
09:05:29,796 INFO DriverManagerConnectionProvider:43 - Hibernate connection pool size: 100
09:05:29,875 INFO DriverManagerConnectionProvider:77 - using driver: ca.edbc.jdbc.EdbcDriver at URL: jdbc:edbc://papasmurf:p27/actg
09:05:29,875 INFO DriverManagerConnectionProvider:78 - connection properties: {user=cooldude, password=topsecret}
09:05:29,890 INFO TransactionManagerLookupFactory:33 - No TransactionManagerLookup configured (in JTA environment, use of process level read-write cache is not recommended)
09:05:29,890 DEBUG DriverManagerConnectionProvider:84 - total checked-out connections: 0
09:05:29,890 DEBUG DriverManagerConnectionProvider:100 - opening new JDBC connection
09:05:32,671 DEBUG DriverManagerConnectionProvider:106 - created connection to: jdbc:edbc://papasmurf:p27/actg, Isolation Level: 8
09:05:32,703 DEBUG DriverManagerConnectionProvider:120 - returning connection to pool, pool size: 1
09:05:32,703 INFO SettingsFactory:114 - Use scrollable result sets: false
09:05:32,703 INFO SettingsFactory:117 - Use JDBC3 getGeneratedKeys(): false
09:05:32,703 INFO SettingsFactory:120 - Optimize cache for minimal puts: false
09:05:32,703 INFO SettingsFactory:126 - echoing all SQL to stdout
09:05:32,718 INFO SettingsFactory:129 - Query language substitutions: {}
09:05:32,718 INFO SettingsFactory:140 - cache provider: net.sf.hibernate.cache.EhCacheProvider
09:05:32,718 INFO Configuration:1121 - instantiating and configuring caches
09:05:32,765 INFO SessionFactoryImpl:119 - building session factory
09:05:33,078 INFO SessionFactoryObjectFactory:82 - Not binding factory to JNDI, no JNDI name configured
09:05:33,109 INFO Configuration:900 - configuring from resource: /hibernate.cfg.xml
09:05:33,109 INFO Configuration:872 - Configuration resource: /hibernate.cfg.xml
09:05:33,140 INFO Configuration:331 - Mapping resource: config/T_scase.hbm.xml
09:05:33,187 INFO Binder:230 - Mapping class: config.T_scase -> SCASE
09:05:33,187 INFO Configuration:1058 - Configured SessionFactory: null
09:05:33,203 INFO Configuration:632 - processing one-to-many association mappings
09:05:33,203 INFO Configuration:641 - processing one-to-one association property references
09:05:33,203 INFO Configuration:666 - processing foreign key constraints
09:05:33,203 INFO Dialect:86 - Using dialect: net.sf.hibernate.dialect.IngresDialect
09:05:33,203 INFO SettingsFactory:74 - Use outer join fetching: true
09:05:33,203 INFO DriverManagerConnectionProvider:42 - Using Hibernate built-in connection pool (not for production use!)
09:05:33,203 INFO DriverManagerConnectionProvider:43 - Hibernate connection pool size: 100
09:05:33,203 INFO DriverManagerConnectionProvider:77 - using driver: ca.edbc.jdbc.EdbcDriver at URL: jdbc:edbc://happy:h27/
09:05:33,203 INFO DriverManagerConnectionProvider:78 - connection properties: {user=cooldude, password=topsecret}
09:05:33,203 INFO TransactionManagerLookupFactory:33 - No TransactionManagerLookup configured (in JTA environment, use of process level read-write cache is not recommended)
09:05:33,218 DEBUG DriverManagerConnectionProvider:84 - total checked-out connections: 0
09:05:33,218 DEBUG DriverManagerConnectionProvider:100 - opening new JDBC connection
09:05:33,281 WARN SettingsFactory:107 - Could not obtain connection metadata
ca.edbc.util.EdbcEx: Database name starting with ''
starts with an invalid character.
at ca.edbc.jdbc.EdbcObj.readResults(EdbcObj.java:782)
at ca.edbc.jdbc.EdbcConnect.dbms_connect(EdbcConnect.java:766)
at ca.edbc.jdbc.EdbcConnect.<init>(EdbcConnect.java:349)
at ca.edbc.jdbc.EdbcDriver.connect(EdbcDriver.java:444)
at java.sql.DriverManager.getConnection(DriverManager.java:512)
at java.sql.DriverManager.getConnection(DriverManager.java:140)
at net.sf.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:101)
at net.sf.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:84)
at net.sf.hibernate.cfg.Configuration.buildSettings(Configuration.java:1160)
at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:794)
at config.base._BaseRootDAO.initialize(_BaseRootDAO.java:55)
at config.base._BaseRootDAO.initialize(_BaseRootDAO.java:42)
at config.base._BaseRootDAO.initialize(_BaseRootDAO.java:33)
at config.ConfigTest.test(ConfigTest.java:62)
at config.ConfigTest.main(ConfigTest.java:49)
09:05:33,296 INFO SettingsFactory:114 - Use scrollable result sets: false
09:05:33,296 INFO SettingsFactory:117 - Use JDBC3 getGeneratedKeys(): false
09:05:33,296 INFO SettingsFactory:120 - Optimize cache for minimal puts: false
09:05:33,296 INFO SettingsFactory:126 - echoing all SQL to stdout
09:05:33,296 INFO SettingsFactory:129 - Query language substitutions: {}
09:05:33,296 INFO SettingsFactory:140 - cache provider: net.sf.hibernate.cache.EhCacheProvider
09:05:33,296 INFO Configuration:1121 - instantiating and configuring caches
09:05:33,296 INFO SessionFactoryImpl:119 - building session factory
09:05:33,390 INFO SessionFactoryObjectFactory:82 - Not binding factory to JNDI, no JNDI name configured
09:05:33,484 DEBUG DriverManagerConnectionProvider:84 - total checked-out connections: 0
09:05:33,484 DEBUG DriverManagerConnectionProvider:100 - opening new JDBC connection
09:05:33,546 WARN JDBCExceptionReporter:57 - SQL Error: 6688, SQLState: 5000A
09:05:33,546 ERROR JDBCExceptionReporter:58 - Database name starting with ''
starts with an invalid character.
09:05:33,546 WARN JDBCExceptionReporter:57 - SQL Error: 590115, SQLState: 08001
09:05:33,546 ERROR JDBCExceptionReporter:58 - Error initiating session.
09:05:33,562 WARN JDBCExceptionReporter:57 - SQL Error: 13172737, SQLState: 08006
09:05:33,562 ERROR JDBCExceptionReporter:58 - The connection to the server has been aborted.
net.sf.hibernate.exception.GenericJDBCException: Cannot open connection
at net.sf.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:81)
at net.sf.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:70)
at net.sf.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:30)
at net.sf.hibernate.impl.BatcherImpl.convert(BatcherImpl.java:325)
at net.sf.hibernate.impl.BatcherImpl.openConnection(BatcherImpl.java:292)
at net.sf.hibernate.impl.SessionImpl.connect(SessionImpl.java:3361)
at net.sf.hibernate.impl.SessionImpl.connection(SessionImpl.java:3321)
at net.sf.hibernate.impl.BatcherImpl.prepareQueryStatement(BatcherImpl.java:66)
at net.sf.hibernate.loader.Loader.prepareQueryStatement(Loader.java:779)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:265)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
at net.sf.hibernate.loader.Loader.loadEntity(Loader.java:911)
at net.sf.hibernate.loader.Loader.loadEntity(Loader.java:931)
at net.sf.hibernate.loader.EntityLoader.load(EntityLoader.java:59)
at net.sf.hibernate.loader.EntityLoader.load(EntityLoader.java:51)
at net.sf.hibernate.persister.EntityPersister.load(EntityPersister.java:415)
at net.sf.hibernate.impl.SessionImpl.doLoad(SessionImpl.java:2130)
at net.sf.hibernate.impl.SessionImpl.doLoadByClass(SessionImpl.java:2000)
at net.sf.hibernate.impl.SessionImpl.load(SessionImpl.java:1929)
at config.base._BaseRootDAO.load(_BaseRootDAO.java:292)
at config.base._BaseRootDAO.load(_BaseRootDAO.java:281)
at config.base.BaseT_scaseDAO.load(BaseT_scaseDAO.java:53)
at config.ConfigTest.test(ConfigTest.java:68)
at config.ConfigTest.main(ConfigTest.java:49)
Caused by: ca.edbc.util.EdbcEx: Database name starting with ''
starts with an invalid character.
at ca.edbc.jdbc.EdbcObj.readResults(EdbcObj.java:782)
at ca.edbc.jdbc.EdbcConnect.dbms_connect(EdbcConnect.java:766)
at ca.edbc.jdbc.EdbcConnect.<init>(EdbcConnect.java:349)
at ca.edbc.jdbc.EdbcDriver.connect(EdbcDriver.java:444)
at java.sql.DriverManager.getConnection(DriverManager.java:512)
at java.sql.DriverManager.getConnection(DriverManager.java:140)
at net.sf.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:101)
at net.sf.hibernate.impl.BatcherImpl.openConnection(BatcherImpl.java:289)
... 19 more


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 25, 2005 11:24 am 
Senior
Senior

Joined: Mon Apr 04, 2005 8:04 am
Posts: 128
Location: Manchester, NH USA
I'm sorry, I still don't understand what you're doing - what is the JDBC driver edbc.ca? It looks like you should look at the source code referenced in the JDBC driver for more help:
Code:
09:05:33,281 WARN SettingsFactory:107 - Could not obtain connection metadata
ca.edbc.util.EdbcEx: Database name starting with ''
starts with an invalid character.
at [b]ca.edbc.jdbc.EdbcObj.readResults(EdbcObj.java:782)[/b]
at ca.edbc.jdbc.EdbcConnect.dbms_connect(EdbcConnect.java:766)
at ca.edbc.jdbc.EdbcConnect.<init>(EdbcConnect.java:349)
at ca.edbc.jdbc.EdbcDriver.connect(EdbcDriver.java:444)


You're getting a meaningful error from Hibernate:
Quote:
09:05:33,281 WARN SettingsFactory:107 - Could not obtain connection metadata


Is it possible that this JDBC driver isn't JDBC compliant and doesn't implement some parts of the JDBC interface?

Furthermore, why are you choosing the IngresDialect?

It looks like you are successfully changing the target JDBC URL from jdbc:edbc://papasmurf:p27/actg to jdbc:edbc://happy:h27/ (assuming this is what you wanted to be doing).


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 25, 2005 2:02 pm 
Beginner
Beginner

Joined: Fri Feb 04, 2005 2:44 pm
Posts: 25
Location: Buffalo, NY
- I am trying to use Hibernate, but instead of providing the database name in the hibernate.connection.url property of the hibernate.hbm.xml file, I want to define in dynamically [from command line]

- edbc.ca is the JDBC driver

- I can't see the source code from the JDBC driver. It is a jar file with just .class files. It's from commerical vendor Computer Associates. It is JDBC compliant.

- I am choosing IngresDialect because I am connecting to an Ingres database.

- I do NOT want to change the target JDBC URL


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 25, 2005 2:26 pm 
Senior
Senior

Joined: Mon Apr 04, 2005 8:04 am
Posts: 128
Location: Manchester, NH USA
It looks like you are passing jdbc:edbc://happy:h27/ as the JDBC URL. Will this JDBC URL work in a standard JDBC program (Hibernate being removed from the picture)? I was looking at the Ingres documentation and it read as through the name of the database was a required part of the JDBC URL - which is missing in this URL - the database name should appear e.g.
jdbc:edbc://happy:h27/dbname. But, I'm not familiar enough with Ingres to know whether this is required.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 25, 2005 2:28 pm 
Senior
Senior

Joined: Mon Apr 04, 2005 8:04 am
Posts: 128
Location: Manchester, NH USA
weaselboy1976 wrote:
I do NOT want to change the target JDBC URL


I mentioned this because in your log file, I see two JDBC URLs referenced in a row:

Quote:
09:05:29,796 INFO DriverManagerConnectionProvider:42 - Using Hibernate built-in connection pool (not for production use!)
09:05:29,796 INFO DriverManagerConnectionProvider:43 - Hibernate connection pool size: 100
09:05:29,875 INFO DriverManagerConnectionProvider:77 - using driver: ca.edbc.jdbc.EdbcDriver at URL: jdbc:edbc://papasmurf:p27/actg
09:05:29,875 INFO DriverManagerConnectionProvider:78 - connection properties: {user=cooldude, password=topsecret}
09:05:29,890 INFO TransactionManagerLookupFactory:33 - No TransactionManagerLookup configured (in JTA environment, use of process level read-write cache is not recommended)
09:05:29,890 DEBUG DriverManagerConnectionProvider:84 - total checked-out connections: 0
09:05:29,890 DEBUG DriverManagerConnectionProvider:100 - opening new JDBC connection
09:05:32,671 DEBUG DriverManagerConnectionProvider:106 - created connection to: jdbc:edbc://papasmurf:p27/actg, Isolation Level: 8
09:05:32,703 DEBUG DriverManagerConnectionProvider:120 - returning connection to pool, pool size: 1
<snip>
09:05:33,203 INFO DriverManagerConnectionProvider:42 - Using Hibernate built-in connection pool (not for production use!)
09:05:33,203 INFO DriverManagerConnectionProvider:43 - Hibernate connection pool size: 100
09:05:33,203 INFO DriverManagerConnectionProvider:77 - using driver: ca.edbc.jdbc.EdbcDriver at URL: jdbc:edbc://happy:h27/
09:05:33,203 INFO DriverManagerConnectionProvider:78 - connection properties: {user=cooldude, password=topsecret}
09:05:33,203 INFO TransactionManagerLookupFactory:33 - No TransactionManagerLookup configured (in JTA environment, use of process level read-write cache is not recommended)
09:05:33,218 DEBUG DriverManagerConnectionProvider:84 - total checked-out connections: 0
09:05:33,218 DEBUG DriverManagerConnectionProvider:100 - opening new JDBC connection
09:05:33,281 WARN SettingsFactory:107 - Could not obtain connection metadata
ca.edbc.util.EdbcEx: Database name starting with ''
starts with an invalid character.


I do note that the first URL seems to connect file, and it does have the database name specified (actg).


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 13 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.