-->
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.  [ 4 posts ] 
Author Message
 Post subject: Hibernate mapping loads "[B@109506a" from MySQL &q
PostPosted: Wed Dec 21, 2005 12:55 pm 
Regular
Regular

Joined: Wed Dec 07, 2005 4:19 pm
Posts: 53
For some ungawdly reason, in one of my many objects, Hibernate loads something that looks like some "blob reference" instead of the database column content.

When Hibernate calls my object InstDataSource.setValue(String value) method, the value is:

"[B@109506a" (or some other address value), instead of the data in the database (even MySQL Front can show the data right).

When I change the database column declaration from "TEXT" to "VARCHAR(255)", Hibernate loads the right values.

I suspect there is some sensitivity to "something" in the mapping file, but I am using the same property/column description in many other cases, where it works just fine.

The problem applies to columns "Value" and "Words", both of which are sql-type="TEXT". I can't find anything like "[B@" in Hibernate source, but tracking the setValue() in the debugger shows the value "[B@109506a" at least 5 levels deep down the Hibernate code.

Hibernate version:
3.0
MySQL driver:
mysql-connector-java-3.1.10-bin.jar

Mapping documents:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>

<class name="com.recordfusion.gen.model.county.InstDataSource" table="instdatasource" lazy="false">
<id name="Id" type="java.lang.Integer">
<column name="Id" scale="11" precision="0" not-null="false" unique="true" sql-type="int" />
<generator class="native" />
</id>
<version name="Version" type="integer" column="Version"/>

<property name="instDataId" type="java.lang.Integer">
<column name="InstDataId" not-null="false" sql-type="int" />
</property>
<property name="statusDB" type="java.lang.String">
<column name="Status" not-null="false" sql-type="varchar" />
</property>
<property name="value" type="java.lang.String">
<column name="Value" not-null="false" sql-type="TEXT" />
</property>
<property name="wordsDB" type="java.lang.String">
<column name="Words" not-null="false" sql-type="TEXT" />
</property>
<property name="creationDate" type="java.util.Date">
<column name="CreationDate" scale="19" precision="0" not-null="false" sql-type="datetime" />
</property>
<property name="updateDate" type="java.util.Date">
<column name="UpdateDate" scale="19" precision="0" not-null="false" sql-type="datetime" />
</property>
</class>
</hibernate-mapping>


Database Schema:


CREATE TABLE `instdatasource` (
`Id` int(11) NOT NULL auto_increment,
`Version` int(11) NOT NULL default '0',
`InstDataId` int(11) default NULL,
`Status` varchar(16) default NULL,
`Value` text collate utf8_bin,
`Words` text collate utf8_bin,
`CreationDate` datetime default NULL,
`UpdateDate` timestamp NOT NULL default '0000-00-00 00:00:00',
PRIMARY KEY (`Id`),
KEY `InstDataId` (`InstDataId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='Instrument data (field) raw data form';


Code between sessionFactory.openSession() and session.close():

Query qsrc = ses.createQuery("select src from InstData data, InstDataSource src " +
" where data.instrument = :inst and src.instDataId = data.id ");
qsrc.setEntity("inst", inst);
// qsrc.setInteger("inst", inst.getId());
qsrc.setMaxResults(1024);
List<InstDataSource> srcs = qsrc.list();



Full stack trace of any exception that occurs:

Name and version of the database you are using:
MySQL 5.0 build 17 (the problem is the same in MySQL 5.0 beta)

The generated SQL (show_sql=true):
Hibernate: select instdataso1_.Id as Id, instdataso1_.Version as Version20_, instdataso1_.InstDataId as InstDataId20_, instdataso1_.Status as Status20_, instdataso1_.Value as Value20_, instdataso1_.Words as Words20_, instdataso1_.CreationDate as Creation7_20_, instdataso1_.UpdateDate as UpdateDate20_ from instdata instdata0_, instdatasource instdataso1_ where instdata0_.InstrId=? and instdataso1_.InstDataId=instdata0_.Id limit ?

Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 21, 2005 5:16 pm 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
It looks like a result from "toString()" ( "byte[].class.getName()" returns "[B" ).
Try to map "TEXT" as "Clob" or implement custom type to convert "Clob" to string.


Top
 Profile  
 
 Post subject: Resolved - MySQL Java Connect driver error
PostPosted: Thu Dec 29, 2005 1:44 pm 
Regular
Regular

Joined: Wed Dec 07, 2005 4:19 pm
Posts: 53
I think I can "assign the blame" for this one.

I was using MySQL Java Connect driver:
mysql-connector-java-3.1.10-bin.jar

Switching to
mysql-connector-java-3.1.12-bin.jar

solved the prolem. My "text" data are now coming in "right", instead of corrupted "[B@123456"

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 09, 2006 9:44 am 
Newbie

Joined: Thu Mar 09, 2006 9:32 am
Posts: 1
I ran into this too, it seemed to be a problem with mysql-connector-java-3.1.10 and MyISAM, when I switched over to InnoDB it worked fine. Of coarse, with 3.12 it doesn't matter.


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