facebook

Possible Hibernate mapping bug

  1. MyEclipse Archived
  2.  > 
  3. Database Tools (DB Explorer, Hibernate, etc.)
Viewing 15 posts - 1 through 15 (of 19 total)
  • Author
    Posts
  • #236906 Reply

    tarantula
    Participant

    Hi,

    I’m running Eclipse 3.1 with ME4.0GA on a W2K machine and I think I found a bug with the MyEclipse Hibernate mapping feature. My database is MySQL 4.1.13a-nt and I’m using the MySQL Connector/J driver version 3.1.10.

    The problem seems to be that the default Hibernate mapping generated by MyEclipse for a TEXT (CLOB) column causes a Hibernate serialization exception at runtime. The Hibernate mapping type for the property is “serializable” when it should probably be “string” or “text” (see http://www.hibernate.org/112.html).

    Here is the Hibernate mapping file created by MyEclipse. Notice the type=”serializable” value for the book_description property:

    
    <!-- DO NOT EDIT: This is a generated file that is synchronized -->
    <!-- by MyEclipse Hibernate tool integration.                   -->
    <!-- Created Thu Sep 08 11:04:26 EDT 2005                         -->
    <hibernate-mapping package="test">
    
        <class name="Book" table="book">
            <id name="bookId" column="book_id" type="integer">
                <generator class="native"/>
            </id>
     
            <property name="bookTitle" column="book_title" type="string"  not-null="true" />
            <property name="bookDescription" column="book_description" [b]type="serializable"[/b]  not-null="true" />
        </class>
        
    </hibernate-mapping>

    Here is a unit test that should pass but fails:

    package test;
    
    import java.util.List;
    import junit.framework.TestCase;
    import org.hibernate.Query;
    
    public class TestHibernate extends TestCase {
    
        public void testQuery() {
            try {
                String hql = "from test.Book";
                Query q = HibernateSessionFactory.currentSession().createQuery(hql);
                List books = q.list();
                assertNotNull(books);
            } catch (Exception e) {
                e.printStackTrace();
                assertFalse(true);
            }
        }
    }

    Below is the stack trace from running this test:

    org.hibernate.type.SerializationException: could not deserialize
        at org.hibernate.util.SerializationHelper.deserialize(SerializationHelper.java:211)
        at org.hibernate.util.SerializationHelper.deserialize(SerializationHelper.java:234)
        at org.hibernate.type.SerializableType.fromBytes(SerializableType.java:78)
        at org.hibernate.type.SerializableType.get(SerializableType.java:39)
        at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:77)
        at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:68)
        at org.hibernate.type.AbstractType.hydrate(AbstractType.java:80)
        at org.hibernate.persister.entity.BasicEntityPersister.hydrate(BasicEntityPersister.java:1690)
        at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:991)
        at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:942)
        at org.hibernate.loader.Loader.getRow(Loader.java:855)
        at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:305)
        at org.hibernate.loader.Loader.doQuery(Loader.java:412)
        at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)
        at org.hibernate.loader.Loader.doList(Loader.java:1593)
        at org.hibernate.loader.Loader.list(Loader.java:1577)
        at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:395)
        at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:271)
        at org.hibernate.impl.SessionImpl.list(SessionImpl.java:844)
        at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
        at test.TestHibernate.testQuery(TestHibernate.java:13)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at junit.framework.TestCase.runTest(TestCase.java:154)
        at junit.framework.TestCase.runBare(TestCase.java:127)
        at junit.framework.TestResult$1.protect(TestResult.java:106)
        at junit.framework.TestResult.runProtected(TestResult.java:124)
        at junit.framework.TestResult.run(TestResult.java:109)
        at junit.framework.TestCase.run(TestCase.java:118)
        at junit.framework.TestSuite.runTest(TestSuite.java:208)
        at junit.framework.TestSuite.run(TestSuite.java:203)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
    Caused by: java.io.StreamCorruptedException: invalid stream header
        at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:753)
        at java.io.ObjectInputStream.<init>(ObjectInputStream.java:268)
        at org.hibernate.util.SerializationHelper$CustomObjectInputStream.<init>(SerializationHelper.java:246)
        at org.hibernate.util.SerializationHelper.deserialize(SerializationHelper.java:203)
        ... 35 more

    If I change the book_description property type to “text” or “string” the unit test passes.

    Can you look into this please?

    Thank you,
    Ian

    #236907 Reply

    tarantula
    Participant

    I couldn’t post my original message because it contains SQL. Here goes another try:

    Here is my database schema with some sample data:

    C REATE TABLE book (
      book_id int(11) unsigned NOT NULL auto_increment,
      book_title varchar(255) NOT NULL default '',
      book_description text NOT NULL,
      PRIMARY KEY  (book_id)
    ) Engine=InnoDB DEFAULT CHARSET=latin1;
    
    I NSERT INTO book VALUES("1", "The Nicomachean Ethics", "A philosophical treatise on virtue by Aristotle.");
    I NSERT INTO book VALUES("2", "The Politics", "Aristotle compares the various forms of government.");
    I NSERT INTO book VALUES("3", "The Republic", "Plato considers what constitutes the ideal political community.");
    #236911 Reply

    tarantula
    Participant

    BTW I’m using JDK 1.5.

    #238043 Reply

    Greg Ames
    Participant

    This message has not been recovered.

    #238045 Reply

    Greg Ames
    Participant

    This message has not been recovered.

    #238048 Reply

    Riyad Kalla
    Member

    This message has not been recovered.

    #238135 Reply

    Greg Ames
    Participant

    This message has not been recovered.

    #239041 Reply

    Daniel Kohl
    Member

    Same versions…same problems…..confused, too 😀

    #239112 Reply

    rdraju
    Member

    I am sure this is the problem. If data more than tinyblob, gives and EOF.

    * The “serialized” type defaults to tinyBlob using the MySQLInnoDB dialect, which has size 255 bytes. Many serialized objects are larger, causing EOF exceptions. Use length=”257″ or some such to trigger mapping to a larger blob type.
    * Large serialized objects seem to trigger false dirty checks, causing the same update to be done twice, which in turn is a versioning / optimistic lock error (unexpected row count: …) Use a UserType rather than “serialized” to map larger objects.

    #239113 Reply

    rdraju
    Member

    Sorry for not being very clear. Adding the *length=”257″* to make it blob fixed the problem for me.
    <property name=”DataMap” column=”data_map” type=”serializable” length=”257″/>

    #240265 Reply

    Greg Ames
    Participant

    Very disapointed this was not fixed in the latest release. Please fix this. 😥

    #240268 Reply

    Riyad Kalla
    Member

    Guys we are sorry this slipped by the 4.0.3 release, I have added your comments to the existing issue in our tracking system and marked it as high priority for us. We will nail it.

    #240504 Reply

    tarantula
    Participant

    @support-rkalla wrote:

    Guys we are sorry this slipped by the 4.0.3 release, I have added your comments to the existing issue in our tracking system and marked it as high priority for us. We will nail it.

    I found a workaround to this problem. When generating a Hibernate mapping from database tables in the DB explorer view, use Java types instead of Hibernate types.

    #244124 Reply

    Greg Ames
    Participant

    Is this fixed yet?

    #244134 Reply

    Riyad Kalla
    Member

    Greg not yet, it likely won’t make it into 4.1 and will go into 4.1.1. However there are completely new generation tools in 4.1 so this might have been fixed by those changes. Hang tight 4.1 is due out at end of month.

Viewing 15 posts - 1 through 15 (of 19 total)
Reply To: Possible Hibernate mapping bug

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