-->
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.  [ 3 posts ] 
Author Message
 Post subject: Increment generator not using default Schema.
PostPosted: Mon Nov 01, 2004 6:23 pm 
Newbie

Joined: Mon Sep 13, 2004 4:00 pm
Posts: 15
Location: WI
Hibernate version:
2.1
Mapping documents:
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">

<hibernate-configuration>

    <session-factory>
        <property name="hibernate.connection.driver_class">COM.ibm.db2.jdbc.app.DB2Driver</property>
        <property name="hibernate.connection.url">jdbc:db2:DB2T</property>
        <property name="hibernate.connection.username">name removed</property>
        <property name="hibernate.connection.password">pass removed</property>
        <property name="hibernate.default_schema">ADMRLDDE</property>
        <property name="dialect">net.sf.hibernate.dialect.DB2Dialect</property>
        <property name="show_sql">true</property>
        <property name="hibernate.c3p0.min_size">5</property>
        <property name="hibernate.c3p0.max_size">10</property>
        <property name="hibernate.c3p0.timeout">300</property>
        <property name="hibernate.c3p0.max_statements">20</property>
        <property name="hibernate.c3p0.idle_test_period">3000</property>
    </session-factory>

</hibernate-configuration>

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
                                   "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
    <!-- Contact ************************************************************ -->
    <class name="Contact" table="DEXA912T">
        <id column="contact_id" name="id" type="integer">
            <generator class="increment"/>
        </id>
        <property name="emailAddress" column="email" type="string"/>
        <property name="faxNumber" column="fax" type="string"/>
        <property name="name" column="name" type="string"/>
        <property name="phoneNumber" column="phone" type="string"/>
        <property name="phoneNumberExt" column="extension" type="string"/>
    </class>
</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():
Code:
      PersistanceManager.beginTransaction();
      
      try{
         Contact c = getContact(false);
         
         session.save(c);
      }
      catch(HibernateException hbmEx){
         System.err.println(hbmEx);
         System.exit(-1);   
      }
      
      PersistanceManager.commitTransaction();


Full stack trace of any exception that occurs:
Code:
>COM.ibm.db2.jdbc.DB2Exception: [IBM][CLI Driver][DB2] SQL0204N  "VKDB2T2.DEXA912T" is an undefined name.  SQLSTATE=42704

   at COM.ibm.db2.jdbc.app.SQLExceptionGenerator.throw_SQLException(SQLExceptionGenerator.java:270)
   at COM.ibm.db2.jdbc.app.SQLExceptionGenerator.throw_SQLException(SQLExceptionGenerator.java:207)
   at COM.ibm.db2.jdbc.app.SQLExceptionGenerator.check_return_code(SQLExceptionGenerator.java:458)
   at COM.ibm.db2.jdbc.app.DB2PreparedStatement.execute2(DB2PreparedStatement.java:2110)
   at COM.ibm.db2.jdbc.app.DB2PreparedStatement.executeQuery(DB2PreparedStatement.java:1596)
   at com.mchange.v2.sql.filter.FilterPreparedStatement.executeQuery(FilterPreparedStatement.java:68)
   at com.mchange.v2.c3p0.impl.C3P0PooledConnection$2.executeQuery(C3P0PooledConnection.java:567)
   at net.sf.hibernate.id.IncrementGenerator.getNext(IncrementGenerator.java:67)
   at net.sf.hibernate.id.IncrementGenerator.generate(IncrementGenerator.java:42)
   at net.sf.hibernate.impl.SessionImpl.saveWithGeneratedIdentifier(SessionImpl.java:765)
   at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:738)
   at westest.WesTest.main(WesTest.java:39)

net.sf.hibernate.JDBCException: Could not save object

Name and version of the database you are using:
DB2
The generated SQL (show_sql=true):
None shown.
Debug level Hibernate log excerpt:



It appears that the incement generator doesn't use the default_schema that I am setting in hibernate.cfg.xml. If I just try to read a row, it finds the table fine, but when I insert a new row, it gets the above error.

If I put the schema in the hibernate-mapping or class entities it does work. However, I have one file for each class, and we have our database in several different schemas. Updating all the files each time we want to use a different schema would be a maintenence problem.

Is there a workaround for this?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 02, 2004 3:31 pm 
Newbie

Joined: Mon Sep 13, 2004 4:00 pm
Posts: 15
Location: WI
I think I found the spot in the Hibernate code, but I'm not sure how to fix it.

Around line 966 of net.sf.hibernate.cfg.Binder.java:

Code:
Properties params = new Properties();

         if ( mappings.getSchemaName()!=null ) {
            params.setProperty( PersistentIdentifierGenerator.SCHEMA, mappings.getSchemaName() );
         }


This code just checks the mapping for the particular class to see if there is a schema defined. It doesn't check the Configuration's properties to see if the schema has been set in there.

I tried to access the default schema from the environment, but it doesn't look like it is set yet.

Is there any way to get this to work?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 02, 2004 4:45 pm 
Expert
Expert

Joined: Thu Jan 29, 2004 2:31 am
Posts: 362
Location: Switzerland, Bern
Quote:
If I put the schema in the hibernate-mapping or class entities it does work. However, I have one file for each class, and we have our database in several different schemas. Updating all the files each time we want to use a different schema would be a maintenence problem.


Well, not really a nice solution, but if you must you can play with the XML Document and patch the DB schema name before feeding the mapping into Configuration.

HTH
Ernst


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.