facebook

Hibernate and MySQL backticks

  1. MyEclipse IDE
  2.  > 
  3. Off Topic
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #247079 Reply

    How can I configure Hibernate to use MySQL backticks?
    I follow the MyEclipse_Hibernate_Quickstart and create my HibernateDemo project but …
    SQLGrammarException: ….

    This is the query as in the ‘mysql_query.log’:
    insert into test__mymsg (num, desc) values (‘one’, ‘desc number 1.’)

    And this is the query that works in the DataBase Explorer:
    insert into test.mymsg (`num`, `desc`) values (‘one’, ‘desc number 1.’)

    … the only diffrence is in the columns backticks, but I can’t find any place to configure it.
    I’ve already tried changing the MySQL dialects … but nothing.

    I use Eclipse 3.1.1, MyEclipse 4.1, MySQL 5.0.18.

    In other forum I’ve found that:
    http://opensource2.atlassian.com/projects/hibernate/browse/HB-1539

    but it doesn’t help me much.

    #247088 Reply

    Riyad Kalla
    Member

    This is a Hibernate question, MyEclipse cannot instrument Hibernate to change this. It does seem like a real enough issue that others should have run into it on the Hibernate forums, have you checked there or seen if there is a mysql-specific property for it?

    #247104 Reply

    Haris Peco
    Member

    and this is error

    test__mymsg

    correct is test.mymsg

    best

    #247129 Reply

    Solved.
    The problem was in the mapping file:
    _ added the backticks to the column and table names
    _ removed the catalog name.

    This DON’T works.

    
     <?xml version="1.0"?>
    <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
    <!-- 
        Mapping file autogenerated by MyEclipse - Hibernate Tools
    -->
    <hibernate-mapping>
        <class name="casc.hib.test.Mymsg" table="mymsg" catalog="test">
            <composite-id name="id" class="casc.hib.test.MymsgId">
                <key-property name="num" type="java.lang.String">
                    <column name="num" length="45" />
                </key-property>
                <key-property name="desc" type="java.lang.String">
                    <column name="desc" length="45" />
                </key-property>
            </composite-id>
        </class>
    </hibernate-mapping>
    

    And this works.

    
     <?xml version="1.0"?>
    <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
    <!-- 
        Mapping file autogenerated by MyEclipse - Hibernate Tools
    -->
    <hibernate-mapping>
        <class name="casc.hib.test.Mymsg" table="`mymsg`">
            <composite-id name="id" class="casc.hib.test.MymsgId">
                <key-property name="num" type="java.lang.String">
                    <column name="`num`" length="45" />
                </key-property>
                <key-property name="desc" type="java.lang.String">
                    <column name="`desc`" length="45" />
                </key-property>
            </composite-id>
        </class>
    </hibernate-mapping>
    
    #247148 Reply

    Haris Peco
    Member

    casc,

    This mapping

    <?xml version="1.0"?>
    <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
    <!--
        Mapping file autogenerated by MyEclipse - Hibernate Tools
    -->
    <hibernate-mapping>
        <class name="casc.hib.test.Mymsg" table="mymsg" catalog="test">
            <composite-id name="id" class="casc.hib.test.MymsgId">
                <key-property name="num" type="java.lang.String">
                    <column name="num" length="45" />
                </key-property>
                <key-property name="desc" type="java.lang.String">
                    <column name="desc" length="45" />
                </key-property>
            </composite-id>
        </class>
    </hibernate-mapping> 

    is correct mapping, but doesn’t work , because exists hibernate bug (incorrect make table name).
    We fixed bug in 4.1.1

    best

Viewing 5 posts - 1 through 5 (of 5 total)
Reply To: Hibernate and MySQL backticks

You must be logged in to post in the forum log in