-->
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.  [ 6 posts ] 
Author Message
 Post subject: Case-sensitive sql field names
PostPosted: Mon Jan 17, 2005 9:36 am 
Newbie

Joined: Mon Jan 17, 2005 9:23 am
Posts: 15
Our problem is that the generated sql MUST include quotes around the field names to make them case-sensitive, otherwise Firebird will convert them to uppercase and tell us the field does not exist...
Is it possible to tell Hibernate to quote all field names??




Hibernate version: 2.1.7

Mapping document:
<?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>
<class name="sps.data.Makler" table="MAKLER">
<id name="id" column="makler_id" type="int">
<generator class="assigned" />
</id>
<property name="accountNr" column="account_nr" type="string" />
<property name="angelegtUserId" column="angelegt_user_id" type="int" />
<property name="angelegtZeit" column="angelegt_zeit" type="timestamp" not-null="true" />
<property name="ansprechpartner" column="ansprechpartner" type="string" />
<property name="bemerkung" column="bemerkung" type="string" />
<property name="bemerkung2" column="bemerkung2" type="string" />
<property name="changeTimestamp" column="change_timestamp" type="timestamp" />
<property name="email" column="email" type="string" />
<property name="fax" column="fax" type="string" />
<property name="fibuNr" column="fibu_nr" type="string" />
<property name="gutschriftRechnung" column="gutschrift_rechnung" type="int" />
<property name="journal" column="journal" type="int" />
<property name="kurzname" column="kurzname" type="string" />
<property name="maklerRabattProz" column="makler_rabatt_proz" type="float" />
<property name="maklergruppeId" column="maklergruppe_id" type="int" />
<property name="name" column="name" type="string" not-null="true" />
<property name="name2" column="name2" type="string" />
<property name="ort" column="ort" type="string" />
<property name="plz" column="plz" type="string" />
<property name="postfach" column="postfach" type="string" />
<property name="provisionssatz" column="provisionssatz" type="float" />
<property name="rechnungskopies" column="rechnungskopies" type="int" />
<property name="rechnungsname1" column="rechnungsname_1" type="string" />
<property name="rechnungsname2" column="rechnungsname_2" type="string" />
<property name="rechnungsname3" column="rechnungsname_3" type="string" />
<property name="sammelkommission" column="sammelkommission" type="int" />
<property name="smdAgentcode" column="smd_agentcode" type="string" />
<property name="smdName" column="smd_name" type="string" />
<property name="status" column="status" type="int" />
<property name="strasse" column="strasse" type="string" />
<property name="tarifId" column="tarif_id" type="int" />
<property name="telefon" column="telefon" type="string" />
<property name="verholleistungenGesplittet" column="verholleistungen_gesplittet" type="int" />
<property name="www" column="www" type="string" />
</class>
</hibernate-mapping>



Code between sessionFactory.openSession() and session.close():
Transaction t = ses.beginTransaction();
List l = ses.find("from Makler as m order by m.id asc");
for(Iterator it = l.iterator();it.hasNext();) {
m=(Makler)it.next();
break;
}
t.commit();

Full stack trace of any exception that occurs:

17.01.2005 14:24:28 net.sf.hibernate.util.JDBCExceptionReporter logExceptions
WARNUNG: SQL Error: 335544569, SQLState: HY000
17.01.2005 14:24:28 net.sf.hibernate.util.JDBCExceptionReporter logExceptions
SCHWERWIEGEND: GDS Exception. 335544569. Dynamic SQL Error
SQL error code = -206
Column unknown
MAKLER0_.MAKLER_ID
At line 1, column 17.
17.01.2005 14:24:28 net.sf.hibernate.util.JDBCExceptionReporter logExceptions
WARNUNG: SQL Error: 335544569, SQLState: HY000
17.01.2005 14:24:28 net.sf.hibernate.util.JDBCExceptionReporter logExceptions
SCHWERWIEGEND: GDS Exception. 335544569. Dynamic SQL Error
SQL error code = -206
Column unknown
MAKLER0_.MAKLER_ID
At line 1, column 17.
Debug: ERROR: HibernateException
Debug: Could not execute query
Debug: net.sf.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:81)
Debug: net.sf.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:70)
Debug: net.sf.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:30)
Debug: net.sf.hibernate.impl.SessionImpl.convert(SessionImpl.java:4110)
Debug: net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1556)
Debug: net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1530)
Debug: net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1522)
Debug: sps.logic.Database.holeMakler(Database.java:68)
Debug: sps.test.Main.main(Main.java:24)

Name and version of the database you are using:
Firebird 1.5

The generated SQL (show_sql=true):
Hibernate: select makler0_.makler_id as makler_id, makler0_.account_nr as account_nr, makler0_.angelegt_user_id as angelegt3_, makler0_.angelegt_zeit as angelegt4_, makler0_.ansprechpartner as ansprech5_, makler0_.bemerkung as bemerkung, makler0_.bemerkung2 as bemerkung2, makler0_.change_timestamp as change_t8_, makler0_.email as email, makler0_.fax as fax, makler0_.fibu_nr as fibu_nr, makler0_.gutschrift_rechnung as gutschr12_, makler0_.journal as journal, makler0_.kurzname as kurzname, makler0_.makler_rabatt_proz as makler_15_, makler0_.maklergruppe_id as maklerg16_, makler0_.name as name, makler0_.name2 as name2, makler0_.ort as ort, makler0_.plz as plz, makler0_.postfach as postfach, makler0_.provisionssatz as provisi22_, makler0_.rechnungskopies as rechnun23_, makler0_.rechnungsname_1 as rechnun24_, makler0_.rechnungsname_2 as rechnun25_, makler0_.rechnungsname_3 as rechnun26_, makler0_.sammelkommission as sammelk27_, makler0_.smd_agentcode as smd_age28_, makler0_.smd_name as smd_name, makler0_.status as status, makler0_.strasse as strasse, makler0_.tarif_id as tarif_id, makler0_.telefon as telefon, makler0_.verholleistungen_gesplittet as verholl34_, makler0_.www as www from MAKLER makler0_ order by makler0_.makler_id asc

Debug level Hibernate log excerpt:
7.01.2005 14:24:24 net.sf.hibernate.cfg.Environment <clinit>
INFO: Hibernate 2.1.7
17.01.2005 14:24:24 net.sf.hibernate.cfg.Environment <clinit>
INFO: loaded properties from resource hibernate.properties: {hibernate.connection.username=sysdba, hibernate.connection.password=masterkey, hibernate.cglib.use_reflection_optimizer=true, hibernate.dialect=net.sf.hibernate.dialect.FirebirdDialect, hibernate.show_sql=true, hibernate.connection.url=jdbc:firebirdsql:192.168.1.50/3050:/opt/firebird/datenbank/mafelo/mafelo_sps_test.gdb, hibernate.connection.driver_class=org.firebirdsql.jdbc.FBDriver}
17.01.2005 14:24:24 net.sf.hibernate.cfg.Environment <clinit>
INFO: using CGLIB reflection optimizer
17.01.2005 14:24:24 net.sf.hibernate.cfg.Environment <clinit>
INFO: using JDK 1.4 java.sql.Timestamp handling
17.01.2005 14:24:24 net.sf.hibernate.cfg.Configuration addResource
INFO: Mapping resource: sps/data/Makler.hbm.xml
17.01.2005 14:24:25 net.sf.hibernate.cfg.Binder bindRootClass
INFO: Mapping class: sps.data.Makler -> MAKLER
17.01.2005 14:24:25 net.sf.hibernate.cfg.Configuration secondPassCompile
INFO: processing one-to-many association mappings
17.01.2005 14:24:25 net.sf.hibernate.cfg.Configuration secondPassCompile
INFO: processing one-to-one association property references
17.01.2005 14:24:25 net.sf.hibernate.cfg.Configuration secondPassCompile
INFO: processing foreign key constraints
17.01.2005 14:24:25 net.sf.hibernate.dialect.Dialect <init>
INFO: Using dialect: net.sf.hibernate.dialect.FirebirdDialect
17.01.2005 14:24:25 net.sf.hibernate.cfg.SettingsFactory buildSettings
INFO: Use outer join fetching: true
17.01.2005 14:24:25 net.sf.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Using Hibernate built-in connection pool (not for production use!)
17.01.2005 14:24:25 net.sf.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Hibernate connection pool size: 20
17.01.2005 14:24:25 net.sf.hibernate.connection.DriverManagerConnectionProvider configure
INFO: using driver: org.firebirdsql.jdbc.FBDriver at URL: jdbc:firebirdsql:192.168.1.50/3050:/opt/firebird/datenbank/mafelo/mafelo_sps_test.gdb
17.01.2005 14:24:25 net.sf.hibernate.connection.DriverManagerConnectionProvider configure
INFO: connection properties: {user=sysdba, password=masterkey}
17.01.2005 14:24:25 net.sf.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
INFO: No TransactionManagerLookup configured (in JTA environment, use of process level read-write cache is not recommended)
17.01.2005 14:24:26 net.sf.hibernate.cfg.SettingsFactory buildSettings
INFO: Use scrollable result sets: true
17.01.2005 14:24:26 net.sf.hibernate.cfg.SettingsFactory buildSettings
INFO: Use JDBC3 getGeneratedKeys(): false
17.01.2005 14:24:26 net.sf.hibernate.cfg.SettingsFactory buildSettings
INFO: Optimize cache for minimal puts: false
17.01.2005 14:24:26 net.sf.hibernate.cfg.SettingsFactory buildSettings
INFO: echoing all SQL to stdout
17.01.2005 14:24:26 net.sf.hibernate.cfg.SettingsFactory buildSettings
INFO: Query language substitutions: {}
17.01.2005 14:24:26 net.sf.hibernate.cfg.SettingsFactory buildSettings
INFO: cache provider: net.sf.hibernate.cache.EhCacheProvider
17.01.2005 14:24:26 net.sf.hibernate.cfg.Configuration configureCaches
INFO: instantiating and configuring caches
17.01.2005 14:24:26 net.sf.hibernate.impl.SessionFactoryImpl <init>
INFO: building session factory
17.01.2005 14:24:27 net.sf.hibernate.impl.SessionFactoryObjectFactory addInstance
INFO: Not binding factory to JNDI, no JNDI name configured


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 17, 2005 10:48 am 
Newbie

Joined: Mon Jan 17, 2005 9:23 am
Posts: 15
BTW, we create the mapping and the Java code from the existing database, using Eclipse and HiberClipse plugin.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 17, 2005 1:44 pm 
Newbie

Joined: Mon Jan 17, 2005 9:23 am
Posts: 15
I have now written this quick&dirty hack for converting my mappingfiles .... is this REALLY the only solution??? please help

Code:
/*
* Created on 17.01.2005
*
*/
package sps.data.convert;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.*;


import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.FactoryConfigurationError;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;

/**
* Very dirty script to honor lower-case field names in Hibernate...
*
* @author Bastian Voigt
*
*/
public class Converter {
    private String m_path;
   
    public Converter()
    {
        try
        {
            m_builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
            m_trans = TransformerFactory.newInstance();
        } catch (ParserConfigurationException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (FactoryConfigurationError e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
       
    }
   

   public DocumentBuilder m_builder;
   private TransformerFactory m_trans;
   
   public void convertFile(File f) throws Exception
   {
       doConvert(new FileInputStream(f), new FileOutputStream(m_path+"\\convert\\"+f.getName()));
   }
   
   public void convertFile(String filename) throws Exception
   {
       doConvert(new FileInputStream(m_path+ "\\" +filename),
               new FileOutputStream(m_path+ "\\" +filename));
   }
   
   public void doConvert(InputStream in, OutputStream out) throws Exception
   {
      Document doc = m_builder.parse(in);
      in.close();
      Element elemRoot = doc.getDocumentElement();
      Node n = null;
      n = elemRoot.getFirstChild();
      while(!(n instanceof Element)) n=n.getNextSibling();
      n = n.getFirstChild();
      while((n!=null) && !(n instanceof Element))
          n=n.getNextSibling();

      String a = null, tagname=null;
      if(n!=null)
          do
          {
              if(!(n instanceof Element))
                  continue;
              Element elem = (Element) n;
              tagname = elem.getTagName();
              if(tagname.equals("property") || tagname.equals("id"))
              {
                  if((a=elem.getAttribute("column"))!=null)
                 {
                      if(!(a.startsWith("`")))
                          elem.setAttribute("column", "`" + a + "`");
                 }
              }             
          } while( (n = n.getNextSibling())!=null);
      Transformer t = m_trans.newTransformer();
      t.transform(new DOMSource(doc), new StreamResult(out));
      out.close();
   }
   
   public void setPath(String p)
   {
       m_path=p;
   }
   
   public void convertFiles() throws Exception
   {
       File f = new File(m_path);
       FileFilter ff = new FileFilter()
        {
            public boolean accept(File pathname)
            {
                if( (pathname.isFile()) && (pathname.getName().endsWith(".hbm.xml")) && (pathname.getName().indexOf('$')==-1))
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
        };
       File[] files = f.listFiles(ff);
       for(int i=0;i<files.length;i++)
       {
           System.out.println("Converting file "+files[i].getAbsolutePath());
           convertFile(files[i]);
       }
          
   }
   
   public static void main(String[] args) {
       try {
       Converter c = new Converter();
       c.setPath("c:\\eclipse\\workspace\\sps\\src\\sps\\data");
       c.convertFiles();
       }
       catch(Exception e) {e.printStackTrace();}
      
   }
   
}



Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 17, 2005 2:46 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Have you tried hooking this in with a custom NamingStrategy implementation?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 18, 2005 9:12 am 
Newbie

Joined: Mon Jan 17, 2005 9:23 am
Posts: 15
I have now written my own custom NamingStrategy. How can I tell Hibernate to use it when running DDL2HBM? Is there a property I can write in my .properties file?


Top
 Profile  
 
 Post subject: Re: Case-sensitive sql field names
PostPosted: Tue Sep 29, 2009 6:09 pm 
Newbie

Joined: Tue Sep 29, 2009 6:04 pm
Posts: 2
Despues de muchas vueltas, con postgres me funciono esto...

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="zavaleta.luis.VO">
<class name="CatTiendasVO" table="&quot;CatTiendas&quot;">
<id name="idTienda" column="&quot;idTienda&quot;">
<generator class="native"/>
</id>
<property name="idCadena" type="string" column="&quot;idCadena&quot;"/>

despues de esto solo siguen mas atributos con la misma nomeclatura y cerrar los tags... es una solucion fea, pero bueno... espero alguien tenga algo mejor XD..


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